Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1 | /* |
| 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 Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 26 | #include <drm/drmP.h> |
| 27 | #include <drm/radeon_drm.h> |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 28 | #include "radeon.h" |
| 29 | |
| 30 | #include "atom.h" |
| 31 | #include "atom-bits.h" |
| 32 | |
| 33 | /* from radeon_encoder.c */ |
| 34 | extern uint32_t |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 35 | radeon_get_encoder_enum(struct drm_device *dev, uint32_t supported_device, |
| 36 | uint8_t dac); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 37 | extern void radeon_link_encoder_connector(struct drm_device *dev); |
| 38 | extern void |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 39 | radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_enum, |
Alex Deucher | 36868bd | 2011-01-06 21:19:21 -0500 | [diff] [blame] | 40 | uint32_t supported_device, u16 caps); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 41 | |
| 42 | /* from radeon_connector.c */ |
| 43 | extern void |
| 44 | radeon_add_atom_connector(struct drm_device *dev, |
| 45 | uint32_t connector_id, |
| 46 | uint32_t supported_device, |
| 47 | int connector_type, |
| 48 | struct radeon_i2c_bus_rec *i2c_bus, |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 49 | uint32_t igp_lane_info, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 50 | uint16_t connector_object_id, |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 51 | struct radeon_hpd *hpd, |
| 52 | struct radeon_router *router); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 53 | |
| 54 | /* from radeon_legacy_encoder.c */ |
| 55 | extern void |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 56 | radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 57 | uint32_t supported_device); |
| 58 | |
| 59 | union atom_supported_devices { |
| 60 | struct _ATOM_SUPPORTED_DEVICES_INFO info; |
| 61 | struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2; |
| 62 | struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1; |
| 63 | }; |
| 64 | |
Alex Deucher | 21240f9 | 2011-11-21 12:41:21 -0500 | [diff] [blame] | 65 | static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev, |
| 66 | ATOM_GPIO_I2C_ASSIGMENT *gpio, |
| 67 | u8 index) |
| 68 | { |
| 69 | /* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */ |
| 70 | if ((rdev->family == CHIP_R420) || |
| 71 | (rdev->family == CHIP_R423) || |
| 72 | (rdev->family == CHIP_RV410)) { |
| 73 | if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) || |
| 74 | (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) || |
| 75 | (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) { |
| 76 | gpio->ucClkMaskShift = 0x19; |
| 77 | gpio->ucDataMaskShift = 0x18; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /* some evergreen boards have bad data for this entry */ |
| 82 | if (ASIC_IS_DCE4(rdev)) { |
| 83 | if ((index == 7) && |
| 84 | (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) && |
| 85 | (gpio->sucI2cId.ucAccess == 0)) { |
| 86 | gpio->sucI2cId.ucAccess = 0x97; |
| 87 | gpio->ucDataMaskShift = 8; |
| 88 | gpio->ucDataEnShift = 8; |
| 89 | gpio->ucDataY_Shift = 8; |
| 90 | gpio->ucDataA_Shift = 8; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /* some DCE3 boards have bad data for this entry */ |
| 95 | if (ASIC_IS_DCE3(rdev)) { |
| 96 | if ((index == 4) && |
| 97 | (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) && |
| 98 | (gpio->sucI2cId.ucAccess == 0x94)) |
| 99 | gpio->sucI2cId.ucAccess = 0x14; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio) |
| 104 | { |
| 105 | struct radeon_i2c_bus_rec i2c; |
| 106 | |
| 107 | memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec)); |
| 108 | |
| 109 | i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4; |
| 110 | i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4; |
| 111 | i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4; |
| 112 | i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4; |
| 113 | i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4; |
| 114 | i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4; |
| 115 | i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4; |
| 116 | i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4; |
| 117 | i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift); |
| 118 | i2c.mask_data_mask = (1 << gpio->ucDataMaskShift); |
| 119 | i2c.en_clk_mask = (1 << gpio->ucClkEnShift); |
| 120 | i2c.en_data_mask = (1 << gpio->ucDataEnShift); |
| 121 | i2c.y_clk_mask = (1 << gpio->ucClkY_Shift); |
| 122 | i2c.y_data_mask = (1 << gpio->ucDataY_Shift); |
| 123 | i2c.a_clk_mask = (1 << gpio->ucClkA_Shift); |
| 124 | i2c.a_data_mask = (1 << gpio->ucDataA_Shift); |
| 125 | |
| 126 | if (gpio->sucI2cId.sbfAccess.bfHW_Capable) |
| 127 | i2c.hw_capable = true; |
| 128 | else |
| 129 | i2c.hw_capable = false; |
| 130 | |
| 131 | if (gpio->sucI2cId.ucAccess == 0xa0) |
| 132 | i2c.mm_i2c = true; |
| 133 | else |
| 134 | i2c.mm_i2c = false; |
| 135 | |
| 136 | i2c.i2c_id = gpio->sucI2cId.ucAccess; |
| 137 | |
| 138 | if (i2c.mask_clk_reg) |
| 139 | i2c.valid = true; |
| 140 | else |
| 141 | i2c.valid = false; |
| 142 | |
| 143 | return i2c; |
| 144 | } |
| 145 | |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 146 | static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 147 | uint8_t id) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 148 | { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 149 | struct atom_context *ctx = rdev->mode_info.atom_context; |
Alex Deucher | 6a93cb2 | 2009-11-23 17:39:28 -0500 | [diff] [blame] | 150 | ATOM_GPIO_I2C_ASSIGMENT *gpio; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 151 | struct radeon_i2c_bus_rec i2c; |
| 152 | int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info); |
| 153 | struct _ATOM_GPIO_I2C_INFO *i2c_info; |
Alex Deucher | 95beb69 | 2010-04-01 19:08:47 +0000 | [diff] [blame] | 154 | uint16_t data_offset, size; |
| 155 | int i, num_indices; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 156 | |
| 157 | memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec)); |
| 158 | i2c.valid = false; |
| 159 | |
Alex Deucher | 95beb69 | 2010-04-01 19:08:47 +0000 | [diff] [blame] | 160 | if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) { |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 161 | i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 162 | |
Alex Deucher | 95beb69 | 2010-04-01 19:08:47 +0000 | [diff] [blame] | 163 | num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / |
| 164 | sizeof(ATOM_GPIO_I2C_ASSIGMENT); |
| 165 | |
| 166 | for (i = 0; i < num_indices; i++) { |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 167 | gpio = &i2c_info->asGPIO_Info[i]; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 168 | |
Alex Deucher | 21240f9 | 2011-11-21 12:41:21 -0500 | [diff] [blame] | 169 | radeon_lookup_i2c_gpio_quirks(rdev, gpio, i); |
Alex Deucher | 3074adc | 2010-11-30 00:15:10 -0500 | [diff] [blame] | 170 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 171 | if (gpio->sucI2cId.ucAccess == id) { |
Alex Deucher | 21240f9 | 2011-11-21 12:41:21 -0500 | [diff] [blame] | 172 | i2c = radeon_get_bus_rec_for_i2c_gpio(gpio); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 173 | break; |
| 174 | } |
Alex Deucher | d3f420d | 2009-12-08 14:30:49 -0500 | [diff] [blame] | 175 | } |
| 176 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 177 | |
| 178 | return i2c; |
| 179 | } |
| 180 | |
Alex Deucher | f376b94 | 2010-08-05 21:21:16 -0400 | [diff] [blame] | 181 | void radeon_atombios_i2c_init(struct radeon_device *rdev) |
| 182 | { |
| 183 | struct atom_context *ctx = rdev->mode_info.atom_context; |
| 184 | ATOM_GPIO_I2C_ASSIGMENT *gpio; |
| 185 | struct radeon_i2c_bus_rec i2c; |
| 186 | int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info); |
| 187 | struct _ATOM_GPIO_I2C_INFO *i2c_info; |
| 188 | uint16_t data_offset, size; |
| 189 | int i, num_indices; |
| 190 | char stmp[32]; |
| 191 | |
Alex Deucher | f376b94 | 2010-08-05 21:21:16 -0400 | [diff] [blame] | 192 | if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) { |
| 193 | i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); |
| 194 | |
| 195 | num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / |
| 196 | sizeof(ATOM_GPIO_I2C_ASSIGMENT); |
| 197 | |
| 198 | for (i = 0; i < num_indices; i++) { |
| 199 | gpio = &i2c_info->asGPIO_Info[i]; |
Alex Deucher | ea39302 | 2010-08-27 16:04:29 -0400 | [diff] [blame] | 200 | |
Alex Deucher | 21240f9 | 2011-11-21 12:41:21 -0500 | [diff] [blame] | 201 | radeon_lookup_i2c_gpio_quirks(rdev, gpio, i); |
Alex Deucher | d724502 | 2011-11-21 12:10:14 -0500 | [diff] [blame] | 202 | |
Alex Deucher | 21240f9 | 2011-11-21 12:41:21 -0500 | [diff] [blame] | 203 | i2c = radeon_get_bus_rec_for_i2c_gpio(gpio); |
Alex Deucher | ea39302 | 2010-08-27 16:04:29 -0400 | [diff] [blame] | 204 | |
Alex Deucher | 21240f9 | 2011-11-21 12:41:21 -0500 | [diff] [blame] | 205 | if (i2c.valid) { |
Alex Deucher | f376b94 | 2010-08-05 21:21:16 -0400 | [diff] [blame] | 206 | sprintf(stmp, "0x%x", i2c.i2c_id); |
| 207 | rdev->i2c_bus[i] = radeon_i2c_create(rdev->ddev, &i2c, stmp); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | |
Andi Kleen | ce580fa | 2011-10-13 16:08:47 -0700 | [diff] [blame] | 213 | static struct radeon_gpio_rec radeon_lookup_gpio(struct radeon_device *rdev, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 214 | u8 id) |
| 215 | { |
| 216 | struct atom_context *ctx = rdev->mode_info.atom_context; |
| 217 | struct radeon_gpio_rec gpio; |
| 218 | int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT); |
| 219 | struct _ATOM_GPIO_PIN_LUT *gpio_info; |
| 220 | ATOM_GPIO_PIN_ASSIGNMENT *pin; |
| 221 | u16 data_offset, size; |
| 222 | int i, num_indices; |
| 223 | |
| 224 | memset(&gpio, 0, sizeof(struct radeon_gpio_rec)); |
| 225 | gpio.valid = false; |
| 226 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 227 | if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) { |
| 228 | gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset); |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 229 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 230 | num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / |
| 231 | sizeof(ATOM_GPIO_PIN_ASSIGNMENT); |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 232 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 233 | for (i = 0; i < num_indices; i++) { |
| 234 | pin = &gpio_info->asGPIO_Pin[i]; |
| 235 | if (id == pin->ucGPIO_ID) { |
| 236 | gpio.id = pin->ucGPIO_ID; |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 237 | gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex) * 4; |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 238 | gpio.mask = (1 << pin->ucGpioPinBitShift); |
| 239 | gpio.valid = true; |
| 240 | break; |
| 241 | } |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | return gpio; |
| 246 | } |
| 247 | |
| 248 | static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device *rdev, |
| 249 | struct radeon_gpio_rec *gpio) |
| 250 | { |
| 251 | struct radeon_hpd hpd; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 252 | u32 reg; |
| 253 | |
Jean Delvare | 1d978da | 2010-08-15 14:11:24 +0200 | [diff] [blame] | 254 | memset(&hpd, 0, sizeof(struct radeon_hpd)); |
| 255 | |
Alex Deucher | 82d118e | 2012-03-20 17:18:01 -0400 | [diff] [blame] | 256 | if (ASIC_IS_DCE6(rdev)) |
| 257 | reg = SI_DC_GPIO_HPD_A; |
| 258 | else if (ASIC_IS_DCE4(rdev)) |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 259 | reg = EVERGREEN_DC_GPIO_HPD_A; |
| 260 | else |
| 261 | reg = AVIVO_DC_GPIO_HPD_A; |
| 262 | |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 263 | hpd.gpio = *gpio; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 264 | if (gpio->reg == reg) { |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 265 | switch(gpio->mask) { |
| 266 | case (1 << 0): |
| 267 | hpd.hpd = RADEON_HPD_1; |
| 268 | break; |
| 269 | case (1 << 8): |
| 270 | hpd.hpd = RADEON_HPD_2; |
| 271 | break; |
| 272 | case (1 << 16): |
| 273 | hpd.hpd = RADEON_HPD_3; |
| 274 | break; |
| 275 | case (1 << 24): |
| 276 | hpd.hpd = RADEON_HPD_4; |
| 277 | break; |
| 278 | case (1 << 26): |
| 279 | hpd.hpd = RADEON_HPD_5; |
| 280 | break; |
| 281 | case (1 << 28): |
| 282 | hpd.hpd = RADEON_HPD_6; |
| 283 | break; |
| 284 | default: |
| 285 | hpd.hpd = RADEON_HPD_NONE; |
| 286 | break; |
| 287 | } |
| 288 | } else |
| 289 | hpd.hpd = RADEON_HPD_NONE; |
| 290 | return hpd; |
| 291 | } |
| 292 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 293 | static bool radeon_atom_apply_quirks(struct drm_device *dev, |
| 294 | uint32_t supported_device, |
| 295 | int *connector_type, |
Alex Deucher | 848577e | 2009-07-08 16:15:30 -0400 | [diff] [blame] | 296 | struct radeon_i2c_bus_rec *i2c_bus, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 297 | uint16_t *line_mux, |
| 298 | struct radeon_hpd *hpd) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 299 | { |
| 300 | |
| 301 | /* Asus M2A-VM HDMI board lists the DVI port as HDMI */ |
| 302 | if ((dev->pdev->device == 0x791e) && |
| 303 | (dev->pdev->subsystem_vendor == 0x1043) && |
| 304 | (dev->pdev->subsystem_device == 0x826d)) { |
| 305 | if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) && |
| 306 | (supported_device == ATOM_DEVICE_DFP3_SUPPORT)) |
| 307 | *connector_type = DRM_MODE_CONNECTOR_DVID; |
| 308 | } |
| 309 | |
Alex Deucher | c86a903 | 2010-02-18 14:14:58 -0500 | [diff] [blame] | 310 | /* Asrock RS600 board lists the DVI port as HDMI */ |
| 311 | if ((dev->pdev->device == 0x7941) && |
| 312 | (dev->pdev->subsystem_vendor == 0x1849) && |
| 313 | (dev->pdev->subsystem_device == 0x7941)) { |
| 314 | if ((*connector_type == DRM_MODE_CONNECTOR_HDMIA) && |
| 315 | (supported_device == ATOM_DEVICE_DFP3_SUPPORT)) |
| 316 | *connector_type = DRM_MODE_CONNECTOR_DVID; |
| 317 | } |
| 318 | |
Alex Deucher | f36fce0 | 2010-09-27 11:33:00 -0400 | [diff] [blame] | 319 | /* MSI K9A2GM V2/V3 board has no HDMI or DVI */ |
| 320 | if ((dev->pdev->device == 0x796e) && |
| 321 | (dev->pdev->subsystem_vendor == 0x1462) && |
| 322 | (dev->pdev->subsystem_device == 0x7302)) { |
| 323 | if ((supported_device == ATOM_DEVICE_DFP2_SUPPORT) || |
| 324 | (supported_device == ATOM_DEVICE_DFP3_SUPPORT)) |
| 325 | return false; |
| 326 | } |
| 327 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 328 | /* a-bit f-i90hd - ciaranm on #radeonhd - this board has no DVI */ |
| 329 | if ((dev->pdev->device == 0x7941) && |
| 330 | (dev->pdev->subsystem_vendor == 0x147b) && |
| 331 | (dev->pdev->subsystem_device == 0x2412)) { |
| 332 | if (*connector_type == DRM_MODE_CONNECTOR_DVII) |
| 333 | return false; |
| 334 | } |
| 335 | |
| 336 | /* Falcon NW laptop lists vga ddc line for LVDS */ |
| 337 | if ((dev->pdev->device == 0x5653) && |
| 338 | (dev->pdev->subsystem_vendor == 0x1462) && |
| 339 | (dev->pdev->subsystem_device == 0x0291)) { |
Alex Deucher | 848577e | 2009-07-08 16:15:30 -0400 | [diff] [blame] | 340 | if (*connector_type == DRM_MODE_CONNECTOR_LVDS) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 341 | i2c_bus->valid = false; |
Alex Deucher | 848577e | 2009-07-08 16:15:30 -0400 | [diff] [blame] | 342 | *line_mux = 53; |
| 343 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Alex Deucher | 4e3f9b78 | 2009-12-01 14:49:50 -0500 | [diff] [blame] | 346 | /* HIS X1300 is DVI+VGA, not DVI+DVI */ |
| 347 | if ((dev->pdev->device == 0x7146) && |
| 348 | (dev->pdev->subsystem_vendor == 0x17af) && |
| 349 | (dev->pdev->subsystem_device == 0x2058)) { |
| 350 | if (supported_device == ATOM_DEVICE_DFP1_SUPPORT) |
| 351 | return false; |
| 352 | } |
| 353 | |
Dave Airlie | aa1a750 | 2009-12-04 11:51:34 +1000 | [diff] [blame] | 354 | /* Gigabyte X1300 is DVI+VGA, not DVI+DVI */ |
| 355 | if ((dev->pdev->device == 0x7142) && |
| 356 | (dev->pdev->subsystem_vendor == 0x1458) && |
| 357 | (dev->pdev->subsystem_device == 0x2134)) { |
| 358 | if (supported_device == ATOM_DEVICE_DFP1_SUPPORT) |
| 359 | return false; |
| 360 | } |
| 361 | |
| 362 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 363 | /* Funky macbooks */ |
| 364 | if ((dev->pdev->device == 0x71C5) && |
| 365 | (dev->pdev->subsystem_vendor == 0x106b) && |
| 366 | (dev->pdev->subsystem_device == 0x0080)) { |
| 367 | if ((supported_device == ATOM_DEVICE_CRT1_SUPPORT) || |
| 368 | (supported_device == ATOM_DEVICE_DFP2_SUPPORT)) |
| 369 | return false; |
Alex Deucher | e1e8a5d | 2010-03-26 17:14:37 -0400 | [diff] [blame] | 370 | if (supported_device == ATOM_DEVICE_CRT2_SUPPORT) |
| 371 | *line_mux = 0x90; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Alex Deucher | be23da8 | 2011-01-18 18:26:11 +0000 | [diff] [blame] | 374 | /* mac rv630, rv730, others */ |
| 375 | if ((supported_device == ATOM_DEVICE_TV1_SUPPORT) && |
| 376 | (*connector_type == DRM_MODE_CONNECTOR_DVII)) { |
| 377 | *connector_type = DRM_MODE_CONNECTOR_9PinDIN; |
| 378 | *line_mux = CONNECTOR_7PIN_DIN_ENUM_ID1; |
Alex Deucher | f598aa7 | 2011-01-04 00:43:39 -0500 | [diff] [blame] | 379 | } |
| 380 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 381 | /* ASUS HD 3600 XT board lists the DVI port as HDMI */ |
| 382 | if ((dev->pdev->device == 0x9598) && |
| 383 | (dev->pdev->subsystem_vendor == 0x1043) && |
| 384 | (dev->pdev->subsystem_device == 0x01da)) { |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 385 | if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) { |
Alex Deucher | d42571e | 2009-09-11 15:27:14 -0400 | [diff] [blame] | 386 | *connector_type = DRM_MODE_CONNECTOR_DVII; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | |
Alex Deucher | e153b70 | 2010-07-20 18:07:22 -0400 | [diff] [blame] | 390 | /* ASUS HD 3600 board lists the DVI port as HDMI */ |
| 391 | if ((dev->pdev->device == 0x9598) && |
| 392 | (dev->pdev->subsystem_vendor == 0x1043) && |
| 393 | (dev->pdev->subsystem_device == 0x01e4)) { |
| 394 | if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) { |
| 395 | *connector_type = DRM_MODE_CONNECTOR_DVII; |
| 396 | } |
| 397 | } |
| 398 | |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 399 | /* ASUS HD 3450 board lists the DVI port as HDMI */ |
| 400 | if ((dev->pdev->device == 0x95C5) && |
| 401 | (dev->pdev->subsystem_vendor == 0x1043) && |
| 402 | (dev->pdev->subsystem_device == 0x01e2)) { |
| 403 | if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) { |
Alex Deucher | d42571e | 2009-09-11 15:27:14 -0400 | [diff] [blame] | 404 | *connector_type = DRM_MODE_CONNECTOR_DVII; |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
| 408 | /* some BIOSes seem to report DAC on HDMI - usually this is a board with |
| 409 | * HDMI + VGA reporting as HDMI |
| 410 | */ |
| 411 | if (*connector_type == DRM_MODE_CONNECTOR_HDMIA) { |
| 412 | if (supported_device & (ATOM_DEVICE_CRT_SUPPORT)) { |
| 413 | *connector_type = DRM_MODE_CONNECTOR_VGA; |
| 414 | *line_mux = 0; |
| 415 | } |
| 416 | } |
| 417 | |
Alex Deucher | 4f87af4 | 2011-05-04 11:41:47 -0400 | [diff] [blame] | 418 | /* Acer laptop (Acer TravelMate 5730/5730G) has an HDMI port |
Alex Deucher | 2f299d5 | 2011-01-04 17:42:20 -0500 | [diff] [blame] | 419 | * on the laptop and a DVI port on the docking station and |
| 420 | * both share the same encoder, hpd pin, and ddc line. |
| 421 | * So while the bios table is technically correct, |
| 422 | * we drop the DVI port here since xrandr has no concept of |
| 423 | * encoders and will try and drive both connectors |
| 424 | * with different crtcs which isn't possible on the hardware |
| 425 | * side and leaves no crtcs for LVDS or VGA. |
| 426 | */ |
Alex Deucher | 4f87af4 | 2011-05-04 11:41:47 -0400 | [diff] [blame] | 427 | if (((dev->pdev->device == 0x95c4) || (dev->pdev->device == 0x9591)) && |
Alex Deucher | 3e5f8ff | 2009-11-17 17:12:10 -0500 | [diff] [blame] | 428 | (dev->pdev->subsystem_vendor == 0x1025) && |
| 429 | (dev->pdev->subsystem_device == 0x013c)) { |
| 430 | if ((*connector_type == DRM_MODE_CONNECTOR_DVII) && |
Alex Deucher | 9ea2c4b | 2010-08-06 00:27:44 -0400 | [diff] [blame] | 431 | (supported_device == ATOM_DEVICE_DFP1_SUPPORT)) { |
Alex Deucher | 2f299d5 | 2011-01-04 17:42:20 -0500 | [diff] [blame] | 432 | /* actually it's a DVI-D port not DVI-I */ |
Alex Deucher | 3e5f8ff | 2009-11-17 17:12:10 -0500 | [diff] [blame] | 433 | *connector_type = DRM_MODE_CONNECTOR_DVID; |
Alex Deucher | 2f299d5 | 2011-01-04 17:42:20 -0500 | [diff] [blame] | 434 | return false; |
Alex Deucher | 9ea2c4b | 2010-08-06 00:27:44 -0400 | [diff] [blame] | 435 | } |
Alex Deucher | 3e5f8ff | 2009-11-17 17:12:10 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Dave Airlie | efa8450 | 2010-02-09 09:06:00 +1000 | [diff] [blame] | 438 | /* XFX Pine Group device rv730 reports no VGA DDC lines |
| 439 | * even though they are wired up to record 0x93 |
| 440 | */ |
| 441 | if ((dev->pdev->device == 0x9498) && |
| 442 | (dev->pdev->subsystem_vendor == 0x1682) && |
Alex Deucher | 1ebf169 | 2012-05-23 11:48:59 -0400 | [diff] [blame] | 443 | (dev->pdev->subsystem_device == 0x2452) && |
| 444 | (i2c_bus->valid == false) && |
| 445 | !(supported_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))) { |
Dave Airlie | efa8450 | 2010-02-09 09:06:00 +1000 | [diff] [blame] | 446 | struct radeon_device *rdev = dev->dev_private; |
| 447 | *i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93); |
| 448 | } |
Alex Deucher | 4c1b2d2 | 2012-03-16 12:22:10 -0400 | [diff] [blame] | 449 | |
| 450 | /* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */ |
Tvrtko Ursulin | 52e9b39 | 2012-08-20 15:16:04 +0100 | [diff] [blame] | 451 | if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) && |
Alex Deucher | 4c1b2d2 | 2012-03-16 12:22:10 -0400 | [diff] [blame] | 452 | (dev->pdev->subsystem_vendor == 0x1734) && |
| 453 | (dev->pdev->subsystem_device == 0x11bd)) { |
| 454 | if (*connector_type == DRM_MODE_CONNECTOR_VGA) { |
| 455 | *connector_type = DRM_MODE_CONNECTOR_DVII; |
| 456 | *line_mux = 0x3103; |
| 457 | } else if (*connector_type == DRM_MODE_CONNECTOR_DVID) { |
| 458 | *connector_type = DRM_MODE_CONNECTOR_DVII; |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 463 | return true; |
| 464 | } |
| 465 | |
| 466 | const int supported_devices_connector_convert[] = { |
| 467 | DRM_MODE_CONNECTOR_Unknown, |
| 468 | DRM_MODE_CONNECTOR_VGA, |
| 469 | DRM_MODE_CONNECTOR_DVII, |
| 470 | DRM_MODE_CONNECTOR_DVID, |
| 471 | DRM_MODE_CONNECTOR_DVIA, |
| 472 | DRM_MODE_CONNECTOR_SVIDEO, |
| 473 | DRM_MODE_CONNECTOR_Composite, |
| 474 | DRM_MODE_CONNECTOR_LVDS, |
| 475 | DRM_MODE_CONNECTOR_Unknown, |
| 476 | DRM_MODE_CONNECTOR_Unknown, |
| 477 | DRM_MODE_CONNECTOR_HDMIA, |
| 478 | DRM_MODE_CONNECTOR_HDMIB, |
| 479 | DRM_MODE_CONNECTOR_Unknown, |
| 480 | DRM_MODE_CONNECTOR_Unknown, |
| 481 | DRM_MODE_CONNECTOR_9PinDIN, |
| 482 | DRM_MODE_CONNECTOR_DisplayPort |
| 483 | }; |
| 484 | |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 485 | const uint16_t supported_devices_connector_object_id_convert[] = { |
| 486 | CONNECTOR_OBJECT_ID_NONE, |
| 487 | CONNECTOR_OBJECT_ID_VGA, |
| 488 | CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I, /* not all boards support DL */ |
| 489 | CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D, /* not all boards support DL */ |
| 490 | CONNECTOR_OBJECT_ID_VGA, /* technically DVI-A */ |
| 491 | CONNECTOR_OBJECT_ID_COMPOSITE, |
| 492 | CONNECTOR_OBJECT_ID_SVIDEO, |
| 493 | CONNECTOR_OBJECT_ID_LVDS, |
| 494 | CONNECTOR_OBJECT_ID_9PIN_DIN, |
| 495 | CONNECTOR_OBJECT_ID_9PIN_DIN, |
| 496 | CONNECTOR_OBJECT_ID_DISPLAYPORT, |
| 497 | CONNECTOR_OBJECT_ID_HDMI_TYPE_A, |
| 498 | CONNECTOR_OBJECT_ID_HDMI_TYPE_B, |
| 499 | CONNECTOR_OBJECT_ID_SVIDEO |
| 500 | }; |
| 501 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 502 | const int object_connector_convert[] = { |
| 503 | DRM_MODE_CONNECTOR_Unknown, |
| 504 | DRM_MODE_CONNECTOR_DVII, |
| 505 | DRM_MODE_CONNECTOR_DVII, |
| 506 | DRM_MODE_CONNECTOR_DVID, |
| 507 | DRM_MODE_CONNECTOR_DVID, |
| 508 | DRM_MODE_CONNECTOR_VGA, |
| 509 | DRM_MODE_CONNECTOR_Composite, |
| 510 | DRM_MODE_CONNECTOR_SVIDEO, |
| 511 | DRM_MODE_CONNECTOR_Unknown, |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 512 | DRM_MODE_CONNECTOR_Unknown, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 513 | DRM_MODE_CONNECTOR_9PinDIN, |
| 514 | DRM_MODE_CONNECTOR_Unknown, |
| 515 | DRM_MODE_CONNECTOR_HDMIA, |
| 516 | DRM_MODE_CONNECTOR_HDMIB, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 517 | DRM_MODE_CONNECTOR_LVDS, |
| 518 | DRM_MODE_CONNECTOR_9PinDIN, |
| 519 | DRM_MODE_CONNECTOR_Unknown, |
| 520 | DRM_MODE_CONNECTOR_Unknown, |
| 521 | DRM_MODE_CONNECTOR_Unknown, |
Alex Deucher | 196c58d | 2010-01-07 14:22:32 -0500 | [diff] [blame] | 522 | DRM_MODE_CONNECTOR_DisplayPort, |
| 523 | DRM_MODE_CONNECTOR_eDP, |
| 524 | DRM_MODE_CONNECTOR_Unknown |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 525 | }; |
| 526 | |
| 527 | bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev) |
| 528 | { |
| 529 | struct radeon_device *rdev = dev->dev_private; |
| 530 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 531 | struct atom_context *ctx = mode_info->atom_context; |
| 532 | int index = GetIndexIntoMasterTable(DATA, Object_Header); |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 533 | u16 size, data_offset; |
| 534 | u8 frev, crev; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 535 | ATOM_CONNECTOR_OBJECT_TABLE *con_obj; |
Alex Deucher | 36868bd | 2011-01-06 21:19:21 -0500 | [diff] [blame] | 536 | ATOM_ENCODER_OBJECT_TABLE *enc_obj; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 537 | ATOM_OBJECT_TABLE *router_obj; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 538 | ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj; |
| 539 | ATOM_OBJECT_HEADER *obj_header; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 540 | int i, j, k, path_size, device_support; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 541 | int connector_type; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 542 | u16 igp_lane_info, conn_id, connector_object_id; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 543 | struct radeon_i2c_bus_rec ddc_bus; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 544 | struct radeon_router router; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 545 | struct radeon_gpio_rec gpio; |
| 546 | struct radeon_hpd hpd; |
| 547 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 548 | if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 549 | return false; |
| 550 | |
| 551 | if (crev < 2) |
| 552 | return false; |
| 553 | |
| 554 | obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset); |
| 555 | path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *) |
| 556 | (ctx->bios + data_offset + |
| 557 | le16_to_cpu(obj_header->usDisplayPathTableOffset)); |
| 558 | con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *) |
| 559 | (ctx->bios + data_offset + |
| 560 | le16_to_cpu(obj_header->usConnectorObjectTableOffset)); |
Alex Deucher | 36868bd | 2011-01-06 21:19:21 -0500 | [diff] [blame] | 561 | enc_obj = (ATOM_ENCODER_OBJECT_TABLE *) |
| 562 | (ctx->bios + data_offset + |
| 563 | le16_to_cpu(obj_header->usEncoderObjectTableOffset)); |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 564 | router_obj = (ATOM_OBJECT_TABLE *) |
| 565 | (ctx->bios + data_offset + |
| 566 | le16_to_cpu(obj_header->usRouterObjectTableOffset)); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 567 | device_support = le16_to_cpu(obj_header->usDeviceSupport); |
| 568 | |
| 569 | path_size = 0; |
| 570 | for (i = 0; i < path_obj->ucNumOfDispPath; i++) { |
| 571 | uint8_t *addr = (uint8_t *) path_obj->asDispPath; |
| 572 | ATOM_DISPLAY_OBJECT_PATH *path; |
| 573 | addr += path_size; |
| 574 | path = (ATOM_DISPLAY_OBJECT_PATH *) addr; |
| 575 | path_size += le16_to_cpu(path->usSize); |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 576 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 577 | if (device_support & le16_to_cpu(path->usDeviceTag)) { |
| 578 | uint8_t con_obj_id, con_obj_num, con_obj_type; |
| 579 | |
| 580 | con_obj_id = |
| 581 | (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK) |
| 582 | >> OBJECT_ID_SHIFT; |
| 583 | con_obj_num = |
| 584 | (le16_to_cpu(path->usConnObjectId) & ENUM_ID_MASK) |
| 585 | >> ENUM_ID_SHIFT; |
| 586 | con_obj_type = |
| 587 | (le16_to_cpu(path->usConnObjectId) & |
| 588 | OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT; |
| 589 | |
Dave Airlie | 4bbd497 | 2009-09-25 08:56:12 +1000 | [diff] [blame] | 590 | /* TODO CV support */ |
| 591 | if (le16_to_cpu(path->usDeviceTag) == |
| 592 | ATOM_DEVICE_CV_SUPPORT) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 593 | continue; |
| 594 | |
Alex Deucher | ee59f2b | 2009-11-05 13:11:46 -0500 | [diff] [blame] | 595 | /* IGP chips */ |
| 596 | if ((rdev->flags & RADEON_IS_IGP) && |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 597 | (con_obj_id == |
| 598 | CONNECTOR_OBJECT_ID_PCIE_CONNECTOR)) { |
| 599 | uint16_t igp_offset = 0; |
| 600 | ATOM_INTEGRATED_SYSTEM_INFO_V2 *igp_obj; |
| 601 | |
| 602 | index = |
| 603 | GetIndexIntoMasterTable(DATA, |
| 604 | IntegratedSystemInfo); |
| 605 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 606 | if (atom_parse_data_header(ctx, index, &size, &frev, |
| 607 | &crev, &igp_offset)) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 608 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 609 | if (crev >= 2) { |
| 610 | igp_obj = |
| 611 | (ATOM_INTEGRATED_SYSTEM_INFO_V2 |
| 612 | *) (ctx->bios + igp_offset); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 613 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 614 | if (igp_obj) { |
| 615 | uint32_t slot_config, ct; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 616 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 617 | if (con_obj_num == 1) |
| 618 | slot_config = |
| 619 | igp_obj-> |
| 620 | ulDDISlot1Config; |
| 621 | else |
| 622 | slot_config = |
| 623 | igp_obj-> |
| 624 | ulDDISlot2Config; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 625 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 626 | ct = (slot_config >> 16) & 0xff; |
| 627 | connector_type = |
| 628 | object_connector_convert |
| 629 | [ct]; |
| 630 | connector_object_id = ct; |
| 631 | igp_lane_info = |
| 632 | slot_config & 0xffff; |
| 633 | } else |
| 634 | continue; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 635 | } else |
| 636 | continue; |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 637 | } else { |
| 638 | igp_lane_info = 0; |
| 639 | connector_type = |
| 640 | object_connector_convert[con_obj_id]; |
| 641 | connector_object_id = con_obj_id; |
| 642 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 643 | } else { |
| 644 | igp_lane_info = 0; |
| 645 | connector_type = |
| 646 | object_connector_convert[con_obj_id]; |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 647 | connector_object_id = con_obj_id; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | if (connector_type == DRM_MODE_CONNECTOR_Unknown) |
| 651 | continue; |
| 652 | |
Tyson Whitehead | bdd91b2 | 2010-11-08 16:08:30 +0000 | [diff] [blame] | 653 | router.ddc_valid = false; |
| 654 | router.cd_valid = false; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 655 | for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) { |
| 656 | uint8_t grph_obj_id, grph_obj_num, grph_obj_type; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 657 | |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 658 | grph_obj_id = |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 659 | (le16_to_cpu(path->usGraphicObjIds[j]) & |
| 660 | OBJECT_ID_MASK) >> OBJECT_ID_SHIFT; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 661 | grph_obj_num = |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 662 | (le16_to_cpu(path->usGraphicObjIds[j]) & |
| 663 | ENUM_ID_MASK) >> ENUM_ID_SHIFT; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 664 | grph_obj_type = |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 665 | (le16_to_cpu(path->usGraphicObjIds[j]) & |
| 666 | OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT; |
| 667 | |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 668 | if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) { |
Alex Deucher | 36868bd | 2011-01-06 21:19:21 -0500 | [diff] [blame] | 669 | for (k = 0; k < enc_obj->ucNumberOfObjects; k++) { |
| 670 | u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID); |
| 671 | if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) { |
| 672 | ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *) |
| 673 | (ctx->bios + data_offset + |
| 674 | le16_to_cpu(enc_obj->asObjects[k].usRecordOffset)); |
| 675 | ATOM_ENCODER_CAP_RECORD *cap_record; |
| 676 | u16 caps = 0; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 677 | |
John Lindgren | 97ea530 | 2011-03-24 23:28:31 +0000 | [diff] [blame] | 678 | while (record->ucRecordSize > 0 && |
| 679 | record->ucRecordType > 0 && |
Alex Deucher | 36868bd | 2011-01-06 21:19:21 -0500 | [diff] [blame] | 680 | record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) { |
| 681 | switch (record->ucRecordType) { |
| 682 | case ATOM_ENCODER_CAP_RECORD_TYPE: |
| 683 | cap_record =(ATOM_ENCODER_CAP_RECORD *) |
| 684 | record; |
| 685 | caps = le16_to_cpu(cap_record->usEncoderCap); |
| 686 | break; |
| 687 | } |
| 688 | record = (ATOM_COMMON_RECORD_HEADER *) |
| 689 | ((char *)record + record->ucRecordSize); |
| 690 | } |
| 691 | radeon_add_atom_encoder(dev, |
| 692 | encoder_obj, |
| 693 | le16_to_cpu |
| 694 | (path-> |
| 695 | usDeviceTag), |
| 696 | caps); |
| 697 | } |
| 698 | } |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 699 | } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) { |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 700 | for (k = 0; k < router_obj->ucNumberOfObjects; k++) { |
Tyson Whitehead | bdd91b2 | 2010-11-08 16:08:30 +0000 | [diff] [blame] | 701 | u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID); |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 702 | if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) { |
| 703 | ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *) |
| 704 | (ctx->bios + data_offset + |
| 705 | le16_to_cpu(router_obj->asObjects[k].usRecordOffset)); |
| 706 | ATOM_I2C_RECORD *i2c_record; |
| 707 | ATOM_I2C_ID_CONFIG_ACCESS *i2c_config; |
| 708 | ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path; |
Alex Deucher | fb939df | 2010-11-08 16:08:29 +0000 | [diff] [blame] | 709 | ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 710 | ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table = |
| 711 | (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *) |
| 712 | (ctx->bios + data_offset + |
| 713 | le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset)); |
| 714 | int enum_id; |
| 715 | |
| 716 | router.router_id = router_obj_id; |
| 717 | for (enum_id = 0; enum_id < router_src_dst_table->ucNumberOfDst; |
| 718 | enum_id++) { |
| 719 | if (le16_to_cpu(path->usConnObjectId) == |
| 720 | le16_to_cpu(router_src_dst_table->usDstObjectID[enum_id])) |
| 721 | break; |
| 722 | } |
| 723 | |
John Lindgren | 97ea530 | 2011-03-24 23:28:31 +0000 | [diff] [blame] | 724 | while (record->ucRecordSize > 0 && |
| 725 | record->ucRecordType > 0 && |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 726 | record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) { |
| 727 | switch (record->ucRecordType) { |
| 728 | case ATOM_I2C_RECORD_TYPE: |
| 729 | i2c_record = |
| 730 | (ATOM_I2C_RECORD *) |
| 731 | record; |
| 732 | i2c_config = |
| 733 | (ATOM_I2C_ID_CONFIG_ACCESS *) |
| 734 | &i2c_record->sucI2cId; |
| 735 | router.i2c_info = |
| 736 | radeon_lookup_i2c_gpio(rdev, |
| 737 | i2c_config-> |
| 738 | ucAccess); |
| 739 | router.i2c_addr = i2c_record->ucI2CAddr >> 1; |
| 740 | break; |
| 741 | case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE: |
| 742 | ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *) |
| 743 | record; |
Alex Deucher | fb939df | 2010-11-08 16:08:29 +0000 | [diff] [blame] | 744 | router.ddc_valid = true; |
| 745 | router.ddc_mux_type = ddc_path->ucMuxType; |
| 746 | router.ddc_mux_control_pin = ddc_path->ucMuxControlPin; |
| 747 | router.ddc_mux_state = ddc_path->ucMuxState[enum_id]; |
| 748 | break; |
| 749 | case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE: |
| 750 | cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *) |
| 751 | record; |
| 752 | router.cd_valid = true; |
| 753 | router.cd_mux_type = cd_path->ucMuxType; |
| 754 | router.cd_mux_control_pin = cd_path->ucMuxControlPin; |
| 755 | router.cd_mux_state = cd_path->ucMuxState[enum_id]; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 756 | break; |
| 757 | } |
| 758 | record = (ATOM_COMMON_RECORD_HEADER *) |
| 759 | ((char *)record + record->ucRecordSize); |
| 760 | } |
| 761 | } |
| 762 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 766 | /* look up gpio for ddc, hpd */ |
Alex Deucher | 2bfcc0f | 2010-05-18 19:26:46 -0400 | [diff] [blame] | 767 | ddc_bus.valid = false; |
| 768 | hpd.hpd = RADEON_HPD_NONE; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 769 | if ((le16_to_cpu(path->usDeviceTag) & |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 770 | (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 771 | for (j = 0; j < con_obj->ucNumberOfObjects; j++) { |
| 772 | if (le16_to_cpu(path->usConnObjectId) == |
| 773 | le16_to_cpu(con_obj->asObjects[j]. |
| 774 | usObjectID)) { |
| 775 | ATOM_COMMON_RECORD_HEADER |
| 776 | *record = |
| 777 | (ATOM_COMMON_RECORD_HEADER |
| 778 | *) |
| 779 | (ctx->bios + data_offset + |
| 780 | le16_to_cpu(con_obj-> |
| 781 | asObjects[j]. |
| 782 | usRecordOffset)); |
| 783 | ATOM_I2C_RECORD *i2c_record; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 784 | ATOM_HPD_INT_RECORD *hpd_record; |
Alex Deucher | d3f420d | 2009-12-08 14:30:49 -0500 | [diff] [blame] | 785 | ATOM_I2C_ID_CONFIG_ACCESS *i2c_config; |
Alex Deucher | 6a93cb2 | 2009-11-23 17:39:28 -0500 | [diff] [blame] | 786 | |
John Lindgren | 97ea530 | 2011-03-24 23:28:31 +0000 | [diff] [blame] | 787 | while (record->ucRecordSize > 0 && |
| 788 | record->ucRecordType > 0 && |
| 789 | record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) { |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 790 | switch (record->ucRecordType) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 791 | case ATOM_I2C_RECORD_TYPE: |
| 792 | i2c_record = |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 793 | (ATOM_I2C_RECORD *) |
| 794 | record; |
Alex Deucher | d3f420d | 2009-12-08 14:30:49 -0500 | [diff] [blame] | 795 | i2c_config = |
| 796 | (ATOM_I2C_ID_CONFIG_ACCESS *) |
| 797 | &i2c_record->sucI2cId; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 798 | ddc_bus = radeon_lookup_i2c_gpio(rdev, |
Alex Deucher | d3f420d | 2009-12-08 14:30:49 -0500 | [diff] [blame] | 799 | i2c_config-> |
| 800 | ucAccess); |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 801 | break; |
| 802 | case ATOM_HPD_INT_RECORD_TYPE: |
| 803 | hpd_record = |
| 804 | (ATOM_HPD_INT_RECORD *) |
| 805 | record; |
| 806 | gpio = radeon_lookup_gpio(rdev, |
| 807 | hpd_record->ucHPDIntGPIOID); |
| 808 | hpd = radeon_atom_get_hpd_info_from_gpio(rdev, &gpio); |
| 809 | hpd.plugged_state = hpd_record->ucPlugged_PinState; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 810 | break; |
| 811 | } |
| 812 | record = |
| 813 | (ATOM_COMMON_RECORD_HEADER |
| 814 | *) ((char *)record |
| 815 | + |
| 816 | record-> |
| 817 | ucRecordSize); |
| 818 | } |
| 819 | break; |
| 820 | } |
| 821 | } |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 822 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 823 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 824 | /* needed for aux chan transactions */ |
Alex Deucher | 8e36ed0 | 2010-05-18 19:26:47 -0400 | [diff] [blame] | 825 | ddc_bus.hpd = hpd.hpd; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 826 | |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 827 | conn_id = le16_to_cpu(path->usConnObjectId); |
| 828 | |
| 829 | if (!radeon_atom_apply_quirks |
| 830 | (dev, le16_to_cpu(path->usDeviceTag), &connector_type, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 831 | &ddc_bus, &conn_id, &hpd)) |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 832 | continue; |
| 833 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 834 | radeon_add_atom_connector(dev, |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 835 | conn_id, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 836 | le16_to_cpu(path-> |
| 837 | usDeviceTag), |
| 838 | connector_type, &ddc_bus, |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 839 | igp_lane_info, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 840 | connector_object_id, |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 841 | &hpd, |
| 842 | &router); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 843 | |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | radeon_link_encoder_connector(dev); |
| 848 | |
| 849 | return true; |
| 850 | } |
| 851 | |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 852 | static uint16_t atombios_get_connector_object_id(struct drm_device *dev, |
| 853 | int connector_type, |
| 854 | uint16_t devices) |
| 855 | { |
| 856 | struct radeon_device *rdev = dev->dev_private; |
| 857 | |
| 858 | if (rdev->flags & RADEON_IS_IGP) { |
| 859 | return supported_devices_connector_object_id_convert |
| 860 | [connector_type]; |
| 861 | } else if (((connector_type == DRM_MODE_CONNECTOR_DVII) || |
| 862 | (connector_type == DRM_MODE_CONNECTOR_DVID)) && |
| 863 | (devices & ATOM_DEVICE_DFP2_SUPPORT)) { |
| 864 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 865 | struct atom_context *ctx = mode_info->atom_context; |
| 866 | int index = GetIndexIntoMasterTable(DATA, XTMDS_Info); |
| 867 | uint16_t size, data_offset; |
| 868 | uint8_t frev, crev; |
| 869 | ATOM_XTMDS_INFO *xtmds; |
| 870 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 871 | if (atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset)) { |
| 872 | xtmds = (ATOM_XTMDS_INFO *)(ctx->bios + data_offset); |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 873 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 874 | if (xtmds->ucSupportedLink & ATOM_XTMDS_SUPPORTED_DUALLINK) { |
| 875 | if (connector_type == DRM_MODE_CONNECTOR_DVII) |
| 876 | return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I; |
| 877 | else |
| 878 | return CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D; |
| 879 | } else { |
| 880 | if (connector_type == DRM_MODE_CONNECTOR_DVII) |
| 881 | return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I; |
| 882 | else |
| 883 | return CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D; |
| 884 | } |
| 885 | } else |
| 886 | return supported_devices_connector_object_id_convert |
| 887 | [connector_type]; |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 888 | } else { |
| 889 | return supported_devices_connector_object_id_convert |
| 890 | [connector_type]; |
| 891 | } |
| 892 | } |
| 893 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 894 | struct bios_connector { |
| 895 | bool valid; |
Alex Deucher | 705af9c | 2009-09-10 16:31:13 -0400 | [diff] [blame] | 896 | uint16_t line_mux; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 897 | uint16_t devices; |
| 898 | int connector_type; |
| 899 | struct radeon_i2c_bus_rec ddc_bus; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 900 | struct radeon_hpd hpd; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 901 | }; |
| 902 | |
| 903 | bool radeon_get_atom_connector_info_from_supported_devices_table(struct |
| 904 | drm_device |
| 905 | *dev) |
| 906 | { |
| 907 | struct radeon_device *rdev = dev->dev_private; |
| 908 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 909 | struct atom_context *ctx = mode_info->atom_context; |
| 910 | int index = GetIndexIntoMasterTable(DATA, SupportedDevicesInfo); |
| 911 | uint16_t size, data_offset; |
| 912 | uint8_t frev, crev; |
| 913 | uint16_t device_support; |
| 914 | uint8_t dac; |
| 915 | union atom_supported_devices *supported_devices; |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 916 | int i, j, max_device; |
Prarit Bhargava | f49d273 | 2010-05-24 10:24:07 +1000 | [diff] [blame] | 917 | struct bios_connector *bios_connectors; |
| 918 | size_t bc_size = sizeof(*bios_connectors) * ATOM_MAX_SUPPORTED_DEVICE; |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 919 | struct radeon_router router; |
| 920 | |
Alex Deucher | fb939df | 2010-11-08 16:08:29 +0000 | [diff] [blame] | 921 | router.ddc_valid = false; |
| 922 | router.cd_valid = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 923 | |
Prarit Bhargava | f49d273 | 2010-05-24 10:24:07 +1000 | [diff] [blame] | 924 | bios_connectors = kzalloc(bc_size, GFP_KERNEL); |
| 925 | if (!bios_connectors) |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 926 | return false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 927 | |
Prarit Bhargava | f49d273 | 2010-05-24 10:24:07 +1000 | [diff] [blame] | 928 | if (!atom_parse_data_header(ctx, index, &size, &frev, &crev, |
| 929 | &data_offset)) { |
| 930 | kfree(bios_connectors); |
| 931 | return false; |
| 932 | } |
| 933 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 934 | supported_devices = |
| 935 | (union atom_supported_devices *)(ctx->bios + data_offset); |
| 936 | |
| 937 | device_support = le16_to_cpu(supported_devices->info.usDeviceSupport); |
| 938 | |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 939 | if (frev > 1) |
| 940 | max_device = ATOM_MAX_SUPPORTED_DEVICE; |
| 941 | else |
| 942 | max_device = ATOM_MAX_SUPPORTED_DEVICE_INFO; |
| 943 | |
| 944 | for (i = 0; i < max_device; i++) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 945 | ATOM_CONNECTOR_INFO_I2C ci = |
| 946 | supported_devices->info.asConnInfo[i]; |
| 947 | |
| 948 | bios_connectors[i].valid = false; |
| 949 | |
| 950 | if (!(device_support & (1 << i))) { |
| 951 | continue; |
| 952 | } |
| 953 | |
| 954 | if (i == ATOM_DEVICE_CV_INDEX) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 955 | DRM_DEBUG_KMS("Skipping Component Video\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 956 | continue; |
| 957 | } |
| 958 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 959 | bios_connectors[i].connector_type = |
| 960 | supported_devices_connector_convert[ci.sucConnectorInfo. |
| 961 | sbfAccess. |
| 962 | bfConnectorType]; |
| 963 | |
| 964 | if (bios_connectors[i].connector_type == |
| 965 | DRM_MODE_CONNECTOR_Unknown) |
| 966 | continue; |
| 967 | |
| 968 | dac = ci.sucConnectorInfo.sbfAccess.bfAssociatedDAC; |
| 969 | |
Alex Deucher | d3f420d | 2009-12-08 14:30:49 -0500 | [diff] [blame] | 970 | bios_connectors[i].line_mux = |
| 971 | ci.sucI2cId.ucAccess; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 972 | |
| 973 | /* give tv unique connector ids */ |
| 974 | if (i == ATOM_DEVICE_TV1_INDEX) { |
| 975 | bios_connectors[i].ddc_bus.valid = false; |
| 976 | bios_connectors[i].line_mux = 50; |
| 977 | } else if (i == ATOM_DEVICE_TV2_INDEX) { |
| 978 | bios_connectors[i].ddc_bus.valid = false; |
| 979 | bios_connectors[i].line_mux = 51; |
| 980 | } else if (i == ATOM_DEVICE_CV_INDEX) { |
| 981 | bios_connectors[i].ddc_bus.valid = false; |
| 982 | bios_connectors[i].line_mux = 52; |
| 983 | } else |
| 984 | bios_connectors[i].ddc_bus = |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 985 | radeon_lookup_i2c_gpio(rdev, |
| 986 | bios_connectors[i].line_mux); |
| 987 | |
| 988 | if ((crev > 1) && (frev > 1)) { |
| 989 | u8 isb = supported_devices->info_2d1.asIntSrcInfo[i].ucIntSrcBitmap; |
| 990 | switch (isb) { |
| 991 | case 0x4: |
| 992 | bios_connectors[i].hpd.hpd = RADEON_HPD_1; |
| 993 | break; |
| 994 | case 0xa: |
| 995 | bios_connectors[i].hpd.hpd = RADEON_HPD_2; |
| 996 | break; |
| 997 | default: |
| 998 | bios_connectors[i].hpd.hpd = RADEON_HPD_NONE; |
| 999 | break; |
| 1000 | } |
| 1001 | } else { |
| 1002 | if (i == ATOM_DEVICE_DFP1_INDEX) |
| 1003 | bios_connectors[i].hpd.hpd = RADEON_HPD_1; |
| 1004 | else if (i == ATOM_DEVICE_DFP2_INDEX) |
| 1005 | bios_connectors[i].hpd.hpd = RADEON_HPD_2; |
| 1006 | else |
| 1007 | bios_connectors[i].hpd.hpd = RADEON_HPD_NONE; |
| 1008 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1009 | |
| 1010 | /* Always set the connector type to VGA for CRT1/CRT2. if they are |
| 1011 | * shared with a DVI port, we'll pick up the DVI connector when we |
| 1012 | * merge the outputs. Some bioses incorrectly list VGA ports as DVI. |
| 1013 | */ |
| 1014 | if (i == ATOM_DEVICE_CRT1_INDEX || i == ATOM_DEVICE_CRT2_INDEX) |
| 1015 | bios_connectors[i].connector_type = |
| 1016 | DRM_MODE_CONNECTOR_VGA; |
| 1017 | |
| 1018 | if (!radeon_atom_apply_quirks |
| 1019 | (dev, (1 << i), &bios_connectors[i].connector_type, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1020 | &bios_connectors[i].ddc_bus, &bios_connectors[i].line_mux, |
| 1021 | &bios_connectors[i].hpd)) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1022 | continue; |
| 1023 | |
| 1024 | bios_connectors[i].valid = true; |
| 1025 | bios_connectors[i].devices = (1 << i); |
| 1026 | |
| 1027 | if (ASIC_IS_AVIVO(rdev) || radeon_r4xx_atom) |
| 1028 | radeon_add_atom_encoder(dev, |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 1029 | radeon_get_encoder_enum(dev, |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1030 | (1 << i), |
| 1031 | dac), |
Alex Deucher | 36868bd | 2011-01-06 21:19:21 -0500 | [diff] [blame] | 1032 | (1 << i), |
| 1033 | 0); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1034 | else |
| 1035 | radeon_add_legacy_encoder(dev, |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 1036 | radeon_get_encoder_enum(dev, |
Alex Deucher | f56cd64 | 2009-12-18 11:28:22 -0500 | [diff] [blame] | 1037 | (1 << i), |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1038 | dac), |
| 1039 | (1 << i)); |
| 1040 | } |
| 1041 | |
| 1042 | /* combine shared connectors */ |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1043 | for (i = 0; i < max_device; i++) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1044 | if (bios_connectors[i].valid) { |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1045 | for (j = 0; j < max_device; j++) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1046 | if (bios_connectors[j].valid && (i != j)) { |
| 1047 | if (bios_connectors[i].line_mux == |
| 1048 | bios_connectors[j].line_mux) { |
Alex Deucher | f56cd64 | 2009-12-18 11:28:22 -0500 | [diff] [blame] | 1049 | /* make sure not to combine LVDS */ |
| 1050 | if (bios_connectors[i].devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 1051 | bios_connectors[i].line_mux = 53; |
| 1052 | bios_connectors[i].ddc_bus.valid = false; |
| 1053 | continue; |
| 1054 | } |
| 1055 | if (bios_connectors[j].devices & (ATOM_DEVICE_LCD_SUPPORT)) { |
| 1056 | bios_connectors[j].line_mux = 53; |
| 1057 | bios_connectors[j].ddc_bus.valid = false; |
| 1058 | continue; |
| 1059 | } |
| 1060 | /* combine analog and digital for DVI-I */ |
| 1061 | if (((bios_connectors[i].devices & (ATOM_DEVICE_DFP_SUPPORT)) && |
| 1062 | (bios_connectors[j].devices & (ATOM_DEVICE_CRT_SUPPORT))) || |
| 1063 | ((bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) && |
| 1064 | (bios_connectors[i].devices & (ATOM_DEVICE_CRT_SUPPORT)))) { |
| 1065 | bios_connectors[i].devices |= |
| 1066 | bios_connectors[j].devices; |
| 1067 | bios_connectors[i].connector_type = |
| 1068 | DRM_MODE_CONNECTOR_DVII; |
| 1069 | if (bios_connectors[j].devices & (ATOM_DEVICE_DFP_SUPPORT)) |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1070 | bios_connectors[i].hpd = |
| 1071 | bios_connectors[j].hpd; |
Alex Deucher | f56cd64 | 2009-12-18 11:28:22 -0500 | [diff] [blame] | 1072 | bios_connectors[j].valid = false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1073 | } |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | /* add the connectors */ |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1081 | for (i = 0; i < max_device; i++) { |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 1082 | if (bios_connectors[i].valid) { |
| 1083 | uint16_t connector_object_id = |
| 1084 | atombios_get_connector_object_id(dev, |
| 1085 | bios_connectors[i].connector_type, |
| 1086 | bios_connectors[i].devices); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1087 | radeon_add_atom_connector(dev, |
| 1088 | bios_connectors[i].line_mux, |
| 1089 | bios_connectors[i].devices, |
| 1090 | bios_connectors[i]. |
| 1091 | connector_type, |
| 1092 | &bios_connectors[i].ddc_bus, |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 1093 | 0, |
Alex Deucher | eed45b3 | 2009-12-04 14:45:27 -0500 | [diff] [blame] | 1094 | connector_object_id, |
Alex Deucher | 26b5bc9 | 2010-08-05 21:21:18 -0400 | [diff] [blame] | 1095 | &bios_connectors[i].hpd, |
| 1096 | &router); |
Alex Deucher | b75fad0 | 2009-11-05 13:16:01 -0500 | [diff] [blame] | 1097 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | radeon_link_encoder_connector(dev); |
| 1101 | |
Prarit Bhargava | f49d273 | 2010-05-24 10:24:07 +1000 | [diff] [blame] | 1102 | kfree(bios_connectors); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1103 | return true; |
| 1104 | } |
| 1105 | |
| 1106 | union firmware_info { |
| 1107 | ATOM_FIRMWARE_INFO info; |
| 1108 | ATOM_FIRMWARE_INFO_V1_2 info_12; |
| 1109 | ATOM_FIRMWARE_INFO_V1_3 info_13; |
| 1110 | ATOM_FIRMWARE_INFO_V1_4 info_14; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1111 | ATOM_FIRMWARE_INFO_V2_1 info_21; |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 1112 | ATOM_FIRMWARE_INFO_V2_2 info_22; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1113 | }; |
| 1114 | |
| 1115 | bool radeon_atom_get_clock_info(struct drm_device *dev) |
| 1116 | { |
| 1117 | struct radeon_device *rdev = dev->dev_private; |
| 1118 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1119 | int index = GetIndexIntoMasterTable(DATA, FirmwareInfo); |
| 1120 | union firmware_info *firmware_info; |
| 1121 | uint8_t frev, crev; |
| 1122 | struct radeon_pll *p1pll = &rdev->clock.p1pll; |
| 1123 | struct radeon_pll *p2pll = &rdev->clock.p2pll; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1124 | struct radeon_pll *dcpll = &rdev->clock.dcpll; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1125 | struct radeon_pll *spll = &rdev->clock.spll; |
| 1126 | struct radeon_pll *mpll = &rdev->clock.mpll; |
| 1127 | uint16_t data_offset; |
| 1128 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1129 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 1130 | &frev, &crev, &data_offset)) { |
| 1131 | firmware_info = |
| 1132 | (union firmware_info *)(mode_info->atom_context->bios + |
| 1133 | data_offset); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1134 | /* pixel clocks */ |
| 1135 | p1pll->reference_freq = |
| 1136 | le16_to_cpu(firmware_info->info.usReferenceClock); |
| 1137 | p1pll->reference_div = 0; |
| 1138 | |
Mathias Fröhlich | bc293e5 | 2009-10-19 17:49:49 -0400 | [diff] [blame] | 1139 | if (crev < 2) |
| 1140 | p1pll->pll_out_min = |
| 1141 | le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Output); |
| 1142 | else |
| 1143 | p1pll->pll_out_min = |
| 1144 | le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1145 | p1pll->pll_out_max = |
| 1146 | le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output); |
| 1147 | |
Alex Deucher | 86cb2bb | 2010-03-08 12:55:16 -0500 | [diff] [blame] | 1148 | if (crev >= 4) { |
| 1149 | p1pll->lcd_pll_out_min = |
| 1150 | le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100; |
| 1151 | if (p1pll->lcd_pll_out_min == 0) |
| 1152 | p1pll->lcd_pll_out_min = p1pll->pll_out_min; |
| 1153 | p1pll->lcd_pll_out_max = |
| 1154 | le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100; |
| 1155 | if (p1pll->lcd_pll_out_max == 0) |
| 1156 | p1pll->lcd_pll_out_max = p1pll->pll_out_max; |
| 1157 | } else { |
| 1158 | p1pll->lcd_pll_out_min = p1pll->pll_out_min; |
| 1159 | p1pll->lcd_pll_out_max = p1pll->pll_out_max; |
| 1160 | } |
| 1161 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1162 | if (p1pll->pll_out_min == 0) { |
| 1163 | if (ASIC_IS_AVIVO(rdev)) |
| 1164 | p1pll->pll_out_min = 64800; |
| 1165 | else |
| 1166 | p1pll->pll_out_min = 20000; |
| 1167 | } |
| 1168 | |
| 1169 | p1pll->pll_in_min = |
| 1170 | le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input); |
| 1171 | p1pll->pll_in_max = |
| 1172 | le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input); |
| 1173 | |
| 1174 | *p2pll = *p1pll; |
| 1175 | |
| 1176 | /* system clock */ |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 1177 | if (ASIC_IS_DCE4(rdev)) |
| 1178 | spll->reference_freq = |
| 1179 | le16_to_cpu(firmware_info->info_21.usCoreReferenceClock); |
| 1180 | else |
| 1181 | spll->reference_freq = |
| 1182 | le16_to_cpu(firmware_info->info.usReferenceClock); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1183 | spll->reference_div = 0; |
| 1184 | |
| 1185 | spll->pll_out_min = |
| 1186 | le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output); |
| 1187 | spll->pll_out_max = |
| 1188 | le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output); |
| 1189 | |
| 1190 | /* ??? */ |
| 1191 | if (spll->pll_out_min == 0) { |
| 1192 | if (ASIC_IS_AVIVO(rdev)) |
| 1193 | spll->pll_out_min = 64800; |
| 1194 | else |
| 1195 | spll->pll_out_min = 20000; |
| 1196 | } |
| 1197 | |
| 1198 | spll->pll_in_min = |
| 1199 | le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input); |
| 1200 | spll->pll_in_max = |
| 1201 | le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input); |
| 1202 | |
| 1203 | /* memory clock */ |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 1204 | if (ASIC_IS_DCE4(rdev)) |
| 1205 | mpll->reference_freq = |
| 1206 | le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock); |
| 1207 | else |
| 1208 | mpll->reference_freq = |
| 1209 | le16_to_cpu(firmware_info->info.usReferenceClock); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1210 | mpll->reference_div = 0; |
| 1211 | |
| 1212 | mpll->pll_out_min = |
| 1213 | le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output); |
| 1214 | mpll->pll_out_max = |
| 1215 | le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output); |
| 1216 | |
| 1217 | /* ??? */ |
| 1218 | if (mpll->pll_out_min == 0) { |
| 1219 | if (ASIC_IS_AVIVO(rdev)) |
| 1220 | mpll->pll_out_min = 64800; |
| 1221 | else |
| 1222 | mpll->pll_out_min = 20000; |
| 1223 | } |
| 1224 | |
| 1225 | mpll->pll_in_min = |
| 1226 | le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input); |
| 1227 | mpll->pll_in_max = |
| 1228 | le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input); |
| 1229 | |
| 1230 | rdev->clock.default_sclk = |
| 1231 | le32_to_cpu(firmware_info->info.ulDefaultEngineClock); |
| 1232 | rdev->clock.default_mclk = |
| 1233 | le32_to_cpu(firmware_info->info.ulDefaultMemoryClock); |
| 1234 | |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1235 | if (ASIC_IS_DCE4(rdev)) { |
| 1236 | rdev->clock.default_dispclk = |
| 1237 | le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq); |
Alex Deucher | f82b3dd | 2011-01-06 21:19:15 -0500 | [diff] [blame] | 1238 | if (rdev->clock.default_dispclk == 0) { |
| 1239 | if (ASIC_IS_DCE5(rdev)) |
| 1240 | rdev->clock.default_dispclk = 54000; /* 540 Mhz */ |
| 1241 | else |
| 1242 | rdev->clock.default_dispclk = 60000; /* 600 Mhz */ |
| 1243 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1244 | rdev->clock.dp_extclk = |
| 1245 | le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq); |
Alex Deucher | 4489cd62 | 2013-03-22 15:59:10 -0400 | [diff] [blame] | 1246 | rdev->clock.current_dispclk = rdev->clock.default_dispclk; |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1247 | } |
| 1248 | *dcpll = *p1pll; |
| 1249 | |
Alex Deucher | b20f9be | 2011-06-08 13:01:11 -0400 | [diff] [blame] | 1250 | rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock); |
| 1251 | if (rdev->clock.max_pixel_clock == 0) |
| 1252 | rdev->clock.max_pixel_clock = 40000; |
| 1253 | |
Alex Deucher | af7912e | 2012-07-26 09:50:57 -0400 | [diff] [blame] | 1254 | /* not technically a clock, but... */ |
| 1255 | rdev->mode_info.firmware_flags = |
| 1256 | le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess); |
| 1257 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1258 | return true; |
| 1259 | } |
Alex Deucher | bcc1c2a | 2010-01-12 17:54:34 -0500 | [diff] [blame] | 1260 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1261 | return false; |
| 1262 | } |
| 1263 | |
Alex Deucher | 06b6476 | 2010-01-05 11:27:29 -0500 | [diff] [blame] | 1264 | union igp_info { |
| 1265 | struct _ATOM_INTEGRATED_SYSTEM_INFO info; |
| 1266 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2; |
Alex Deucher | 3838f46 | 2012-07-25 12:32:59 -0400 | [diff] [blame] | 1267 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6; |
| 1268 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7; |
Alex Deucher | c2037ad | 2012-07-25 12:45:16 -0400 | [diff] [blame] | 1269 | struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8; |
Alex Deucher | 06b6476 | 2010-01-05 11:27:29 -0500 | [diff] [blame] | 1270 | }; |
| 1271 | |
| 1272 | bool radeon_atombios_sideport_present(struct radeon_device *rdev) |
| 1273 | { |
| 1274 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1275 | int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo); |
| 1276 | union igp_info *igp_info; |
| 1277 | u8 frev, crev; |
| 1278 | u16 data_offset; |
| 1279 | |
Alex Deucher | 4c70b2e | 2010-08-02 19:39:15 -0400 | [diff] [blame] | 1280 | /* sideport is AMD only */ |
| 1281 | if (rdev->family == CHIP_RS600) |
| 1282 | return false; |
| 1283 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1284 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 1285 | &frev, &crev, &data_offset)) { |
| 1286 | igp_info = (union igp_info *)(mode_info->atom_context->bios + |
Alex Deucher | 06b6476 | 2010-01-05 11:27:29 -0500 | [diff] [blame] | 1287 | data_offset); |
Alex Deucher | 06b6476 | 2010-01-05 11:27:29 -0500 | [diff] [blame] | 1288 | switch (crev) { |
| 1289 | case 1: |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 1290 | if (le32_to_cpu(igp_info->info.ulBootUpMemoryClock)) |
Alex Deucher | 4c70b2e | 2010-08-02 19:39:15 -0400 | [diff] [blame] | 1291 | return true; |
Alex Deucher | 06b6476 | 2010-01-05 11:27:29 -0500 | [diff] [blame] | 1292 | break; |
| 1293 | case 2: |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 1294 | if (le32_to_cpu(igp_info->info_2.ulBootUpSidePortClock)) |
Alex Deucher | 06b6476 | 2010-01-05 11:27:29 -0500 | [diff] [blame] | 1295 | return true; |
| 1296 | break; |
| 1297 | default: |
| 1298 | DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev); |
| 1299 | break; |
| 1300 | } |
| 1301 | } |
| 1302 | return false; |
| 1303 | } |
| 1304 | |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1305 | bool radeon_atombios_get_tmds_info(struct radeon_encoder *encoder, |
| 1306 | struct radeon_encoder_int_tmds *tmds) |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1307 | { |
| 1308 | struct drm_device *dev = encoder->base.dev; |
| 1309 | struct radeon_device *rdev = dev->dev_private; |
| 1310 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1311 | int index = GetIndexIntoMasterTable(DATA, TMDS_Info); |
| 1312 | uint16_t data_offset; |
| 1313 | struct _ATOM_TMDS_INFO *tmds_info; |
| 1314 | uint8_t frev, crev; |
| 1315 | uint16_t maxfreq; |
| 1316 | int i; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1317 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1318 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 1319 | &frev, &crev, &data_offset)) { |
| 1320 | tmds_info = |
| 1321 | (struct _ATOM_TMDS_INFO *)(mode_info->atom_context->bios + |
| 1322 | data_offset); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1323 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1324 | maxfreq = le16_to_cpu(tmds_info->usMaxFrequency); |
| 1325 | for (i = 0; i < 4; i++) { |
| 1326 | tmds->tmds_pll[i].freq = |
| 1327 | le16_to_cpu(tmds_info->asMiscInfo[i].usFrequency); |
| 1328 | tmds->tmds_pll[i].value = |
| 1329 | tmds_info->asMiscInfo[i].ucPLL_ChargePump & 0x3f; |
| 1330 | tmds->tmds_pll[i].value |= |
| 1331 | (tmds_info->asMiscInfo[i]. |
| 1332 | ucPLL_VCO_Gain & 0x3f) << 6; |
| 1333 | tmds->tmds_pll[i].value |= |
| 1334 | (tmds_info->asMiscInfo[i]. |
| 1335 | ucPLL_DutyCycle & 0xf) << 12; |
| 1336 | tmds->tmds_pll[i].value |= |
| 1337 | (tmds_info->asMiscInfo[i]. |
| 1338 | ucPLL_VoltageSwing & 0xf) << 16; |
| 1339 | |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 1340 | DRM_DEBUG_KMS("TMDS PLL From ATOMBIOS %u %x\n", |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1341 | tmds->tmds_pll[i].freq, |
| 1342 | tmds->tmds_pll[i].value); |
| 1343 | |
| 1344 | if (maxfreq == tmds->tmds_pll[i].freq) { |
| 1345 | tmds->tmds_pll[i].freq = 0xffffffff; |
| 1346 | break; |
| 1347 | } |
| 1348 | } |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1349 | return true; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1350 | } |
Dave Airlie | 445282d | 2009-09-09 17:40:54 +1000 | [diff] [blame] | 1351 | return false; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1352 | } |
| 1353 | |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1354 | bool radeon_atombios_get_ppll_ss_info(struct radeon_device *rdev, |
| 1355 | struct radeon_atom_ss *ss, |
| 1356 | int id) |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1357 | { |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1358 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1359 | int index = GetIndexIntoMasterTable(DATA, PPLL_SS_Info); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1360 | uint16_t data_offset, size; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1361 | struct _ATOM_SPREAD_SPECTRUM_INFO *ss_info; |
| 1362 | uint8_t frev, crev; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1363 | int i, num_indices; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1364 | |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1365 | memset(ss, 0, sizeof(struct radeon_atom_ss)); |
| 1366 | if (atom_parse_data_header(mode_info->atom_context, index, &size, |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1367 | &frev, &crev, &data_offset)) { |
| 1368 | ss_info = |
| 1369 | (struct _ATOM_SPREAD_SPECTRUM_INFO *)(mode_info->atom_context->bios + data_offset); |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1370 | |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1371 | num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / |
| 1372 | sizeof(ATOM_SPREAD_SPECTRUM_ASSIGNMENT); |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1373 | |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1374 | for (i = 0; i < num_indices; i++) { |
Alex Deucher | 279b215 | 2009-12-08 14:07:03 -0500 | [diff] [blame] | 1375 | if (ss_info->asSS_Info[i].ucSS_Id == id) { |
| 1376 | ss->percentage = |
| 1377 | le16_to_cpu(ss_info->asSS_Info[i].usSpreadSpectrumPercentage); |
| 1378 | ss->type = ss_info->asSS_Info[i].ucSpreadSpectrumType; |
| 1379 | ss->step = ss_info->asSS_Info[i].ucSS_Step; |
| 1380 | ss->delay = ss_info->asSS_Info[i].ucSS_Delay; |
| 1381 | ss->range = ss_info->asSS_Info[i].ucSS_Range; |
| 1382 | ss->refdiv = ss_info->asSS_Info[i].ucRecommendedRef_Div; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1383 | return true; |
Alex Deucher | 279b215 | 2009-12-08 14:07:03 -0500 | [diff] [blame] | 1384 | } |
| 1385 | } |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1386 | } |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1387 | return false; |
| 1388 | } |
| 1389 | |
Alex Deucher | 4339c44 | 2010-11-22 17:56:25 -0500 | [diff] [blame] | 1390 | static void radeon_atombios_get_igp_ss_overrides(struct radeon_device *rdev, |
| 1391 | struct radeon_atom_ss *ss, |
| 1392 | int id) |
| 1393 | { |
| 1394 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1395 | int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo); |
| 1396 | u16 data_offset, size; |
Alex Deucher | 3838f46 | 2012-07-25 12:32:59 -0400 | [diff] [blame] | 1397 | union igp_info *igp_info; |
Alex Deucher | 4339c44 | 2010-11-22 17:56:25 -0500 | [diff] [blame] | 1398 | u8 frev, crev; |
| 1399 | u16 percentage = 0, rate = 0; |
| 1400 | |
| 1401 | /* get any igp specific overrides */ |
| 1402 | if (atom_parse_data_header(mode_info->atom_context, index, &size, |
| 1403 | &frev, &crev, &data_offset)) { |
Alex Deucher | 3838f46 | 2012-07-25 12:32:59 -0400 | [diff] [blame] | 1404 | igp_info = (union igp_info *) |
Alex Deucher | 4339c44 | 2010-11-22 17:56:25 -0500 | [diff] [blame] | 1405 | (mode_info->atom_context->bios + data_offset); |
Alex Deucher | 3838f46 | 2012-07-25 12:32:59 -0400 | [diff] [blame] | 1406 | switch (crev) { |
| 1407 | case 6: |
| 1408 | switch (id) { |
| 1409 | case ASIC_INTERNAL_SS_ON_TMDS: |
| 1410 | percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage); |
| 1411 | rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz); |
| 1412 | break; |
| 1413 | case ASIC_INTERNAL_SS_ON_HDMI: |
| 1414 | percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage); |
| 1415 | rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz); |
| 1416 | break; |
| 1417 | case ASIC_INTERNAL_SS_ON_LVDS: |
| 1418 | percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage); |
| 1419 | rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz); |
| 1420 | break; |
| 1421 | } |
Alex Deucher | 4339c44 | 2010-11-22 17:56:25 -0500 | [diff] [blame] | 1422 | break; |
Alex Deucher | 3838f46 | 2012-07-25 12:32:59 -0400 | [diff] [blame] | 1423 | case 7: |
| 1424 | switch (id) { |
| 1425 | case ASIC_INTERNAL_SS_ON_TMDS: |
| 1426 | percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage); |
| 1427 | rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz); |
| 1428 | break; |
| 1429 | case ASIC_INTERNAL_SS_ON_HDMI: |
| 1430 | percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage); |
| 1431 | rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz); |
| 1432 | break; |
| 1433 | case ASIC_INTERNAL_SS_ON_LVDS: |
| 1434 | percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage); |
| 1435 | rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz); |
| 1436 | break; |
| 1437 | } |
Alex Deucher | 4339c44 | 2010-11-22 17:56:25 -0500 | [diff] [blame] | 1438 | break; |
Alex Deucher | c2037ad | 2012-07-25 12:45:16 -0400 | [diff] [blame] | 1439 | case 8: |
| 1440 | switch (id) { |
| 1441 | case ASIC_INTERNAL_SS_ON_TMDS: |
| 1442 | percentage = le16_to_cpu(igp_info->info_8.usDVISSPercentage); |
| 1443 | rate = le16_to_cpu(igp_info->info_8.usDVISSpreadRateIn10Hz); |
| 1444 | break; |
| 1445 | case ASIC_INTERNAL_SS_ON_HDMI: |
| 1446 | percentage = le16_to_cpu(igp_info->info_8.usHDMISSPercentage); |
| 1447 | rate = le16_to_cpu(igp_info->info_8.usHDMISSpreadRateIn10Hz); |
| 1448 | break; |
| 1449 | case ASIC_INTERNAL_SS_ON_LVDS: |
| 1450 | percentage = le16_to_cpu(igp_info->info_8.usLvdsSSPercentage); |
| 1451 | rate = le16_to_cpu(igp_info->info_8.usLvdsSSpreadRateIn10Hz); |
| 1452 | break; |
| 1453 | } |
| 1454 | break; |
Alex Deucher | 3838f46 | 2012-07-25 12:32:59 -0400 | [diff] [blame] | 1455 | default: |
| 1456 | DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev); |
Alex Deucher | 4339c44 | 2010-11-22 17:56:25 -0500 | [diff] [blame] | 1457 | break; |
| 1458 | } |
| 1459 | if (percentage) |
| 1460 | ss->percentage = percentage; |
| 1461 | if (rate) |
| 1462 | ss->rate = rate; |
| 1463 | } |
| 1464 | } |
| 1465 | |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1466 | union asic_ss_info { |
| 1467 | struct _ATOM_ASIC_INTERNAL_SS_INFO info; |
| 1468 | struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2; |
| 1469 | struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3; |
| 1470 | }; |
| 1471 | |
| 1472 | bool radeon_atombios_get_asic_ss_info(struct radeon_device *rdev, |
| 1473 | struct radeon_atom_ss *ss, |
| 1474 | int id, u32 clock) |
| 1475 | { |
| 1476 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1477 | int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info); |
| 1478 | uint16_t data_offset, size; |
| 1479 | union asic_ss_info *ss_info; |
| 1480 | uint8_t frev, crev; |
| 1481 | int i, num_indices; |
| 1482 | |
| 1483 | memset(ss, 0, sizeof(struct radeon_atom_ss)); |
| 1484 | if (atom_parse_data_header(mode_info->atom_context, index, &size, |
| 1485 | &frev, &crev, &data_offset)) { |
| 1486 | |
| 1487 | ss_info = |
| 1488 | (union asic_ss_info *)(mode_info->atom_context->bios + data_offset); |
| 1489 | |
| 1490 | switch (frev) { |
| 1491 | case 1: |
| 1492 | num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / |
| 1493 | sizeof(ATOM_ASIC_SS_ASSIGNMENT); |
| 1494 | |
| 1495 | for (i = 0; i < num_indices; i++) { |
| 1496 | if ((ss_info->info.asSpreadSpectrum[i].ucClockIndication == id) && |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 1497 | (clock <= le32_to_cpu(ss_info->info.asSpreadSpectrum[i].ulTargetClockRange))) { |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1498 | ss->percentage = |
| 1499 | le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadSpectrumPercentage); |
| 1500 | ss->type = ss_info->info.asSpreadSpectrum[i].ucSpreadSpectrumMode; |
| 1501 | ss->rate = le16_to_cpu(ss_info->info.asSpreadSpectrum[i].usSpreadRateInKhz); |
| 1502 | return true; |
| 1503 | } |
| 1504 | } |
| 1505 | break; |
| 1506 | case 2: |
| 1507 | num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / |
| 1508 | sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2); |
| 1509 | for (i = 0; i < num_indices; i++) { |
| 1510 | if ((ss_info->info_2.asSpreadSpectrum[i].ucClockIndication == id) && |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 1511 | (clock <= le32_to_cpu(ss_info->info_2.asSpreadSpectrum[i].ulTargetClockRange))) { |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1512 | ss->percentage = |
| 1513 | le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadSpectrumPercentage); |
| 1514 | ss->type = ss_info->info_2.asSpreadSpectrum[i].ucSpreadSpectrumMode; |
| 1515 | ss->rate = le16_to_cpu(ss_info->info_2.asSpreadSpectrum[i].usSpreadRateIn10Hz); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 1516 | if ((crev == 2) && |
| 1517 | ((id == ASIC_INTERNAL_ENGINE_SS) || |
| 1518 | (id == ASIC_INTERNAL_MEMORY_SS))) |
| 1519 | ss->rate /= 100; |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1520 | return true; |
| 1521 | } |
| 1522 | } |
| 1523 | break; |
| 1524 | case 3: |
| 1525 | num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / |
| 1526 | sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3); |
| 1527 | for (i = 0; i < num_indices; i++) { |
| 1528 | if ((ss_info->info_3.asSpreadSpectrum[i].ucClockIndication == id) && |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 1529 | (clock <= le32_to_cpu(ss_info->info_3.asSpreadSpectrum[i].ulTargetClockRange))) { |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1530 | ss->percentage = |
| 1531 | le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadSpectrumPercentage); |
| 1532 | ss->type = ss_info->info_3.asSpreadSpectrum[i].ucSpreadSpectrumMode; |
| 1533 | ss->rate = le16_to_cpu(ss_info->info_3.asSpreadSpectrum[i].usSpreadRateIn10Hz); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 1534 | if ((id == ASIC_INTERNAL_ENGINE_SS) || |
| 1535 | (id == ASIC_INTERNAL_MEMORY_SS)) |
| 1536 | ss->rate /= 100; |
Alex Deucher | 4339c44 | 2010-11-22 17:56:25 -0500 | [diff] [blame] | 1537 | if (rdev->flags & RADEON_IS_IGP) |
| 1538 | radeon_atombios_get_igp_ss_overrides(rdev, ss, id); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1539 | return true; |
| 1540 | } |
| 1541 | } |
| 1542 | break; |
| 1543 | default: |
| 1544 | DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev); |
| 1545 | break; |
| 1546 | } |
| 1547 | |
| 1548 | } |
| 1549 | return false; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1550 | } |
| 1551 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1552 | union lvds_info { |
| 1553 | struct _ATOM_LVDS_INFO info; |
| 1554 | struct _ATOM_LVDS_INFO_V12 info_12; |
| 1555 | }; |
| 1556 | |
| 1557 | struct radeon_encoder_atom_dig *radeon_atombios_get_lvds_info(struct |
| 1558 | radeon_encoder |
| 1559 | *encoder) |
| 1560 | { |
| 1561 | struct drm_device *dev = encoder->base.dev; |
| 1562 | struct radeon_device *rdev = dev->dev_private; |
| 1563 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1564 | int index = GetIndexIntoMasterTable(DATA, LVDS_Info); |
Alex Deucher | 7dde8a19 | 2009-11-30 01:40:24 -0500 | [diff] [blame] | 1565 | uint16_t data_offset, misc; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1566 | union lvds_info *lvds_info; |
| 1567 | uint8_t frev, crev; |
| 1568 | struct radeon_encoder_atom_dig *lvds = NULL; |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 1569 | int encoder_enum = (encoder->encoder_enum & ENUM_ID_MASK) >> ENUM_ID_SHIFT; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1570 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1571 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 1572 | &frev, &crev, &data_offset)) { |
| 1573 | lvds_info = |
| 1574 | (union lvds_info *)(mode_info->atom_context->bios + data_offset); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1575 | lvds = |
| 1576 | kzalloc(sizeof(struct radeon_encoder_atom_dig), GFP_KERNEL); |
| 1577 | |
| 1578 | if (!lvds) |
| 1579 | return NULL; |
| 1580 | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 1581 | lvds->native_mode.clock = |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1582 | le16_to_cpu(lvds_info->info.sLCDTiming.usPixClk) * 10; |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 1583 | lvds->native_mode.hdisplay = |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1584 | le16_to_cpu(lvds_info->info.sLCDTiming.usHActive); |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 1585 | lvds->native_mode.vdisplay = |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1586 | le16_to_cpu(lvds_info->info.sLCDTiming.usVActive); |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 1587 | lvds->native_mode.htotal = lvds->native_mode.hdisplay + |
| 1588 | le16_to_cpu(lvds_info->info.sLCDTiming.usHBlanking_Time); |
| 1589 | lvds->native_mode.hsync_start = lvds->native_mode.hdisplay + |
| 1590 | le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncOffset); |
| 1591 | lvds->native_mode.hsync_end = lvds->native_mode.hsync_start + |
| 1592 | le16_to_cpu(lvds_info->info.sLCDTiming.usHSyncWidth); |
| 1593 | lvds->native_mode.vtotal = lvds->native_mode.vdisplay + |
| 1594 | le16_to_cpu(lvds_info->info.sLCDTiming.usVBlanking_Time); |
| 1595 | lvds->native_mode.vsync_start = lvds->native_mode.vdisplay + |
Alex Deucher | 1ff26a3 | 2010-05-18 00:23:15 -0400 | [diff] [blame] | 1596 | le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncOffset); |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 1597 | lvds->native_mode.vsync_end = lvds->native_mode.vsync_start + |
| 1598 | le16_to_cpu(lvds_info->info.sLCDTiming.usVSyncWidth); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1599 | lvds->panel_pwr_delay = |
| 1600 | le16_to_cpu(lvds_info->info.usOffDelayInMs); |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1601 | lvds->lcd_misc = lvds_info->info.ucLVDS_Misc; |
Alex Deucher | 7dde8a19 | 2009-11-30 01:40:24 -0500 | [diff] [blame] | 1602 | |
| 1603 | misc = le16_to_cpu(lvds_info->info.sLCDTiming.susModeMiscInfo.usAccess); |
| 1604 | if (misc & ATOM_VSYNC_POLARITY) |
| 1605 | lvds->native_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
| 1606 | if (misc & ATOM_HSYNC_POLARITY) |
| 1607 | lvds->native_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
| 1608 | if (misc & ATOM_COMPOSITESYNC) |
| 1609 | lvds->native_mode.flags |= DRM_MODE_FLAG_CSYNC; |
| 1610 | if (misc & ATOM_INTERLACE) |
| 1611 | lvds->native_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 1612 | if (misc & ATOM_DOUBLE_CLOCK_MODE) |
| 1613 | lvds->native_mode.flags |= DRM_MODE_FLAG_DBLSCAN; |
| 1614 | |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 1615 | lvds->native_mode.width_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageHSize); |
| 1616 | lvds->native_mode.height_mm = le16_to_cpu(lvds_info->info.sLCDTiming.usImageVSize); |
Alex Deucher | 7a868e1 | 2010-12-08 22:13:05 -0500 | [diff] [blame] | 1617 | |
Alex Deucher | de2103e | 2009-10-09 15:14:30 -0400 | [diff] [blame] | 1618 | /* set crtc values */ |
| 1619 | drm_mode_set_crtcinfo(&lvds->native_mode, CRTC_INTERLACE_HALVE_V); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1620 | |
Alex Deucher | ba032a5 | 2010-10-04 17:13:01 -0400 | [diff] [blame] | 1621 | lvds->lcd_ss_id = lvds_info->info.ucSS_Id; |
Alex Deucher | ebbe1cb | 2009-10-16 11:15:25 -0400 | [diff] [blame] | 1622 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1623 | encoder->native_mode = lvds->native_mode; |
Alex Deucher | 5137ee9 | 2010-08-12 18:58:47 -0400 | [diff] [blame] | 1624 | |
| 1625 | if (encoder_enum == 2) |
| 1626 | lvds->linkb = true; |
| 1627 | else |
| 1628 | lvds->linkb = false; |
| 1629 | |
Alex Deucher | c324acd | 2010-12-08 22:13:06 -0500 | [diff] [blame] | 1630 | /* parse the lcd record table */ |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 1631 | if (le16_to_cpu(lvds_info->info.usModePatchTableOffset)) { |
Alex Deucher | c324acd | 2010-12-08 22:13:06 -0500 | [diff] [blame] | 1632 | ATOM_FAKE_EDID_PATCH_RECORD *fake_edid_record; |
| 1633 | ATOM_PANEL_RESOLUTION_PATCH_RECORD *panel_res_record; |
| 1634 | bool bad_record = false; |
Alex Deucher | 05fa7ea | 2011-05-11 14:02:07 -0400 | [diff] [blame] | 1635 | u8 *record; |
| 1636 | |
| 1637 | if ((frev == 1) && (crev < 2)) |
| 1638 | /* absolute */ |
| 1639 | record = (u8 *)(mode_info->atom_context->bios + |
| 1640 | le16_to_cpu(lvds_info->info.usModePatchTableOffset)); |
| 1641 | else |
| 1642 | /* relative */ |
| 1643 | record = (u8 *)(mode_info->atom_context->bios + |
| 1644 | data_offset + |
| 1645 | le16_to_cpu(lvds_info->info.usModePatchTableOffset)); |
Alex Deucher | c324acd | 2010-12-08 22:13:06 -0500 | [diff] [blame] | 1646 | while (*record != ATOM_RECORD_END_TYPE) { |
| 1647 | switch (*record) { |
| 1648 | case LCD_MODE_PATCH_RECORD_MODE_TYPE: |
| 1649 | record += sizeof(ATOM_PATCH_RECORD_MODE); |
| 1650 | break; |
| 1651 | case LCD_RTS_RECORD_TYPE: |
| 1652 | record += sizeof(ATOM_LCD_RTS_RECORD); |
| 1653 | break; |
| 1654 | case LCD_CAP_RECORD_TYPE: |
| 1655 | record += sizeof(ATOM_LCD_MODE_CONTROL_CAP); |
| 1656 | break; |
| 1657 | case LCD_FAKE_EDID_PATCH_RECORD_TYPE: |
| 1658 | fake_edid_record = (ATOM_FAKE_EDID_PATCH_RECORD *)record; |
| 1659 | if (fake_edid_record->ucFakeEDIDLength) { |
| 1660 | struct edid *edid; |
| 1661 | int edid_size = |
| 1662 | max((int)EDID_LENGTH, (int)fake_edid_record->ucFakeEDIDLength); |
| 1663 | edid = kmalloc(edid_size, GFP_KERNEL); |
| 1664 | if (edid) { |
| 1665 | memcpy((u8 *)edid, (u8 *)&fake_edid_record->ucFakeEDIDString[0], |
| 1666 | fake_edid_record->ucFakeEDIDLength); |
| 1667 | |
Dave Airlie | eaa4f5e | 2011-05-01 20:16:30 +1000 | [diff] [blame] | 1668 | if (drm_edid_is_valid(edid)) { |
Alex Deucher | c324acd | 2010-12-08 22:13:06 -0500 | [diff] [blame] | 1669 | rdev->mode_info.bios_hardcoded_edid = edid; |
Dave Airlie | eaa4f5e | 2011-05-01 20:16:30 +1000 | [diff] [blame] | 1670 | rdev->mode_info.bios_hardcoded_edid_size = edid_size; |
| 1671 | } else |
Alex Deucher | c324acd | 2010-12-08 22:13:06 -0500 | [diff] [blame] | 1672 | kfree(edid); |
| 1673 | } |
| 1674 | } |
| 1675 | record += sizeof(ATOM_FAKE_EDID_PATCH_RECORD); |
| 1676 | break; |
| 1677 | case LCD_PANEL_RESOLUTION_RECORD_TYPE: |
| 1678 | panel_res_record = (ATOM_PANEL_RESOLUTION_PATCH_RECORD *)record; |
| 1679 | lvds->native_mode.width_mm = panel_res_record->usHSize; |
| 1680 | lvds->native_mode.height_mm = panel_res_record->usVSize; |
| 1681 | record += sizeof(ATOM_PANEL_RESOLUTION_PATCH_RECORD); |
| 1682 | break; |
| 1683 | default: |
| 1684 | DRM_ERROR("Bad LCD record %d\n", *record); |
| 1685 | bad_record = true; |
| 1686 | break; |
| 1687 | } |
| 1688 | if (bad_record) |
| 1689 | break; |
| 1690 | } |
| 1691 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 1692 | } |
| 1693 | return lvds; |
| 1694 | } |
| 1695 | |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1696 | struct radeon_encoder_primary_dac * |
| 1697 | radeon_atombios_get_primary_dac_info(struct radeon_encoder *encoder) |
| 1698 | { |
| 1699 | struct drm_device *dev = encoder->base.dev; |
| 1700 | struct radeon_device *rdev = dev->dev_private; |
| 1701 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1702 | int index = GetIndexIntoMasterTable(DATA, CompassionateData); |
| 1703 | uint16_t data_offset; |
| 1704 | struct _COMPASSIONATE_DATA *dac_info; |
| 1705 | uint8_t frev, crev; |
| 1706 | uint8_t bg, dac; |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1707 | struct radeon_encoder_primary_dac *p_dac = NULL; |
| 1708 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1709 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 1710 | &frev, &crev, &data_offset)) { |
| 1711 | dac_info = (struct _COMPASSIONATE_DATA *) |
| 1712 | (mode_info->atom_context->bios + data_offset); |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1713 | |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1714 | p_dac = kzalloc(sizeof(struct radeon_encoder_primary_dac), GFP_KERNEL); |
| 1715 | |
| 1716 | if (!p_dac) |
| 1717 | return NULL; |
| 1718 | |
| 1719 | bg = dac_info->ucDAC1_BG_Adjustment; |
| 1720 | dac = dac_info->ucDAC1_DAC_Adjustment; |
| 1721 | p_dac->ps2_pdac_adj = (bg << 8) | (dac); |
| 1722 | |
| 1723 | } |
| 1724 | return p_dac; |
| 1725 | } |
| 1726 | |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1727 | bool radeon_atom_get_tv_timings(struct radeon_device *rdev, int index, |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1728 | struct drm_display_mode *mode) |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1729 | { |
| 1730 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1731 | ATOM_ANALOG_TV_INFO *tv_info; |
| 1732 | ATOM_ANALOG_TV_INFO_V1_2 *tv_info_v1_2; |
| 1733 | ATOM_DTD_FORMAT *dtd_timings; |
| 1734 | int data_index = GetIndexIntoMasterTable(DATA, AnalogTV_Info); |
| 1735 | u8 frev, crev; |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1736 | u16 data_offset, misc; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1737 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1738 | if (!atom_parse_data_header(mode_info->atom_context, data_index, NULL, |
| 1739 | &frev, &crev, &data_offset)) |
| 1740 | return false; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1741 | |
| 1742 | switch (crev) { |
| 1743 | case 1: |
| 1744 | tv_info = (ATOM_ANALOG_TV_INFO *)(mode_info->atom_context->bios + data_offset); |
Dan Carpenter | 0031c41 | 2010-04-27 14:11:04 -0700 | [diff] [blame] | 1745 | if (index >= MAX_SUPPORTED_TV_TIMING) |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1746 | return false; |
| 1747 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1748 | mode->crtc_htotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Total); |
| 1749 | mode->crtc_hdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_Disp); |
| 1750 | mode->crtc_hsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart); |
| 1751 | mode->crtc_hsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncStart) + |
| 1752 | le16_to_cpu(tv_info->aModeTimings[index].usCRTC_H_SyncWidth); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1753 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1754 | mode->crtc_vtotal = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Total); |
| 1755 | mode->crtc_vdisplay = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_Disp); |
| 1756 | mode->crtc_vsync_start = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart); |
| 1757 | mode->crtc_vsync_end = le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncStart) + |
| 1758 | le16_to_cpu(tv_info->aModeTimings[index].usCRTC_V_SyncWidth); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1759 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1760 | mode->flags = 0; |
| 1761 | misc = le16_to_cpu(tv_info->aModeTimings[index].susModeMiscInfo.usAccess); |
| 1762 | if (misc & ATOM_VSYNC_POLARITY) |
| 1763 | mode->flags |= DRM_MODE_FLAG_NVSYNC; |
| 1764 | if (misc & ATOM_HSYNC_POLARITY) |
| 1765 | mode->flags |= DRM_MODE_FLAG_NHSYNC; |
| 1766 | if (misc & ATOM_COMPOSITESYNC) |
| 1767 | mode->flags |= DRM_MODE_FLAG_CSYNC; |
| 1768 | if (misc & ATOM_INTERLACE) |
| 1769 | mode->flags |= DRM_MODE_FLAG_INTERLACE; |
| 1770 | if (misc & ATOM_DOUBLE_CLOCK_MODE) |
| 1771 | mode->flags |= DRM_MODE_FLAG_DBLSCAN; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1772 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1773 | mode->clock = le16_to_cpu(tv_info->aModeTimings[index].usPixelClock) * 10; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1774 | |
| 1775 | if (index == 1) { |
| 1776 | /* PAL timings appear to have wrong values for totals */ |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1777 | mode->crtc_htotal -= 1; |
| 1778 | mode->crtc_vtotal -= 1; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1779 | } |
| 1780 | break; |
| 1781 | case 2: |
| 1782 | tv_info_v1_2 = (ATOM_ANALOG_TV_INFO_V1_2 *)(mode_info->atom_context->bios + data_offset); |
Dan Carpenter | 0031c41 | 2010-04-27 14:11:04 -0700 | [diff] [blame] | 1783 | if (index >= MAX_SUPPORTED_TV_TIMING_V1_2) |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1784 | return false; |
| 1785 | |
| 1786 | dtd_timings = &tv_info_v1_2->aModeTimings[index]; |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1787 | mode->crtc_htotal = le16_to_cpu(dtd_timings->usHActive) + |
| 1788 | le16_to_cpu(dtd_timings->usHBlanking_Time); |
| 1789 | mode->crtc_hdisplay = le16_to_cpu(dtd_timings->usHActive); |
| 1790 | mode->crtc_hsync_start = le16_to_cpu(dtd_timings->usHActive) + |
| 1791 | le16_to_cpu(dtd_timings->usHSyncOffset); |
| 1792 | mode->crtc_hsync_end = mode->crtc_hsync_start + |
| 1793 | le16_to_cpu(dtd_timings->usHSyncWidth); |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1794 | |
Alex Deucher | 5a9bcac | 2009-10-08 15:09:31 -0400 | [diff] [blame] | 1795 | mode->crtc_vtotal = le16_to_cpu(dtd_timings->usVActive) + |
| 1796 | le16_to_cpu(dtd_timings->usVBlanking_Time); |
| 1797 | mode->crtc_vdisplay = le16_to_cpu(dtd_timings->usVActive); |
| 1798 | mode->crtc_vsync_start = le16_to_cpu(dtd_timings->usVActive) + |
| 1799 | le16_to_cpu(dtd_timings->usVSyncOffset); |
| 1800 | mode->crtc_vsync_end = mode->crtc_vsync_start + |
| 1801 | le16_to_cpu(dtd_timings->usVSyncWidth); |
| 1802 | |
| 1803 | mode->flags = 0; |
| 1804 | misc = le16_to_cpu(dtd_timings->susModeMiscInfo.usAccess); |
| 1805 | if (misc & ATOM_VSYNC_POLARITY) |
| 1806 | mode->flags |= DRM_MODE_FLAG_NVSYNC; |
| 1807 | if (misc & ATOM_HSYNC_POLARITY) |
| 1808 | mode->flags |= DRM_MODE_FLAG_NHSYNC; |
| 1809 | if (misc & ATOM_COMPOSITESYNC) |
| 1810 | mode->flags |= DRM_MODE_FLAG_CSYNC; |
| 1811 | if (misc & ATOM_INTERLACE) |
| 1812 | mode->flags |= DRM_MODE_FLAG_INTERLACE; |
| 1813 | if (misc & ATOM_DOUBLE_CLOCK_MODE) |
| 1814 | mode->flags |= DRM_MODE_FLAG_DBLSCAN; |
| 1815 | |
| 1816 | mode->clock = le16_to_cpu(dtd_timings->usPixClk) * 10; |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 1817 | break; |
| 1818 | } |
| 1819 | return true; |
| 1820 | } |
| 1821 | |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1822 | enum radeon_tv_std |
| 1823 | radeon_atombios_get_tv_info(struct radeon_device *rdev) |
| 1824 | { |
| 1825 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1826 | int index = GetIndexIntoMasterTable(DATA, AnalogTV_Info); |
| 1827 | uint16_t data_offset; |
| 1828 | uint8_t frev, crev; |
| 1829 | struct _ATOM_ANALOG_TV_INFO *tv_info; |
| 1830 | enum radeon_tv_std tv_std = TV_STD_NTSC; |
| 1831 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1832 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 1833 | &frev, &crev, &data_offset)) { |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1834 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1835 | tv_info = (struct _ATOM_ANALOG_TV_INFO *) |
| 1836 | (mode_info->atom_context->bios + data_offset); |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1837 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1838 | switch (tv_info->ucTV_BootUpDefaultStandard) { |
| 1839 | case ATOM_TV_NTSC: |
| 1840 | tv_std = TV_STD_NTSC; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1841 | DRM_DEBUG_KMS("Default TV standard: NTSC\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1842 | break; |
| 1843 | case ATOM_TV_NTSCJ: |
| 1844 | tv_std = TV_STD_NTSC_J; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1845 | DRM_DEBUG_KMS("Default TV standard: NTSC-J\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1846 | break; |
| 1847 | case ATOM_TV_PAL: |
| 1848 | tv_std = TV_STD_PAL; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1849 | DRM_DEBUG_KMS("Default TV standard: PAL\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1850 | break; |
| 1851 | case ATOM_TV_PALM: |
| 1852 | tv_std = TV_STD_PAL_M; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1853 | DRM_DEBUG_KMS("Default TV standard: PAL-M\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1854 | break; |
| 1855 | case ATOM_TV_PALN: |
| 1856 | tv_std = TV_STD_PAL_N; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1857 | DRM_DEBUG_KMS("Default TV standard: PAL-N\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1858 | break; |
| 1859 | case ATOM_TV_PALCN: |
| 1860 | tv_std = TV_STD_PAL_CN; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1861 | DRM_DEBUG_KMS("Default TV standard: PAL-CN\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1862 | break; |
| 1863 | case ATOM_TV_PAL60: |
| 1864 | tv_std = TV_STD_PAL_60; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1865 | DRM_DEBUG_KMS("Default TV standard: PAL-60\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1866 | break; |
| 1867 | case ATOM_TV_SECAM: |
| 1868 | tv_std = TV_STD_SECAM; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1869 | DRM_DEBUG_KMS("Default TV standard: SECAM\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1870 | break; |
| 1871 | default: |
| 1872 | tv_std = TV_STD_NTSC; |
Alex Deucher | 40f76d8 | 2010-10-07 22:38:42 -0400 | [diff] [blame] | 1873 | DRM_DEBUG_KMS("Unknown TV standard; defaulting to NTSC\n"); |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1874 | break; |
| 1875 | } |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1876 | } |
| 1877 | return tv_std; |
| 1878 | } |
| 1879 | |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1880 | struct radeon_encoder_tv_dac * |
| 1881 | radeon_atombios_get_tv_dac_info(struct radeon_encoder *encoder) |
| 1882 | { |
| 1883 | struct drm_device *dev = encoder->base.dev; |
| 1884 | struct radeon_device *rdev = dev->dev_private; |
| 1885 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 1886 | int index = GetIndexIntoMasterTable(DATA, CompassionateData); |
| 1887 | uint16_t data_offset; |
| 1888 | struct _COMPASSIONATE_DATA *dac_info; |
| 1889 | uint8_t frev, crev; |
| 1890 | uint8_t bg, dac; |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1891 | struct radeon_encoder_tv_dac *tv_dac = NULL; |
| 1892 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1893 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 1894 | &frev, &crev, &data_offset)) { |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1895 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 1896 | dac_info = (struct _COMPASSIONATE_DATA *) |
| 1897 | (mode_info->atom_context->bios + data_offset); |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1898 | |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1899 | tv_dac = kzalloc(sizeof(struct radeon_encoder_tv_dac), GFP_KERNEL); |
| 1900 | |
| 1901 | if (!tv_dac) |
| 1902 | return NULL; |
| 1903 | |
| 1904 | bg = dac_info->ucDAC2_CRT2_BG_Adjustment; |
| 1905 | dac = dac_info->ucDAC2_CRT2_DAC_Adjustment; |
| 1906 | tv_dac->ps2_tvdac_adj = (bg << 16) | (dac << 20); |
| 1907 | |
| 1908 | bg = dac_info->ucDAC2_PAL_BG_Adjustment; |
| 1909 | dac = dac_info->ucDAC2_PAL_DAC_Adjustment; |
| 1910 | tv_dac->pal_tvdac_adj = (bg << 16) | (dac << 20); |
| 1911 | |
| 1912 | bg = dac_info->ucDAC2_NTSC_BG_Adjustment; |
| 1913 | dac = dac_info->ucDAC2_NTSC_DAC_Adjustment; |
| 1914 | tv_dac->ntsc_tvdac_adj = (bg << 16) | (dac << 20); |
| 1915 | |
Alex Deucher | d79766f | 2009-12-17 19:00:29 -0500 | [diff] [blame] | 1916 | tv_dac->tv_std = radeon_atombios_get_tv_info(rdev); |
Alex Deucher | 6fe7ac3 | 2009-06-12 17:26:08 +0000 | [diff] [blame] | 1917 | } |
| 1918 | return tv_dac; |
| 1919 | } |
| 1920 | |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1921 | static const char *thermal_controller_names[] = { |
| 1922 | "NONE", |
Alex Deucher | 678e7dfa | 2010-04-22 14:17:56 -0400 | [diff] [blame] | 1923 | "lm63", |
| 1924 | "adm1032", |
| 1925 | "adm1030", |
| 1926 | "max6649", |
| 1927 | "lm64", |
| 1928 | "f75375", |
| 1929 | "asc7xxx", |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1930 | }; |
| 1931 | |
| 1932 | static const char *pp_lib_thermal_controller_names[] = { |
| 1933 | "NONE", |
Alex Deucher | 678e7dfa | 2010-04-22 14:17:56 -0400 | [diff] [blame] | 1934 | "lm63", |
| 1935 | "adm1032", |
| 1936 | "adm1030", |
| 1937 | "max6649", |
| 1938 | "lm64", |
| 1939 | "f75375", |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1940 | "RV6xx", |
| 1941 | "RV770", |
Alex Deucher | 678e7dfa | 2010-04-22 14:17:56 -0400 | [diff] [blame] | 1942 | "adt7473", |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 1943 | "NONE", |
Alex Deucher | 49f6598 | 2010-03-24 16:39:45 -0400 | [diff] [blame] | 1944 | "External GPIO", |
| 1945 | "Evergreen", |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 1946 | "emc2103", |
| 1947 | "Sumo", |
Alex Deucher | 4fddba1 | 2011-01-06 21:19:22 -0500 | [diff] [blame] | 1948 | "Northern Islands", |
Alex Deucher | 14607d0 | 2012-03-20 17:18:09 -0400 | [diff] [blame] | 1949 | "Southern Islands", |
| 1950 | "lm96163", |
Alex Deucher | 5115020 | 2012-12-18 22:07:14 -0500 | [diff] [blame] | 1951 | "Sea Islands", |
Alex Deucher | 29fb52c | 2010-03-11 10:01:17 -0500 | [diff] [blame] | 1952 | }; |
| 1953 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1954 | union power_info { |
| 1955 | struct _ATOM_POWERPLAY_INFO info; |
| 1956 | struct _ATOM_POWERPLAY_INFO_V2 info_2; |
| 1957 | struct _ATOM_POWERPLAY_INFO_V3 info_3; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 1958 | struct _ATOM_PPLIB_POWERPLAYTABLE pplib; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 1959 | struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2; |
| 1960 | struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3; |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 1961 | }; |
| 1962 | |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 1963 | union pplib_clock_info { |
| 1964 | struct _ATOM_PPLIB_R600_CLOCK_INFO r600; |
| 1965 | struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780; |
| 1966 | struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 1967 | struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo; |
Alex Deucher | 14607d0 | 2012-03-20 17:18:09 -0400 | [diff] [blame] | 1968 | struct _ATOM_PPLIB_SI_CLOCK_INFO si; |
Alex Deucher | bc19f59 | 2013-06-07 11:41:05 -0400 | [diff] [blame] | 1969 | struct _ATOM_PPLIB_CI_CLOCK_INFO ci; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 1970 | }; |
| 1971 | |
| 1972 | union pplib_power_state { |
| 1973 | struct _ATOM_PPLIB_STATE v1; |
| 1974 | struct _ATOM_PPLIB_STATE_V2 v2; |
| 1975 | }; |
| 1976 | |
| 1977 | static void radeon_atombios_parse_misc_flags_1_3(struct radeon_device *rdev, |
| 1978 | int state_index, |
| 1979 | u32 misc, u32 misc2) |
| 1980 | { |
| 1981 | rdev->pm.power_state[state_index].misc = misc; |
| 1982 | rdev->pm.power_state[state_index].misc2 = misc2; |
| 1983 | /* order matters! */ |
| 1984 | if (misc & ATOM_PM_MISCINFO_POWER_SAVING_MODE) |
| 1985 | rdev->pm.power_state[state_index].type = |
| 1986 | POWER_STATE_TYPE_POWERSAVE; |
| 1987 | if (misc & ATOM_PM_MISCINFO_DEFAULT_DC_STATE_ENTRY_TRUE) |
| 1988 | rdev->pm.power_state[state_index].type = |
| 1989 | POWER_STATE_TYPE_BATTERY; |
| 1990 | if (misc & ATOM_PM_MISCINFO_DEFAULT_LOW_DC_STATE_ENTRY_TRUE) |
| 1991 | rdev->pm.power_state[state_index].type = |
| 1992 | POWER_STATE_TYPE_BATTERY; |
| 1993 | if (misc & ATOM_PM_MISCINFO_LOAD_BALANCE_EN) |
| 1994 | rdev->pm.power_state[state_index].type = |
| 1995 | POWER_STATE_TYPE_BALANCED; |
| 1996 | if (misc & ATOM_PM_MISCINFO_3D_ACCELERATION_EN) { |
| 1997 | rdev->pm.power_state[state_index].type = |
| 1998 | POWER_STATE_TYPE_PERFORMANCE; |
| 1999 | rdev->pm.power_state[state_index].flags &= |
| 2000 | ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY; |
| 2001 | } |
| 2002 | if (misc2 & ATOM_PM_MISCINFO2_SYSTEM_AC_LITE_MODE) |
| 2003 | rdev->pm.power_state[state_index].type = |
| 2004 | POWER_STATE_TYPE_BALANCED; |
| 2005 | if (misc & ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE) { |
| 2006 | rdev->pm.power_state[state_index].type = |
| 2007 | POWER_STATE_TYPE_DEFAULT; |
| 2008 | rdev->pm.default_power_state_index = state_index; |
| 2009 | rdev->pm.power_state[state_index].default_clock_mode = |
| 2010 | &rdev->pm.power_state[state_index].clock_info[0]; |
| 2011 | } else if (state_index == 0) { |
| 2012 | rdev->pm.power_state[state_index].clock_info[0].flags |= |
| 2013 | RADEON_PM_MODE_NO_DISPLAY; |
| 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | static int radeon_atombios_parse_power_table_1_3(struct radeon_device *rdev) |
| 2018 | { |
| 2019 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 2020 | u32 misc, misc2 = 0; |
| 2021 | int num_modes = 0, i; |
| 2022 | int state_index = 0; |
| 2023 | struct radeon_i2c_bus_rec i2c_bus; |
| 2024 | union power_info *power_info; |
| 2025 | int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); |
| 2026 | u16 data_offset; |
| 2027 | u8 frev, crev; |
| 2028 | |
| 2029 | if (!atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 2030 | &frev, &crev, &data_offset)) |
| 2031 | return state_index; |
| 2032 | power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); |
| 2033 | |
| 2034 | /* add the i2c bus for thermal/fan chip */ |
Alex Deucher | 4755fab | 2012-08-30 13:30:49 -0400 | [diff] [blame] | 2035 | if ((power_info->info.ucOverdriveThermalController > 0) && |
| 2036 | (power_info->info.ucOverdriveThermalController < ARRAY_SIZE(thermal_controller_names))) { |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2037 | DRM_INFO("Possible %s thermal controller at 0x%02x\n", |
| 2038 | thermal_controller_names[power_info->info.ucOverdriveThermalController], |
| 2039 | power_info->info.ucOverdriveControllerAddress >> 1); |
| 2040 | i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine); |
| 2041 | rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus); |
| 2042 | if (rdev->pm.i2c_bus) { |
| 2043 | struct i2c_board_info info = { }; |
| 2044 | const char *name = thermal_controller_names[power_info->info. |
| 2045 | ucOverdriveThermalController]; |
| 2046 | info.addr = power_info->info.ucOverdriveControllerAddress >> 1; |
| 2047 | strlcpy(info.type, name, sizeof(info.type)); |
| 2048 | i2c_new_device(&rdev->pm.i2c_bus->adapter, &info); |
| 2049 | } |
| 2050 | } |
| 2051 | num_modes = power_info->info.ucNumOfPowerModeEntries; |
| 2052 | if (num_modes > ATOM_MAX_NUMBEROF_POWER_BLOCK) |
| 2053 | num_modes = ATOM_MAX_NUMBEROF_POWER_BLOCK; |
Alex Deucher | f8e6bfc | 2013-04-25 09:29:17 -0400 | [diff] [blame] | 2054 | if (num_modes == 0) |
| 2055 | return state_index; |
Alex Deucher | 0975b16 | 2011-02-02 18:42:03 -0500 | [diff] [blame] | 2056 | rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL); |
| 2057 | if (!rdev->pm.power_state) |
| 2058 | return state_index; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2059 | /* last mode is usually default, array is low to high */ |
| 2060 | for (i = 0; i < num_modes; i++) { |
Alex Deucher | 6991b8f | 2011-11-14 17:52:51 -0500 | [diff] [blame] | 2061 | rdev->pm.power_state[state_index].clock_info = |
| 2062 | kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL); |
| 2063 | if (!rdev->pm.power_state[state_index].clock_info) |
| 2064 | return state_index; |
| 2065 | rdev->pm.power_state[state_index].num_clock_modes = 1; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2066 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE; |
| 2067 | switch (frev) { |
| 2068 | case 1: |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2069 | rdev->pm.power_state[state_index].clock_info[0].mclk = |
| 2070 | le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock); |
| 2071 | rdev->pm.power_state[state_index].clock_info[0].sclk = |
| 2072 | le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock); |
| 2073 | /* skip invalid modes */ |
| 2074 | if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) || |
| 2075 | (rdev->pm.power_state[state_index].clock_info[0].sclk == 0)) |
| 2076 | continue; |
| 2077 | rdev->pm.power_state[state_index].pcie_lanes = |
| 2078 | power_info->info.asPowerPlayInfo[i].ucNumPciELanes; |
| 2079 | misc = le32_to_cpu(power_info->info.asPowerPlayInfo[i].ulMiscInfo); |
| 2080 | if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) || |
| 2081 | (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) { |
| 2082 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = |
| 2083 | VOLTAGE_GPIO; |
| 2084 | rdev->pm.power_state[state_index].clock_info[0].voltage.gpio = |
| 2085 | radeon_lookup_gpio(rdev, |
| 2086 | power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex); |
| 2087 | if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH) |
| 2088 | rdev->pm.power_state[state_index].clock_info[0].voltage.active_high = |
| 2089 | true; |
| 2090 | else |
| 2091 | rdev->pm.power_state[state_index].clock_info[0].voltage.active_high = |
| 2092 | false; |
| 2093 | } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) { |
| 2094 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = |
| 2095 | VOLTAGE_VDDC; |
| 2096 | rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id = |
| 2097 | power_info->info.asPowerPlayInfo[i].ucVoltageDropIndex; |
| 2098 | } |
| 2099 | rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY; |
| 2100 | radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0); |
| 2101 | state_index++; |
| 2102 | break; |
| 2103 | case 2: |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2104 | rdev->pm.power_state[state_index].clock_info[0].mclk = |
| 2105 | le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock); |
| 2106 | rdev->pm.power_state[state_index].clock_info[0].sclk = |
| 2107 | le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock); |
| 2108 | /* skip invalid modes */ |
| 2109 | if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) || |
| 2110 | (rdev->pm.power_state[state_index].clock_info[0].sclk == 0)) |
| 2111 | continue; |
| 2112 | rdev->pm.power_state[state_index].pcie_lanes = |
| 2113 | power_info->info_2.asPowerPlayInfo[i].ucNumPciELanes; |
| 2114 | misc = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo); |
| 2115 | misc2 = le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMiscInfo2); |
| 2116 | if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) || |
| 2117 | (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) { |
| 2118 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = |
| 2119 | VOLTAGE_GPIO; |
| 2120 | rdev->pm.power_state[state_index].clock_info[0].voltage.gpio = |
| 2121 | radeon_lookup_gpio(rdev, |
| 2122 | power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex); |
| 2123 | if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH) |
| 2124 | rdev->pm.power_state[state_index].clock_info[0].voltage.active_high = |
| 2125 | true; |
| 2126 | else |
| 2127 | rdev->pm.power_state[state_index].clock_info[0].voltage.active_high = |
| 2128 | false; |
| 2129 | } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) { |
| 2130 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = |
| 2131 | VOLTAGE_VDDC; |
| 2132 | rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id = |
| 2133 | power_info->info_2.asPowerPlayInfo[i].ucVoltageDropIndex; |
| 2134 | } |
| 2135 | rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY; |
| 2136 | radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2); |
| 2137 | state_index++; |
| 2138 | break; |
| 2139 | case 3: |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2140 | rdev->pm.power_state[state_index].clock_info[0].mclk = |
| 2141 | le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock); |
| 2142 | rdev->pm.power_state[state_index].clock_info[0].sclk = |
| 2143 | le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock); |
| 2144 | /* skip invalid modes */ |
| 2145 | if ((rdev->pm.power_state[state_index].clock_info[0].mclk == 0) || |
| 2146 | (rdev->pm.power_state[state_index].clock_info[0].sclk == 0)) |
| 2147 | continue; |
| 2148 | rdev->pm.power_state[state_index].pcie_lanes = |
| 2149 | power_info->info_3.asPowerPlayInfo[i].ucNumPciELanes; |
| 2150 | misc = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo); |
| 2151 | misc2 = le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMiscInfo2); |
| 2152 | if ((misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_SUPPORT) || |
| 2153 | (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH)) { |
| 2154 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = |
| 2155 | VOLTAGE_GPIO; |
| 2156 | rdev->pm.power_state[state_index].clock_info[0].voltage.gpio = |
| 2157 | radeon_lookup_gpio(rdev, |
| 2158 | power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex); |
| 2159 | if (misc & ATOM_PM_MISCINFO_VOLTAGE_DROP_ACTIVE_HIGH) |
| 2160 | rdev->pm.power_state[state_index].clock_info[0].voltage.active_high = |
| 2161 | true; |
| 2162 | else |
| 2163 | rdev->pm.power_state[state_index].clock_info[0].voltage.active_high = |
| 2164 | false; |
| 2165 | } else if (misc & ATOM_PM_MISCINFO_PROGRAM_VOLTAGE) { |
| 2166 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = |
| 2167 | VOLTAGE_VDDC; |
| 2168 | rdev->pm.power_state[state_index].clock_info[0].voltage.vddc_id = |
| 2169 | power_info->info_3.asPowerPlayInfo[i].ucVoltageDropIndex; |
| 2170 | if (misc2 & ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN) { |
| 2171 | rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_enabled = |
| 2172 | true; |
| 2173 | rdev->pm.power_state[state_index].clock_info[0].voltage.vddci_id = |
| 2174 | power_info->info_3.asPowerPlayInfo[i].ucVDDCI_VoltageDropIndex; |
| 2175 | } |
| 2176 | } |
| 2177 | rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY; |
| 2178 | radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2); |
| 2179 | state_index++; |
| 2180 | break; |
| 2181 | } |
| 2182 | } |
| 2183 | /* last mode is usually default */ |
| 2184 | if (rdev->pm.default_power_state_index == -1) { |
| 2185 | rdev->pm.power_state[state_index - 1].type = |
| 2186 | POWER_STATE_TYPE_DEFAULT; |
| 2187 | rdev->pm.default_power_state_index = state_index - 1; |
| 2188 | rdev->pm.power_state[state_index - 1].default_clock_mode = |
| 2189 | &rdev->pm.power_state[state_index - 1].clock_info[0]; |
| 2190 | rdev->pm.power_state[state_index].flags &= |
| 2191 | ~RADEON_PM_STATE_SINGLE_DISPLAY_ONLY; |
| 2192 | rdev->pm.power_state[state_index].misc = 0; |
| 2193 | rdev->pm.power_state[state_index].misc2 = 0; |
| 2194 | } |
| 2195 | return state_index; |
| 2196 | } |
| 2197 | |
| 2198 | static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *rdev, |
| 2199 | ATOM_PPLIB_THERMALCONTROLLER *controller) |
| 2200 | { |
| 2201 | struct radeon_i2c_bus_rec i2c_bus; |
| 2202 | |
| 2203 | /* add the i2c bus for thermal/fan chip */ |
| 2204 | if (controller->ucType > 0) { |
| 2205 | if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) { |
| 2206 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2207 | (controller->ucFanParameters & |
| 2208 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2209 | rdev->pm.int_thermal_type = THERMAL_TYPE_RV6XX; |
| 2210 | } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) { |
| 2211 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2212 | (controller->ucFanParameters & |
| 2213 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2214 | rdev->pm.int_thermal_type = THERMAL_TYPE_RV770; |
| 2215 | } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) { |
| 2216 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2217 | (controller->ucFanParameters & |
| 2218 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2219 | rdev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2220 | } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) { |
| 2221 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2222 | (controller->ucFanParameters & |
| 2223 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2224 | rdev->pm.int_thermal_type = THERMAL_TYPE_SUMO; |
Alex Deucher | 4fddba1 | 2011-01-06 21:19:22 -0500 | [diff] [blame] | 2225 | } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) { |
| 2226 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2227 | (controller->ucFanParameters & |
| 2228 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2229 | rdev->pm.int_thermal_type = THERMAL_TYPE_NI; |
Alex Deucher | 14607d0 | 2012-03-20 17:18:09 -0400 | [diff] [blame] | 2230 | } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) { |
| 2231 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2232 | (controller->ucFanParameters & |
| 2233 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2234 | rdev->pm.int_thermal_type = THERMAL_TYPE_SI; |
Alex Deucher | 5115020 | 2012-12-18 22:07:14 -0500 | [diff] [blame] | 2235 | } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) { |
| 2236 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2237 | (controller->ucFanParameters & |
| 2238 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2239 | rdev->pm.int_thermal_type = THERMAL_TYPE_CI; |
Alex Deucher | 16fbe00 | 2013-04-22 21:41:26 -0400 | [diff] [blame^] | 2240 | } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) { |
| 2241 | DRM_INFO("Internal thermal controller %s fan control\n", |
| 2242 | (controller->ucFanParameters & |
| 2243 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2244 | rdev->pm.int_thermal_type = THERMAL_TYPE_KV; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2245 | } else if ((controller->ucType == |
| 2246 | ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) || |
| 2247 | (controller->ucType == |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2248 | ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) || |
| 2249 | (controller->ucType == |
| 2250 | ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) { |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2251 | DRM_INFO("Special thermal controller config\n"); |
Alex Deucher | 4755fab | 2012-08-30 13:30:49 -0400 | [diff] [blame] | 2252 | } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) { |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2253 | DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n", |
| 2254 | pp_lib_thermal_controller_names[controller->ucType], |
| 2255 | controller->ucI2cAddress >> 1, |
| 2256 | (controller->ucFanParameters & |
| 2257 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
| 2258 | i2c_bus = radeon_lookup_i2c_gpio(rdev, controller->ucI2cLine); |
| 2259 | rdev->pm.i2c_bus = radeon_i2c_lookup(rdev, &i2c_bus); |
| 2260 | if (rdev->pm.i2c_bus) { |
| 2261 | struct i2c_board_info info = { }; |
| 2262 | const char *name = pp_lib_thermal_controller_names[controller->ucType]; |
| 2263 | info.addr = controller->ucI2cAddress >> 1; |
| 2264 | strlcpy(info.type, name, sizeof(info.type)); |
| 2265 | i2c_new_device(&rdev->pm.i2c_bus->adapter, &info); |
| 2266 | } |
Alex Deucher | 4755fab | 2012-08-30 13:30:49 -0400 | [diff] [blame] | 2267 | } else { |
| 2268 | DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n", |
| 2269 | controller->ucType, |
| 2270 | controller->ucI2cAddress >> 1, |
| 2271 | (controller->ucFanParameters & |
| 2272 | ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with"); |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2273 | } |
| 2274 | } |
| 2275 | } |
| 2276 | |
Alex Deucher | 4a6369e | 2013-04-12 14:04:10 -0400 | [diff] [blame] | 2277 | void radeon_atombios_get_default_voltages(struct radeon_device *rdev, |
Alex Deucher | 2abba66 | 2013-03-25 12:47:23 -0400 | [diff] [blame] | 2278 | u16 *vddc, u16 *vddci, u16 *mvdd) |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2279 | { |
| 2280 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 2281 | int index = GetIndexIntoMasterTable(DATA, FirmwareInfo); |
| 2282 | u8 frev, crev; |
| 2283 | u16 data_offset; |
| 2284 | union firmware_info *firmware_info; |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 2285 | |
| 2286 | *vddc = 0; |
| 2287 | *vddci = 0; |
Alex Deucher | 2abba66 | 2013-03-25 12:47:23 -0400 | [diff] [blame] | 2288 | *mvdd = 0; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2289 | |
| 2290 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 2291 | &frev, &crev, &data_offset)) { |
| 2292 | firmware_info = |
| 2293 | (union firmware_info *)(mode_info->atom_context->bios + |
| 2294 | data_offset); |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 2295 | *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage); |
Alex Deucher | 2abba66 | 2013-03-25 12:47:23 -0400 | [diff] [blame] | 2296 | if ((frev == 2) && (crev >= 2)) { |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 2297 | *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage); |
Alex Deucher | 2abba66 | 2013-03-25 12:47:23 -0400 | [diff] [blame] | 2298 | *mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage); |
| 2299 | } |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2300 | } |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev, |
| 2304 | int state_index, int mode_index, |
| 2305 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info) |
| 2306 | { |
| 2307 | int j; |
| 2308 | u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings); |
| 2309 | u32 misc2 = le16_to_cpu(non_clock_info->usClassification); |
Alex Deucher | 2abba66 | 2013-03-25 12:47:23 -0400 | [diff] [blame] | 2310 | u16 vddc, vddci, mvdd; |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 2311 | |
Alex Deucher | 2abba66 | 2013-03-25 12:47:23 -0400 | [diff] [blame] | 2312 | radeon_atombios_get_default_voltages(rdev, &vddc, &vddci, &mvdd); |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2313 | |
| 2314 | rdev->pm.power_state[state_index].misc = misc; |
| 2315 | rdev->pm.power_state[state_index].misc2 = misc2; |
| 2316 | rdev->pm.power_state[state_index].pcie_lanes = |
| 2317 | ((misc & ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >> |
| 2318 | ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1; |
| 2319 | switch (misc2 & ATOM_PPLIB_CLASSIFICATION_UI_MASK) { |
| 2320 | case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY: |
| 2321 | rdev->pm.power_state[state_index].type = |
| 2322 | POWER_STATE_TYPE_BATTERY; |
| 2323 | break; |
| 2324 | case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED: |
| 2325 | rdev->pm.power_state[state_index].type = |
| 2326 | POWER_STATE_TYPE_BALANCED; |
| 2327 | break; |
| 2328 | case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE: |
| 2329 | rdev->pm.power_state[state_index].type = |
| 2330 | POWER_STATE_TYPE_PERFORMANCE; |
| 2331 | break; |
| 2332 | case ATOM_PPLIB_CLASSIFICATION_UI_NONE: |
| 2333 | if (misc2 & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE) |
| 2334 | rdev->pm.power_state[state_index].type = |
| 2335 | POWER_STATE_TYPE_PERFORMANCE; |
| 2336 | break; |
| 2337 | } |
| 2338 | rdev->pm.power_state[state_index].flags = 0; |
| 2339 | if (misc & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) |
| 2340 | rdev->pm.power_state[state_index].flags |= |
| 2341 | RADEON_PM_STATE_SINGLE_DISPLAY_ONLY; |
| 2342 | if (misc2 & ATOM_PPLIB_CLASSIFICATION_BOOT) { |
| 2343 | rdev->pm.power_state[state_index].type = |
| 2344 | POWER_STATE_TYPE_DEFAULT; |
| 2345 | rdev->pm.default_power_state_index = state_index; |
| 2346 | rdev->pm.power_state[state_index].default_clock_mode = |
| 2347 | &rdev->pm.power_state[state_index].clock_info[mode_index - 1]; |
Alex Deucher | 982cb32 | 2013-04-29 10:51:26 -0400 | [diff] [blame] | 2348 | if ((rdev->family >= CHIP_BARTS) && !(rdev->flags & RADEON_IS_IGP)) { |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 2349 | /* NI chips post without MC ucode, so default clocks are strobe mode only */ |
| 2350 | rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk; |
| 2351 | rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk; |
| 2352 | rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage; |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 2353 | rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 2354 | } else { |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 2355 | u16 max_vddci = 0; |
| 2356 | |
| 2357 | if (ASIC_IS_DCE4(rdev)) |
| 2358 | radeon_atom_get_max_voltage(rdev, |
| 2359 | SET_VOLTAGE_TYPE_ASIC_VDDCI, |
| 2360 | &max_vddci); |
| 2361 | /* patch the table values with the default sclk/mclk from firmware info */ |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 2362 | for (j = 0; j < mode_index; j++) { |
| 2363 | rdev->pm.power_state[state_index].clock_info[j].mclk = |
| 2364 | rdev->clock.default_mclk; |
| 2365 | rdev->pm.power_state[state_index].clock_info[j].sclk = |
| 2366 | rdev->clock.default_sclk; |
| 2367 | if (vddc) |
| 2368 | rdev->pm.power_state[state_index].clock_info[j].voltage.voltage = |
| 2369 | vddc; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 2370 | if (max_vddci) |
| 2371 | rdev->pm.power_state[state_index].clock_info[j].voltage.vddci = |
| 2372 | max_vddci; |
Alex Deucher | 9ace9f7 | 2011-01-06 21:19:26 -0500 | [diff] [blame] | 2373 | } |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2374 | } |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev, |
| 2379 | int state_index, int mode_index, |
| 2380 | union pplib_clock_info *clock_info) |
| 2381 | { |
| 2382 | u32 sclk, mclk; |
Alex Deucher | e83753b | 2012-03-20 17:18:08 -0400 | [diff] [blame] | 2383 | u16 vddc; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2384 | |
| 2385 | if (rdev->flags & RADEON_IS_IGP) { |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2386 | if (rdev->family >= CHIP_PALM) { |
| 2387 | sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow); |
| 2388 | sclk |= clock_info->sumo.ucEngineClockHigh << 16; |
| 2389 | rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk; |
| 2390 | } else { |
| 2391 | sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow); |
| 2392 | sclk |= clock_info->rs780.ucLowEngineClockHigh << 16; |
| 2393 | rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk; |
| 2394 | } |
Alex Deucher | bc19f59 | 2013-06-07 11:41:05 -0400 | [diff] [blame] | 2395 | } else if (rdev->family >= CHIP_BONAIRE) { |
| 2396 | sclk = le16_to_cpu(clock_info->ci.usEngineClockLow); |
| 2397 | sclk |= clock_info->ci.ucEngineClockHigh << 16; |
| 2398 | mclk = le16_to_cpu(clock_info->ci.usMemoryClockLow); |
| 2399 | mclk |= clock_info->ci.ucMemoryClockHigh << 16; |
| 2400 | rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk; |
| 2401 | rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk; |
| 2402 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type = |
| 2403 | VOLTAGE_NONE; |
Alex Deucher | 982cb32 | 2013-04-29 10:51:26 -0400 | [diff] [blame] | 2404 | } else if (rdev->family >= CHIP_TAHITI) { |
Alex Deucher | 14607d0 | 2012-03-20 17:18:09 -0400 | [diff] [blame] | 2405 | sclk = le16_to_cpu(clock_info->si.usEngineClockLow); |
| 2406 | sclk |= clock_info->si.ucEngineClockHigh << 16; |
| 2407 | mclk = le16_to_cpu(clock_info->si.usMemoryClockLow); |
| 2408 | mclk |= clock_info->si.ucMemoryClockHigh << 16; |
| 2409 | rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk; |
| 2410 | rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk; |
| 2411 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type = |
| 2412 | VOLTAGE_SW; |
| 2413 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = |
| 2414 | le16_to_cpu(clock_info->si.usVDDC); |
| 2415 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci = |
| 2416 | le16_to_cpu(clock_info->si.usVDDCI); |
Alex Deucher | 982cb32 | 2013-04-29 10:51:26 -0400 | [diff] [blame] | 2417 | } else if (rdev->family >= CHIP_CEDAR) { |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2418 | sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow); |
| 2419 | sclk |= clock_info->evergreen.ucEngineClockHigh << 16; |
| 2420 | mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow); |
| 2421 | mclk |= clock_info->evergreen.ucMemoryClockHigh << 16; |
| 2422 | rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk; |
| 2423 | rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk; |
| 2424 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type = |
| 2425 | VOLTAGE_SW; |
| 2426 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2427 | le16_to_cpu(clock_info->evergreen.usVDDC); |
Alex Deucher | 2feea49 | 2011-04-12 14:49:24 -0400 | [diff] [blame] | 2428 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci = |
| 2429 | le16_to_cpu(clock_info->evergreen.usVDDCI); |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2430 | } else { |
| 2431 | sclk = le16_to_cpu(clock_info->r600.usEngineClockLow); |
| 2432 | sclk |= clock_info->r600.ucEngineClockHigh << 16; |
| 2433 | mclk = le16_to_cpu(clock_info->r600.usMemoryClockLow); |
| 2434 | mclk |= clock_info->r600.ucMemoryClockHigh << 16; |
| 2435 | rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk; |
| 2436 | rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk; |
| 2437 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type = |
| 2438 | VOLTAGE_SW; |
| 2439 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2440 | le16_to_cpu(clock_info->r600.usVDDC); |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2441 | } |
| 2442 | |
Alex Deucher | ee4017f | 2011-06-23 12:19:32 -0400 | [diff] [blame] | 2443 | /* patch up vddc if necessary */ |
Alex Deucher | e83753b | 2012-03-20 17:18:08 -0400 | [diff] [blame] | 2444 | switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) { |
| 2445 | case ATOM_VIRTUAL_VOLTAGE_ID0: |
| 2446 | case ATOM_VIRTUAL_VOLTAGE_ID1: |
| 2447 | case ATOM_VIRTUAL_VOLTAGE_ID2: |
| 2448 | case ATOM_VIRTUAL_VOLTAGE_ID3: |
Alex Deucher | c6cf777 | 2013-07-05 13:14:30 -0400 | [diff] [blame] | 2449 | case ATOM_VIRTUAL_VOLTAGE_ID4: |
| 2450 | case ATOM_VIRTUAL_VOLTAGE_ID5: |
| 2451 | case ATOM_VIRTUAL_VOLTAGE_ID6: |
| 2452 | case ATOM_VIRTUAL_VOLTAGE_ID7: |
Alex Deucher | e83753b | 2012-03-20 17:18:08 -0400 | [diff] [blame] | 2453 | if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC, |
| 2454 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage, |
| 2455 | &vddc) == 0) |
Alex Deucher | ee4017f | 2011-06-23 12:19:32 -0400 | [diff] [blame] | 2456 | rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc; |
Alex Deucher | e83753b | 2012-03-20 17:18:08 -0400 | [diff] [blame] | 2457 | break; |
| 2458 | default: |
| 2459 | break; |
Alex Deucher | ee4017f | 2011-06-23 12:19:32 -0400 | [diff] [blame] | 2460 | } |
| 2461 | |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2462 | if (rdev->flags & RADEON_IS_IGP) { |
| 2463 | /* skip invalid modes */ |
| 2464 | if (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0) |
| 2465 | return false; |
| 2466 | } else { |
| 2467 | /* skip invalid modes */ |
| 2468 | if ((rdev->pm.power_state[state_index].clock_info[mode_index].mclk == 0) || |
| 2469 | (rdev->pm.power_state[state_index].clock_info[mode_index].sclk == 0)) |
| 2470 | return false; |
| 2471 | } |
| 2472 | return true; |
| 2473 | } |
| 2474 | |
| 2475 | static int radeon_atombios_parse_power_table_4_5(struct radeon_device *rdev) |
| 2476 | { |
| 2477 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 2478 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info; |
| 2479 | union pplib_power_state *power_state; |
| 2480 | int i, j; |
| 2481 | int state_index = 0, mode_index = 0; |
| 2482 | union pplib_clock_info *clock_info; |
| 2483 | bool valid; |
| 2484 | union power_info *power_info; |
| 2485 | int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); |
| 2486 | u16 data_offset; |
| 2487 | u8 frev, crev; |
| 2488 | |
| 2489 | if (!atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 2490 | &frev, &crev, &data_offset)) |
| 2491 | return state_index; |
| 2492 | power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); |
| 2493 | |
| 2494 | radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController); |
Alex Deucher | f8e6bfc | 2013-04-25 09:29:17 -0400 | [diff] [blame] | 2495 | if (power_info->pplib.ucNumStates == 0) |
| 2496 | return state_index; |
Alex Deucher | 0975b16 | 2011-02-02 18:42:03 -0500 | [diff] [blame] | 2497 | rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * |
| 2498 | power_info->pplib.ucNumStates, GFP_KERNEL); |
| 2499 | if (!rdev->pm.power_state) |
| 2500 | return state_index; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2501 | /* first mode is usually default, followed by low to high */ |
| 2502 | for (i = 0; i < power_info->pplib.ucNumStates; i++) { |
| 2503 | mode_index = 0; |
| 2504 | power_state = (union pplib_power_state *) |
| 2505 | (mode_info->atom_context->bios + data_offset + |
| 2506 | le16_to_cpu(power_info->pplib.usStateArrayOffset) + |
| 2507 | i * power_info->pplib.ucStateEntrySize); |
| 2508 | non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) |
| 2509 | (mode_info->atom_context->bios + data_offset + |
| 2510 | le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) + |
| 2511 | (power_state->v1.ucNonClockStateIndex * |
| 2512 | power_info->pplib.ucNonClockSize)); |
Alex Deucher | 8f3f1c9 | 2011-11-04 10:09:43 -0400 | [diff] [blame] | 2513 | rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) * |
| 2514 | ((power_info->pplib.ucStateEntrySize - 1) ? |
| 2515 | (power_info->pplib.ucStateEntrySize - 1) : 1), |
| 2516 | GFP_KERNEL); |
| 2517 | if (!rdev->pm.power_state[i].clock_info) |
| 2518 | return state_index; |
| 2519 | if (power_info->pplib.ucStateEntrySize - 1) { |
| 2520 | for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) { |
| 2521 | clock_info = (union pplib_clock_info *) |
| 2522 | (mode_info->atom_context->bios + data_offset + |
| 2523 | le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) + |
| 2524 | (power_state->v1.ucClockStateIndices[j] * |
| 2525 | power_info->pplib.ucClockInfoSize)); |
| 2526 | valid = radeon_atombios_parse_pplib_clock_info(rdev, |
| 2527 | state_index, mode_index, |
| 2528 | clock_info); |
| 2529 | if (valid) |
| 2530 | mode_index++; |
| 2531 | } |
| 2532 | } else { |
| 2533 | rdev->pm.power_state[state_index].clock_info[0].mclk = |
| 2534 | rdev->clock.default_mclk; |
| 2535 | rdev->pm.power_state[state_index].clock_info[0].sclk = |
| 2536 | rdev->clock.default_sclk; |
| 2537 | mode_index++; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2538 | } |
| 2539 | rdev->pm.power_state[state_index].num_clock_modes = mode_index; |
| 2540 | if (mode_index) { |
| 2541 | radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index, |
| 2542 | non_clock_info); |
| 2543 | state_index++; |
| 2544 | } |
| 2545 | } |
| 2546 | /* if multiple clock modes, mark the lowest as no display */ |
| 2547 | for (i = 0; i < state_index; i++) { |
| 2548 | if (rdev->pm.power_state[i].num_clock_modes > 1) |
| 2549 | rdev->pm.power_state[i].clock_info[0].flags |= |
| 2550 | RADEON_PM_MODE_NO_DISPLAY; |
| 2551 | } |
| 2552 | /* first mode is usually default */ |
| 2553 | if (rdev->pm.default_power_state_index == -1) { |
| 2554 | rdev->pm.power_state[0].type = |
| 2555 | POWER_STATE_TYPE_DEFAULT; |
| 2556 | rdev->pm.default_power_state_index = 0; |
| 2557 | rdev->pm.power_state[0].default_clock_mode = |
| 2558 | &rdev->pm.power_state[0].clock_info[0]; |
| 2559 | } |
| 2560 | return state_index; |
| 2561 | } |
| 2562 | |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2563 | static int radeon_atombios_parse_power_table_6(struct radeon_device *rdev) |
| 2564 | { |
| 2565 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 2566 | struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info; |
| 2567 | union pplib_power_state *power_state; |
| 2568 | int i, j, non_clock_array_index, clock_array_index; |
| 2569 | int state_index = 0, mode_index = 0; |
| 2570 | union pplib_clock_info *clock_info; |
Alex Deucher | f734688 | 2012-03-20 17:17:58 -0400 | [diff] [blame] | 2571 | struct _StateArray *state_array; |
| 2572 | struct _ClockInfoArray *clock_info_array; |
| 2573 | struct _NonClockInfoArray *non_clock_info_array; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2574 | bool valid; |
| 2575 | union power_info *power_info; |
| 2576 | int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); |
| 2577 | u16 data_offset; |
| 2578 | u8 frev, crev; |
Alex Deucher | 441e76c | 2013-05-01 14:34:54 -0400 | [diff] [blame] | 2579 | u8 *power_state_offset; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2580 | |
| 2581 | if (!atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 2582 | &frev, &crev, &data_offset)) |
| 2583 | return state_index; |
| 2584 | power_info = (union power_info *)(mode_info->atom_context->bios + data_offset); |
| 2585 | |
| 2586 | radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController); |
Alex Deucher | f734688 | 2012-03-20 17:17:58 -0400 | [diff] [blame] | 2587 | state_array = (struct _StateArray *) |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2588 | (mode_info->atom_context->bios + data_offset + |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2589 | le16_to_cpu(power_info->pplib.usStateArrayOffset)); |
Alex Deucher | f734688 | 2012-03-20 17:17:58 -0400 | [diff] [blame] | 2590 | clock_info_array = (struct _ClockInfoArray *) |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2591 | (mode_info->atom_context->bios + data_offset + |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2592 | le16_to_cpu(power_info->pplib.usClockInfoArrayOffset)); |
Alex Deucher | f734688 | 2012-03-20 17:17:58 -0400 | [diff] [blame] | 2593 | non_clock_info_array = (struct _NonClockInfoArray *) |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2594 | (mode_info->atom_context->bios + data_offset + |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2595 | le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset)); |
Alex Deucher | f8e6bfc | 2013-04-25 09:29:17 -0400 | [diff] [blame] | 2596 | if (state_array->ucNumEntries == 0) |
| 2597 | return state_index; |
Alex Deucher | 0975b16 | 2011-02-02 18:42:03 -0500 | [diff] [blame] | 2598 | rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * |
| 2599 | state_array->ucNumEntries, GFP_KERNEL); |
| 2600 | if (!rdev->pm.power_state) |
| 2601 | return state_index; |
Alex Deucher | 441e76c | 2013-05-01 14:34:54 -0400 | [diff] [blame] | 2602 | power_state_offset = (u8 *)state_array->states; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2603 | for (i = 0; i < state_array->ucNumEntries; i++) { |
| 2604 | mode_index = 0; |
Alex Deucher | 441e76c | 2013-05-01 14:34:54 -0400 | [diff] [blame] | 2605 | power_state = (union pplib_power_state *)power_state_offset; |
| 2606 | non_clock_array_index = power_state->v2.nonClockInfoIndex; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2607 | non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *) |
| 2608 | &non_clock_info_array->nonClockInfo[non_clock_array_index]; |
Alex Deucher | 8f3f1c9 | 2011-11-04 10:09:43 -0400 | [diff] [blame] | 2609 | rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) * |
| 2610 | (power_state->v2.ucNumDPMLevels ? |
| 2611 | power_state->v2.ucNumDPMLevels : 1), |
| 2612 | GFP_KERNEL); |
| 2613 | if (!rdev->pm.power_state[i].clock_info) |
| 2614 | return state_index; |
| 2615 | if (power_state->v2.ucNumDPMLevels) { |
| 2616 | for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) { |
| 2617 | clock_array_index = power_state->v2.clockInfoIndex[j]; |
Alex Deucher | 8f3f1c9 | 2011-11-04 10:09:43 -0400 | [diff] [blame] | 2618 | clock_info = (union pplib_clock_info *) |
Alex Deucher | f734688 | 2012-03-20 17:17:58 -0400 | [diff] [blame] | 2619 | &clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize]; |
Alex Deucher | 8f3f1c9 | 2011-11-04 10:09:43 -0400 | [diff] [blame] | 2620 | valid = radeon_atombios_parse_pplib_clock_info(rdev, |
| 2621 | state_index, mode_index, |
| 2622 | clock_info); |
| 2623 | if (valid) |
| 2624 | mode_index++; |
| 2625 | } |
| 2626 | } else { |
| 2627 | rdev->pm.power_state[state_index].clock_info[0].mclk = |
| 2628 | rdev->clock.default_mclk; |
| 2629 | rdev->pm.power_state[state_index].clock_info[0].sclk = |
| 2630 | rdev->clock.default_sclk; |
| 2631 | mode_index++; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2632 | } |
| 2633 | rdev->pm.power_state[state_index].num_clock_modes = mode_index; |
| 2634 | if (mode_index) { |
| 2635 | radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index, |
| 2636 | non_clock_info); |
| 2637 | state_index++; |
| 2638 | } |
Alex Deucher | 441e76c | 2013-05-01 14:34:54 -0400 | [diff] [blame] | 2639 | power_state_offset += 2 + power_state->v2.ucNumDPMLevels; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2640 | } |
| 2641 | /* if multiple clock modes, mark the lowest as no display */ |
| 2642 | for (i = 0; i < state_index; i++) { |
| 2643 | if (rdev->pm.power_state[i].num_clock_modes > 1) |
| 2644 | rdev->pm.power_state[i].clock_info[0].flags |= |
| 2645 | RADEON_PM_MODE_NO_DISPLAY; |
| 2646 | } |
| 2647 | /* first mode is usually default */ |
| 2648 | if (rdev->pm.default_power_state_index == -1) { |
| 2649 | rdev->pm.power_state[0].type = |
| 2650 | POWER_STATE_TYPE_DEFAULT; |
| 2651 | rdev->pm.default_power_state_index = 0; |
| 2652 | rdev->pm.power_state[0].default_clock_mode = |
| 2653 | &rdev->pm.power_state[0].clock_info[0]; |
| 2654 | } |
| 2655 | return state_index; |
| 2656 | } |
| 2657 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 2658 | void radeon_atombios_get_power_modes(struct radeon_device *rdev) |
| 2659 | { |
| 2660 | struct radeon_mode_info *mode_info = &rdev->mode_info; |
| 2661 | int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo); |
| 2662 | u16 data_offset; |
| 2663 | u8 frev, crev; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2664 | int state_index = 0; |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 2665 | |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 2666 | rdev->pm.default_power_state_index = -1; |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 2667 | |
Alex Deucher | a084e6e | 2010-03-18 01:04:01 -0400 | [diff] [blame] | 2668 | if (atom_parse_data_header(mode_info->atom_context, index, NULL, |
| 2669 | &frev, &crev, &data_offset)) { |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2670 | switch (frev) { |
| 2671 | case 1: |
| 2672 | case 2: |
| 2673 | case 3: |
| 2674 | state_index = radeon_atombios_parse_power_table_1_3(rdev); |
| 2675 | break; |
| 2676 | case 4: |
| 2677 | case 5: |
| 2678 | state_index = radeon_atombios_parse_power_table_4_5(rdev); |
| 2679 | break; |
Alex Deucher | b0e6641 | 2010-11-22 17:56:35 -0500 | [diff] [blame] | 2680 | case 6: |
| 2681 | state_index = radeon_atombios_parse_power_table_6(rdev); |
| 2682 | break; |
Alex Deucher | 560154e | 2010-11-22 17:56:34 -0500 | [diff] [blame] | 2683 | default: |
| 2684 | break; |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 2685 | } |
Alex Deucher | f8e6bfc | 2013-04-25 09:29:17 -0400 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | if (state_index == 0) { |
Alex Deucher | 0975b16 | 2011-02-02 18:42:03 -0500 | [diff] [blame] | 2689 | rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL); |
| 2690 | if (rdev->pm.power_state) { |
Alex Deucher | 8f3f1c9 | 2011-11-04 10:09:43 -0400 | [diff] [blame] | 2691 | rdev->pm.power_state[0].clock_info = |
| 2692 | kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL); |
| 2693 | if (rdev->pm.power_state[0].clock_info) { |
| 2694 | /* add the default mode */ |
| 2695 | rdev->pm.power_state[state_index].type = |
| 2696 | POWER_STATE_TYPE_DEFAULT; |
| 2697 | rdev->pm.power_state[state_index].num_clock_modes = 1; |
| 2698 | rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk; |
| 2699 | rdev->pm.power_state[state_index].clock_info[0].sclk = rdev->clock.default_sclk; |
| 2700 | rdev->pm.power_state[state_index].default_clock_mode = |
| 2701 | &rdev->pm.power_state[state_index].clock_info[0]; |
| 2702 | rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE; |
| 2703 | rdev->pm.power_state[state_index].pcie_lanes = 16; |
| 2704 | rdev->pm.default_power_state_index = state_index; |
| 2705 | rdev->pm.power_state[state_index].flags = 0; |
| 2706 | state_index++; |
| 2707 | } |
Alex Deucher | 0975b16 | 2011-02-02 18:42:03 -0500 | [diff] [blame] | 2708 | } |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 2709 | } |
Alex Deucher | 02b17cc | 2010-04-22 13:25:06 -0400 | [diff] [blame] | 2710 | |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 2711 | rdev->pm.num_power_states = state_index; |
Rafał Miłecki | 9038dfd | 2010-02-20 23:15:04 +0000 | [diff] [blame] | 2712 | |
Alex Deucher | a48b9b4 | 2010-04-22 14:03:55 -0400 | [diff] [blame] | 2713 | rdev->pm.current_power_state_index = rdev->pm.default_power_state_index; |
| 2714 | rdev->pm.current_clock_mode_index = 0; |
Alexander Müller | 4376eee | 2011-12-30 12:55:48 -0500 | [diff] [blame] | 2715 | if (rdev->pm.default_power_state_index >= 0) |
| 2716 | rdev->pm.current_vddc = |
| 2717 | rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage; |
| 2718 | else |
| 2719 | rdev->pm.current_vddc = 0; |
Alex Deucher | 56278a8 | 2009-12-28 13:58:44 -0500 | [diff] [blame] | 2720 | } |
| 2721 | |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2722 | union get_clock_dividers { |
| 2723 | struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1; |
| 2724 | struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2; |
| 2725 | struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3; |
| 2726 | struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4; |
| 2727 | struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5; |
Alex Deucher | 9219ed6 | 2013-02-19 14:35:34 -0500 | [diff] [blame] | 2728 | struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in; |
| 2729 | struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out; |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2730 | }; |
| 2731 | |
| 2732 | int radeon_atom_get_clock_dividers(struct radeon_device *rdev, |
| 2733 | u8 clock_type, |
| 2734 | u32 clock, |
| 2735 | bool strobe_mode, |
| 2736 | struct atom_clock_dividers *dividers) |
| 2737 | { |
| 2738 | union get_clock_dividers args; |
| 2739 | int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryEnginePLL); |
| 2740 | u8 frev, crev; |
| 2741 | |
| 2742 | memset(&args, 0, sizeof(args)); |
| 2743 | memset(dividers, 0, sizeof(struct atom_clock_dividers)); |
| 2744 | |
| 2745 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) |
| 2746 | return -EINVAL; |
| 2747 | |
| 2748 | switch (crev) { |
| 2749 | case 1: |
| 2750 | /* r4xx, r5xx */ |
| 2751 | args.v1.ucAction = clock_type; |
| 2752 | args.v1.ulClock = cpu_to_le32(clock); /* 10 khz */ |
| 2753 | |
| 2754 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2755 | |
| 2756 | dividers->post_div = args.v1.ucPostDiv; |
| 2757 | dividers->fb_div = args.v1.ucFbDiv; |
| 2758 | dividers->enable_post_div = true; |
| 2759 | break; |
| 2760 | case 2: |
| 2761 | case 3: |
Alex Deucher | 360b1f5 | 2013-06-07 11:50:12 -0400 | [diff] [blame] | 2762 | case 5: |
| 2763 | /* r6xx, r7xx, evergreen, ni, si */ |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2764 | if (rdev->family <= CHIP_RV770) { |
| 2765 | args.v2.ucAction = clock_type; |
| 2766 | args.v2.ulClock = cpu_to_le32(clock); /* 10 khz */ |
| 2767 | |
| 2768 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2769 | |
| 2770 | dividers->post_div = args.v2.ucPostDiv; |
| 2771 | dividers->fb_div = le16_to_cpu(args.v2.usFbDiv); |
| 2772 | dividers->ref_div = args.v2.ucAction; |
| 2773 | if (rdev->family == CHIP_RV770) { |
| 2774 | dividers->enable_post_div = (le32_to_cpu(args.v2.ulClock) & (1 << 24)) ? |
| 2775 | true : false; |
| 2776 | dividers->vco_mode = (le32_to_cpu(args.v2.ulClock) & (1 << 25)) ? 1 : 0; |
| 2777 | } else |
| 2778 | dividers->enable_post_div = (dividers->fb_div & 1) ? true : false; |
| 2779 | } else { |
| 2780 | if (clock_type == COMPUTE_ENGINE_PLL_PARAM) { |
Alex Deucher | f4a2596 | 2013-04-22 09:59:01 -0400 | [diff] [blame] | 2781 | args.v3.ulClockParams = cpu_to_le32((clock_type << 24) | clock); |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2782 | |
| 2783 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2784 | |
| 2785 | dividers->post_div = args.v3.ucPostDiv; |
| 2786 | dividers->enable_post_div = (args.v3.ucCntlFlag & |
| 2787 | ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false; |
| 2788 | dividers->enable_dithen = (args.v3.ucCntlFlag & |
| 2789 | ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true; |
Alex Deucher | 20fab64 | 2013-07-28 12:33:56 -0400 | [diff] [blame] | 2790 | dividers->whole_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDiv); |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2791 | dividers->frac_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDivFrac); |
| 2792 | dividers->ref_div = args.v3.ucRefDiv; |
| 2793 | dividers->vco_mode = (args.v3.ucCntlFlag & |
| 2794 | ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0; |
| 2795 | } else { |
Alex Deucher | 360b1f5 | 2013-06-07 11:50:12 -0400 | [diff] [blame] | 2796 | /* for SI we use ComputeMemoryClockParam for memory plls */ |
| 2797 | if (rdev->family >= CHIP_TAHITI) |
| 2798 | return -EINVAL; |
Alex Deucher | f4a2596 | 2013-04-22 09:59:01 -0400 | [diff] [blame] | 2799 | args.v5.ulClockParams = cpu_to_le32((clock_type << 24) | clock); |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2800 | if (strobe_mode) |
| 2801 | args.v5.ucInputFlag = ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN; |
| 2802 | |
| 2803 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2804 | |
| 2805 | dividers->post_div = args.v5.ucPostDiv; |
| 2806 | dividers->enable_post_div = (args.v5.ucCntlFlag & |
| 2807 | ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false; |
| 2808 | dividers->enable_dithen = (args.v5.ucCntlFlag & |
| 2809 | ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true; |
| 2810 | dividers->whole_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDiv); |
| 2811 | dividers->frac_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDivFrac); |
| 2812 | dividers->ref_div = args.v5.ucRefDiv; |
| 2813 | dividers->vco_mode = (args.v5.ucCntlFlag & |
| 2814 | ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0; |
| 2815 | } |
| 2816 | } |
| 2817 | break; |
| 2818 | case 4: |
| 2819 | /* fusion */ |
| 2820 | args.v4.ulClock = cpu_to_le32(clock); /* 10 khz */ |
| 2821 | |
| 2822 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2823 | |
Alex Deucher | 9219ed6 | 2013-02-19 14:35:34 -0500 | [diff] [blame] | 2824 | dividers->post_divider = dividers->post_div = args.v4.ucPostDiv; |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2825 | dividers->real_clock = le32_to_cpu(args.v4.ulClock); |
| 2826 | break; |
Alex Deucher | 9219ed6 | 2013-02-19 14:35:34 -0500 | [diff] [blame] | 2827 | case 6: |
| 2828 | /* CI */ |
| 2829 | /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */ |
| 2830 | args.v6_in.ulClock.ulComputeClockFlag = clock_type; |
| 2831 | args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock); /* 10 khz */ |
| 2832 | |
| 2833 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2834 | |
| 2835 | dividers->whole_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv); |
| 2836 | dividers->frac_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac); |
| 2837 | dividers->ref_div = args.v6_out.ucPllRefDiv; |
| 2838 | dividers->post_div = args.v6_out.ucPllPostDiv; |
| 2839 | dividers->flags = args.v6_out.ucPllCntlFlag; |
| 2840 | dividers->real_clock = le32_to_cpu(args.v6_out.ulClock.ulClock); |
| 2841 | dividers->post_divider = args.v6_out.ulClock.ucPostDiv; |
| 2842 | break; |
Christian König | 7062ab6 | 2013-04-08 12:41:31 +0200 | [diff] [blame] | 2843 | default: |
| 2844 | return -EINVAL; |
| 2845 | } |
| 2846 | return 0; |
| 2847 | } |
| 2848 | |
Alex Deucher | eaa778a | 2013-02-13 16:38:25 -0500 | [diff] [blame] | 2849 | int radeon_atom_get_memory_pll_dividers(struct radeon_device *rdev, |
| 2850 | u32 clock, |
| 2851 | bool strobe_mode, |
| 2852 | struct atom_mpll_param *mpll_param) |
| 2853 | { |
| 2854 | COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args; |
| 2855 | int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam); |
| 2856 | u8 frev, crev; |
| 2857 | |
| 2858 | memset(&args, 0, sizeof(args)); |
| 2859 | memset(mpll_param, 0, sizeof(struct atom_mpll_param)); |
| 2860 | |
| 2861 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) |
| 2862 | return -EINVAL; |
| 2863 | |
| 2864 | switch (frev) { |
| 2865 | case 2: |
| 2866 | switch (crev) { |
| 2867 | case 1: |
| 2868 | /* SI */ |
| 2869 | args.ulClock = cpu_to_le32(clock); /* 10 khz */ |
| 2870 | args.ucInputFlag = 0; |
| 2871 | if (strobe_mode) |
| 2872 | args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN; |
| 2873 | |
| 2874 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2875 | |
| 2876 | mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac); |
| 2877 | mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv); |
| 2878 | mpll_param->post_div = args.ucPostDiv; |
| 2879 | mpll_param->dll_speed = args.ucDllSpeed; |
| 2880 | mpll_param->bwcntl = args.ucBWCntl; |
| 2881 | mpll_param->vco_mode = |
| 2882 | (args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK) ? 1 : 0; |
| 2883 | mpll_param->yclk_sel = |
| 2884 | (args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0; |
| 2885 | mpll_param->qdr = |
| 2886 | (args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0; |
| 2887 | mpll_param->half_rate = |
| 2888 | (args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0; |
| 2889 | break; |
| 2890 | default: |
| 2891 | return -EINVAL; |
| 2892 | } |
| 2893 | break; |
| 2894 | default: |
| 2895 | return -EINVAL; |
| 2896 | } |
| 2897 | return 0; |
| 2898 | } |
| 2899 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2900 | void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable) |
| 2901 | { |
| 2902 | DYNAMIC_CLOCK_GATING_PS_ALLOCATION args; |
| 2903 | int index = GetIndexIntoMasterTable(COMMAND, DynamicClockGating); |
| 2904 | |
| 2905 | args.ucEnable = enable; |
| 2906 | |
| 2907 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2908 | } |
| 2909 | |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 2910 | uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev) |
| 2911 | { |
| 2912 | GET_ENGINE_CLOCK_PS_ALLOCATION args; |
| 2913 | int index = GetIndexIntoMasterTable(COMMAND, GetEngineClock); |
| 2914 | |
| 2915 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2916 | return le32_to_cpu(args.ulReturnEngineClock); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 2917 | } |
| 2918 | |
| 2919 | uint32_t radeon_atom_get_memory_clock(struct radeon_device *rdev) |
| 2920 | { |
| 2921 | GET_MEMORY_CLOCK_PS_ALLOCATION args; |
| 2922 | int index = GetIndexIntoMasterTable(COMMAND, GetMemoryClock); |
| 2923 | |
| 2924 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2925 | return le32_to_cpu(args.ulReturnMemoryClock); |
Rafał Miłecki | 7433874 | 2009-11-03 00:53:02 +0100 | [diff] [blame] | 2926 | } |
| 2927 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2928 | void radeon_atom_set_engine_clock(struct radeon_device *rdev, |
| 2929 | uint32_t eng_clock) |
| 2930 | { |
| 2931 | SET_ENGINE_CLOCK_PS_ALLOCATION args; |
| 2932 | int index = GetIndexIntoMasterTable(COMMAND, SetEngineClock); |
| 2933 | |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2934 | args.ulTargetEngineClock = cpu_to_le32(eng_clock); /* 10 khz */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2935 | |
| 2936 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2937 | } |
| 2938 | |
| 2939 | void radeon_atom_set_memory_clock(struct radeon_device *rdev, |
| 2940 | uint32_t mem_clock) |
| 2941 | { |
| 2942 | SET_MEMORY_CLOCK_PS_ALLOCATION args; |
| 2943 | int index = GetIndexIntoMasterTable(COMMAND, SetMemoryClock); |
| 2944 | |
| 2945 | if (rdev->flags & RADEON_IS_IGP) |
| 2946 | return; |
| 2947 | |
Cédric Cano | 4589433 | 2011-02-11 19:45:37 -0500 | [diff] [blame] | 2948 | args.ulTargetMemoryClock = cpu_to_le32(mem_clock); /* 10 khz */ |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 2949 | |
| 2950 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2951 | } |
| 2952 | |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 2953 | void radeon_atom_set_engine_dram_timings(struct radeon_device *rdev, |
| 2954 | u32 eng_clock, u32 mem_clock) |
| 2955 | { |
| 2956 | SET_ENGINE_CLOCK_PS_ALLOCATION args; |
| 2957 | int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings); |
| 2958 | u32 tmp; |
| 2959 | |
| 2960 | memset(&args, 0, sizeof(args)); |
| 2961 | |
| 2962 | tmp = eng_clock & SET_CLOCK_FREQ_MASK; |
| 2963 | tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24); |
| 2964 | |
| 2965 | args.ulTargetEngineClock = cpu_to_le32(tmp); |
| 2966 | if (mem_clock) |
| 2967 | args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK); |
| 2968 | |
| 2969 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2970 | } |
| 2971 | |
| 2972 | void radeon_atom_update_memory_dll(struct radeon_device *rdev, |
| 2973 | u32 mem_clock) |
| 2974 | { |
| 2975 | u32 args; |
| 2976 | int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings); |
| 2977 | |
| 2978 | args = cpu_to_le32(mem_clock); /* 10 khz */ |
| 2979 | |
| 2980 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2981 | } |
| 2982 | |
| 2983 | void radeon_atom_set_ac_timing(struct radeon_device *rdev, |
| 2984 | u32 mem_clock) |
| 2985 | { |
| 2986 | SET_MEMORY_CLOCK_PS_ALLOCATION args; |
| 2987 | int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings); |
| 2988 | u32 tmp = mem_clock | (COMPUTE_MEMORY_PLL_PARAM << 24); |
| 2989 | |
| 2990 | args.ulTargetMemoryClock = cpu_to_le32(tmp); /* 10 khz */ |
| 2991 | |
| 2992 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 2993 | } |
| 2994 | |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 2995 | union set_voltage { |
| 2996 | struct _SET_VOLTAGE_PS_ALLOCATION alloc; |
| 2997 | struct _SET_VOLTAGE_PARAMETERS v1; |
| 2998 | struct _SET_VOLTAGE_PARAMETERS_V2 v2; |
Alex Deucher | e83753b | 2012-03-20 17:18:08 -0400 | [diff] [blame] | 2999 | struct _SET_VOLTAGE_PARAMETERS_V1_3 v3; |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3000 | }; |
| 3001 | |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 3002 | void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type) |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3003 | { |
| 3004 | union set_voltage args; |
| 3005 | int index = GetIndexIntoMasterTable(COMMAND, SetVoltage); |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 3006 | u8 frev, crev, volt_index = voltage_level; |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3007 | |
| 3008 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) |
| 3009 | return; |
| 3010 | |
Alex Deucher | a377e18 | 2011-06-20 13:00:31 -0400 | [diff] [blame] | 3011 | /* 0xff01 is a flag rather then an actual voltage */ |
| 3012 | if (voltage_level == 0xff01) |
| 3013 | return; |
| 3014 | |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3015 | switch (crev) { |
| 3016 | case 1: |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 3017 | args.v1.ucVoltageType = voltage_type; |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3018 | args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE; |
| 3019 | args.v1.ucVoltageIndex = volt_index; |
| 3020 | break; |
| 3021 | case 2: |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 3022 | args.v2.ucVoltageType = voltage_type; |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3023 | args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE; |
Alex Deucher | 8a83ec5 | 2011-04-12 14:49:23 -0400 | [diff] [blame] | 3024 | args.v2.usVoltageLevel = cpu_to_le16(voltage_level); |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3025 | break; |
Alex Deucher | e83753b | 2012-03-20 17:18:08 -0400 | [diff] [blame] | 3026 | case 3: |
| 3027 | args.v3.ucVoltageType = voltage_type; |
| 3028 | args.v3.ucVoltageMode = ATOM_SET_VOLTAGE; |
| 3029 | args.v3.usVoltageLevel = cpu_to_le16(voltage_level); |
| 3030 | break; |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3031 | default: |
| 3032 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3033 | return; |
| 3034 | } |
| 3035 | |
| 3036 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 3037 | } |
| 3038 | |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3039 | int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type, |
| 3040 | u16 voltage_id, u16 *voltage) |
Alex Deucher | ee4017f | 2011-06-23 12:19:32 -0400 | [diff] [blame] | 3041 | { |
| 3042 | union set_voltage args; |
| 3043 | int index = GetIndexIntoMasterTable(COMMAND, SetVoltage); |
| 3044 | u8 frev, crev; |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3045 | |
Alex Deucher | ee4017f | 2011-06-23 12:19:32 -0400 | [diff] [blame] | 3046 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) |
| 3047 | return -EINVAL; |
| 3048 | |
| 3049 | switch (crev) { |
| 3050 | case 1: |
| 3051 | return -EINVAL; |
| 3052 | case 2: |
| 3053 | args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE; |
| 3054 | args.v2.ucVoltageMode = 0; |
| 3055 | args.v2.usVoltageLevel = 0; |
| 3056 | |
| 3057 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 3058 | |
| 3059 | *voltage = le16_to_cpu(args.v2.usVoltageLevel); |
| 3060 | break; |
Alex Deucher | e83753b | 2012-03-20 17:18:08 -0400 | [diff] [blame] | 3061 | case 3: |
| 3062 | args.v3.ucVoltageType = voltage_type; |
| 3063 | args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL; |
| 3064 | args.v3.usVoltageLevel = cpu_to_le16(voltage_id); |
| 3065 | |
| 3066 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 3067 | |
| 3068 | *voltage = le16_to_cpu(args.v3.usVoltageLevel); |
| 3069 | break; |
Alex Deucher | ee4017f | 2011-06-23 12:19:32 -0400 | [diff] [blame] | 3070 | default: |
| 3071 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3072 | return -EINVAL; |
| 3073 | } |
| 3074 | |
| 3075 | return 0; |
| 3076 | } |
Alex Deucher | 7ac9aa5 | 2010-05-27 19:25:54 -0400 | [diff] [blame] | 3077 | |
Alex Deucher | beb79f4 | 2013-02-19 17:14:43 -0500 | [diff] [blame] | 3078 | int radeon_atom_get_leakage_vddc_based_on_leakage_idx(struct radeon_device *rdev, |
| 3079 | u16 *voltage, |
| 3080 | u16 leakage_idx) |
| 3081 | { |
| 3082 | return radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage); |
| 3083 | } |
| 3084 | |
Alex Deucher | 62c35fd7 | 2013-02-19 18:15:06 -0500 | [diff] [blame] | 3085 | int radeon_atom_get_leakage_id_from_vbios(struct radeon_device *rdev, |
| 3086 | u16 *leakage_id) |
| 3087 | { |
| 3088 | union set_voltage args; |
| 3089 | int index = GetIndexIntoMasterTable(COMMAND, SetVoltage); |
| 3090 | u8 frev, crev; |
| 3091 | |
| 3092 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) |
| 3093 | return -EINVAL; |
| 3094 | |
| 3095 | switch (crev) { |
| 3096 | case 3: |
| 3097 | case 4: |
| 3098 | args.v3.ucVoltageType = 0; |
| 3099 | args.v3.ucVoltageMode = ATOM_GET_LEAKAGE_ID; |
| 3100 | args.v3.usVoltageLevel = 0; |
| 3101 | |
| 3102 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 3103 | |
| 3104 | *leakage_id = le16_to_cpu(args.v3.usVoltageLevel); |
| 3105 | break; |
| 3106 | default: |
| 3107 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3108 | return -EINVAL; |
| 3109 | } |
| 3110 | |
| 3111 | return 0; |
| 3112 | } |
| 3113 | |
| 3114 | int radeon_atom_get_leakage_vddc_based_on_leakage_params(struct radeon_device *rdev, |
| 3115 | u16 *vddc, u16 *vddci, |
| 3116 | u16 virtual_voltage_id, |
| 3117 | u16 vbios_voltage_id) |
| 3118 | { |
| 3119 | int index = GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo); |
| 3120 | u8 frev, crev; |
| 3121 | u16 data_offset, size; |
| 3122 | int i, j; |
| 3123 | ATOM_ASIC_PROFILING_INFO_V2_1 *profile; |
| 3124 | u16 *leakage_bin, *vddc_id_buf, *vddc_buf, *vddci_id_buf, *vddci_buf; |
| 3125 | |
| 3126 | *vddc = 0; |
| 3127 | *vddci = 0; |
| 3128 | |
| 3129 | if (!atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3130 | &frev, &crev, &data_offset)) |
| 3131 | return -EINVAL; |
| 3132 | |
| 3133 | profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *) |
| 3134 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3135 | |
| 3136 | switch (frev) { |
| 3137 | case 1: |
| 3138 | return -EINVAL; |
| 3139 | case 2: |
| 3140 | switch (crev) { |
| 3141 | case 1: |
| 3142 | if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1)) |
| 3143 | return -EINVAL; |
| 3144 | leakage_bin = (u16 *) |
| 3145 | (rdev->mode_info.atom_context->bios + data_offset + |
| 3146 | le16_to_cpu(profile->usLeakageBinArrayOffset)); |
| 3147 | vddc_id_buf = (u16 *) |
| 3148 | (rdev->mode_info.atom_context->bios + data_offset + |
| 3149 | le16_to_cpu(profile->usElbVDDC_IdArrayOffset)); |
| 3150 | vddc_buf = (u16 *) |
| 3151 | (rdev->mode_info.atom_context->bios + data_offset + |
| 3152 | le16_to_cpu(profile->usElbVDDC_LevelArrayOffset)); |
| 3153 | vddci_id_buf = (u16 *) |
| 3154 | (rdev->mode_info.atom_context->bios + data_offset + |
| 3155 | le16_to_cpu(profile->usElbVDDCI_IdArrayOffset)); |
| 3156 | vddci_buf = (u16 *) |
| 3157 | (rdev->mode_info.atom_context->bios + data_offset + |
| 3158 | le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset)); |
| 3159 | |
| 3160 | if (profile->ucElbVDDC_Num > 0) { |
| 3161 | for (i = 0; i < profile->ucElbVDDC_Num; i++) { |
| 3162 | if (vddc_id_buf[i] == virtual_voltage_id) { |
| 3163 | for (j = 0; j < profile->ucLeakageBinNum; j++) { |
| 3164 | if (vbios_voltage_id <= leakage_bin[j]) { |
| 3165 | *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i]; |
| 3166 | break; |
| 3167 | } |
| 3168 | } |
| 3169 | break; |
| 3170 | } |
| 3171 | } |
| 3172 | } |
| 3173 | if (profile->ucElbVDDCI_Num > 0) { |
| 3174 | for (i = 0; i < profile->ucElbVDDCI_Num; i++) { |
| 3175 | if (vddci_id_buf[i] == virtual_voltage_id) { |
| 3176 | for (j = 0; j < profile->ucLeakageBinNum; j++) { |
| 3177 | if (vbios_voltage_id <= leakage_bin[j]) { |
| 3178 | *vddci = vddci_buf[j * profile->ucElbVDDCI_Num + i]; |
| 3179 | break; |
| 3180 | } |
| 3181 | } |
| 3182 | break; |
| 3183 | } |
| 3184 | } |
| 3185 | } |
| 3186 | break; |
| 3187 | default: |
| 3188 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3189 | return -EINVAL; |
| 3190 | } |
| 3191 | break; |
| 3192 | default: |
| 3193 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3194 | return -EINVAL; |
| 3195 | } |
| 3196 | |
| 3197 | return 0; |
| 3198 | } |
| 3199 | |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3200 | int radeon_atom_get_voltage_gpio_settings(struct radeon_device *rdev, |
| 3201 | u16 voltage_level, u8 voltage_type, |
| 3202 | u32 *gpio_value, u32 *gpio_mask) |
| 3203 | { |
| 3204 | union set_voltage args; |
| 3205 | int index = GetIndexIntoMasterTable(COMMAND, SetVoltage); |
| 3206 | u8 frev, crev; |
| 3207 | |
| 3208 | if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) |
| 3209 | return -EINVAL; |
| 3210 | |
| 3211 | switch (crev) { |
| 3212 | case 1: |
| 3213 | return -EINVAL; |
| 3214 | case 2: |
| 3215 | args.v2.ucVoltageType = voltage_type; |
| 3216 | args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK; |
| 3217 | args.v2.usVoltageLevel = cpu_to_le16(voltage_level); |
| 3218 | |
| 3219 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 3220 | |
| 3221 | *gpio_mask = le32_to_cpu(*(u32 *)&args.v2); |
| 3222 | |
| 3223 | args.v2.ucVoltageType = voltage_type; |
| 3224 | args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL; |
| 3225 | args.v2.usVoltageLevel = cpu_to_le16(voltage_level); |
| 3226 | |
| 3227 | atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); |
| 3228 | |
| 3229 | *gpio_value = le32_to_cpu(*(u32 *)&args.v2); |
| 3230 | break; |
| 3231 | default: |
| 3232 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3233 | return -EINVAL; |
| 3234 | } |
| 3235 | |
| 3236 | return 0; |
| 3237 | } |
| 3238 | |
| 3239 | union voltage_object_info { |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3240 | struct _ATOM_VOLTAGE_OBJECT_INFO v1; |
| 3241 | struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2; |
| 3242 | struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3243 | }; |
| 3244 | |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3245 | union voltage_object { |
| 3246 | struct _ATOM_VOLTAGE_OBJECT v1; |
| 3247 | struct _ATOM_VOLTAGE_OBJECT_V2 v2; |
| 3248 | union _ATOM_VOLTAGE_OBJECT_V3 v3; |
| 3249 | }; |
| 3250 | |
| 3251 | static ATOM_VOLTAGE_OBJECT *atom_lookup_voltage_object_v1(ATOM_VOLTAGE_OBJECT_INFO *v1, |
| 3252 | u8 voltage_type) |
| 3253 | { |
Alex Deucher | 6e76476 | 2013-06-24 10:54:16 -0400 | [diff] [blame] | 3254 | u32 size = le16_to_cpu(v1->sHeader.usStructureSize); |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3255 | u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO, asVoltageObj[0]); |
| 3256 | u8 *start = (u8 *)v1; |
| 3257 | |
| 3258 | while (offset < size) { |
| 3259 | ATOM_VOLTAGE_OBJECT *vo = (ATOM_VOLTAGE_OBJECT *)(start + offset); |
| 3260 | if (vo->ucVoltageType == voltage_type) |
| 3261 | return vo; |
| 3262 | offset += offsetof(ATOM_VOLTAGE_OBJECT, asFormula.ucVIDAdjustEntries) + |
| 3263 | vo->asFormula.ucNumOfVoltageEntries; |
| 3264 | } |
| 3265 | return NULL; |
| 3266 | } |
| 3267 | |
| 3268 | static ATOM_VOLTAGE_OBJECT_V2 *atom_lookup_voltage_object_v2(ATOM_VOLTAGE_OBJECT_INFO_V2 *v2, |
| 3269 | u8 voltage_type) |
| 3270 | { |
Alex Deucher | 6e76476 | 2013-06-24 10:54:16 -0400 | [diff] [blame] | 3271 | u32 size = le16_to_cpu(v2->sHeader.usStructureSize); |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3272 | u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V2, asVoltageObj[0]); |
| 3273 | u8 *start = (u8*)v2; |
| 3274 | |
| 3275 | while (offset < size) { |
| 3276 | ATOM_VOLTAGE_OBJECT_V2 *vo = (ATOM_VOLTAGE_OBJECT_V2 *)(start + offset); |
| 3277 | if (vo->ucVoltageType == voltage_type) |
| 3278 | return vo; |
| 3279 | offset += offsetof(ATOM_VOLTAGE_OBJECT_V2, asFormula.asVIDAdjustEntries) + |
| 3280 | (vo->asFormula.ucNumOfVoltageEntries * sizeof(VOLTAGE_LUT_ENTRY)); |
| 3281 | } |
| 3282 | return NULL; |
| 3283 | } |
| 3284 | |
| 3285 | static ATOM_VOLTAGE_OBJECT_V3 *atom_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3, |
| 3286 | u8 voltage_type, u8 voltage_mode) |
| 3287 | { |
Alex Deucher | 6e76476 | 2013-06-24 10:54:16 -0400 | [diff] [blame] | 3288 | u32 size = le16_to_cpu(v3->sHeader.usStructureSize); |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3289 | u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]); |
| 3290 | u8 *start = (u8*)v3; |
| 3291 | |
| 3292 | while (offset < size) { |
| 3293 | ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset); |
| 3294 | if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) && |
| 3295 | (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode)) |
| 3296 | return vo; |
Alex Deucher | 6e76476 | 2013-06-24 10:54:16 -0400 | [diff] [blame] | 3297 | offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize); |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3298 | } |
| 3299 | return NULL; |
| 3300 | } |
| 3301 | |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3302 | bool |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3303 | radeon_atom_is_voltage_gpio(struct radeon_device *rdev, |
| 3304 | u8 voltage_type, u8 voltage_mode) |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3305 | { |
| 3306 | int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo); |
| 3307 | u8 frev, crev; |
| 3308 | u16 data_offset, size; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3309 | union voltage_object_info *voltage_info; |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3310 | union voltage_object *voltage_object = NULL; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3311 | |
| 3312 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3313 | &frev, &crev, &data_offset)) { |
| 3314 | voltage_info = (union voltage_object_info *) |
| 3315 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3316 | |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3317 | switch (frev) { |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3318 | case 1: |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3319 | case 2: |
| 3320 | switch (crev) { |
| 3321 | case 1: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3322 | voltage_object = (union voltage_object *) |
| 3323 | atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type); |
| 3324 | if (voltage_object && |
| 3325 | (voltage_object->v1.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO)) |
| 3326 | return true; |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3327 | break; |
| 3328 | case 2: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3329 | voltage_object = (union voltage_object *) |
| 3330 | atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type); |
| 3331 | if (voltage_object && |
| 3332 | (voltage_object->v2.asControl.ucVoltageControlId == VOLTAGE_CONTROLLED_BY_GPIO)) |
| 3333 | return true; |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3334 | break; |
| 3335 | default: |
| 3336 | DRM_ERROR("unknown voltage object table\n"); |
| 3337 | return false; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3338 | } |
| 3339 | break; |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3340 | case 3: |
| 3341 | switch (crev) { |
| 3342 | case 1: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3343 | if (atom_lookup_voltage_object_v3(&voltage_info->v3, |
| 3344 | voltage_type, voltage_mode)) |
| 3345 | return true; |
Alex Deucher | 58653ab | 2013-02-13 17:04:59 -0500 | [diff] [blame] | 3346 | break; |
| 3347 | default: |
| 3348 | DRM_ERROR("unknown voltage object table\n"); |
| 3349 | return false; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3350 | } |
| 3351 | break; |
| 3352 | default: |
| 3353 | DRM_ERROR("unknown voltage object table\n"); |
| 3354 | return false; |
| 3355 | } |
| 3356 | |
| 3357 | } |
| 3358 | return false; |
| 3359 | } |
| 3360 | |
| 3361 | int radeon_atom_get_max_voltage(struct radeon_device *rdev, |
| 3362 | u8 voltage_type, u16 *max_voltage) |
| 3363 | { |
| 3364 | int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo); |
| 3365 | u8 frev, crev; |
| 3366 | u16 data_offset, size; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3367 | union voltage_object_info *voltage_info; |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3368 | union voltage_object *voltage_object = NULL; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3369 | |
| 3370 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3371 | &frev, &crev, &data_offset)) { |
| 3372 | voltage_info = (union voltage_object_info *) |
| 3373 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3374 | |
| 3375 | switch (crev) { |
| 3376 | case 1: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3377 | voltage_object = (union voltage_object *) |
| 3378 | atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type); |
| 3379 | if (voltage_object) { |
| 3380 | ATOM_VOLTAGE_FORMULA *formula = |
| 3381 | &voltage_object->v1.asFormula; |
| 3382 | if (formula->ucFlag & 1) |
| 3383 | *max_voltage = |
| 3384 | le16_to_cpu(formula->usVoltageBaseLevel) + |
| 3385 | formula->ucNumOfVoltageEntries / 2 * |
| 3386 | le16_to_cpu(formula->usVoltageStep); |
| 3387 | else |
| 3388 | *max_voltage = |
| 3389 | le16_to_cpu(formula->usVoltageBaseLevel) + |
| 3390 | (formula->ucNumOfVoltageEntries - 1) * |
| 3391 | le16_to_cpu(formula->usVoltageStep); |
| 3392 | return 0; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3393 | } |
| 3394 | break; |
| 3395 | case 2: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3396 | voltage_object = (union voltage_object *) |
| 3397 | atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type); |
| 3398 | if (voltage_object) { |
| 3399 | ATOM_VOLTAGE_FORMULA_V2 *formula = |
| 3400 | &voltage_object->v2.asFormula; |
| 3401 | if (formula->ucNumOfVoltageEntries) { |
| 3402 | *max_voltage = |
| 3403 | le16_to_cpu(formula->asVIDAdjustEntries[ |
| 3404 | formula->ucNumOfVoltageEntries - 1 |
| 3405 | ].usVoltageValue); |
| 3406 | return 0; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3407 | } |
| 3408 | } |
| 3409 | break; |
| 3410 | default: |
| 3411 | DRM_ERROR("unknown voltage object table\n"); |
| 3412 | return -EINVAL; |
| 3413 | } |
| 3414 | |
| 3415 | } |
| 3416 | return -EINVAL; |
| 3417 | } |
| 3418 | |
| 3419 | int radeon_atom_get_min_voltage(struct radeon_device *rdev, |
| 3420 | u8 voltage_type, u16 *min_voltage) |
| 3421 | { |
| 3422 | int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo); |
| 3423 | u8 frev, crev; |
| 3424 | u16 data_offset, size; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3425 | union voltage_object_info *voltage_info; |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3426 | union voltage_object *voltage_object = NULL; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3427 | |
| 3428 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3429 | &frev, &crev, &data_offset)) { |
| 3430 | voltage_info = (union voltage_object_info *) |
| 3431 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3432 | |
| 3433 | switch (crev) { |
| 3434 | case 1: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3435 | voltage_object = (union voltage_object *) |
| 3436 | atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type); |
| 3437 | if (voltage_object) { |
| 3438 | ATOM_VOLTAGE_FORMULA *formula = |
| 3439 | &voltage_object->v1.asFormula; |
| 3440 | *min_voltage = |
| 3441 | le16_to_cpu(formula->usVoltageBaseLevel); |
| 3442 | return 0; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3443 | } |
| 3444 | break; |
| 3445 | case 2: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3446 | voltage_object = (union voltage_object *) |
| 3447 | atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type); |
| 3448 | if (voltage_object) { |
| 3449 | ATOM_VOLTAGE_FORMULA_V2 *formula = |
| 3450 | &voltage_object->v2.asFormula; |
| 3451 | if (formula->ucNumOfVoltageEntries) { |
| 3452 | *min_voltage = |
| 3453 | le16_to_cpu(formula->asVIDAdjustEntries[ |
| 3454 | 0 |
| 3455 | ].usVoltageValue); |
| 3456 | return 0; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3457 | } |
| 3458 | } |
| 3459 | break; |
| 3460 | default: |
| 3461 | DRM_ERROR("unknown voltage object table\n"); |
| 3462 | return -EINVAL; |
| 3463 | } |
| 3464 | |
| 3465 | } |
| 3466 | return -EINVAL; |
| 3467 | } |
| 3468 | |
| 3469 | int radeon_atom_get_voltage_step(struct radeon_device *rdev, |
| 3470 | u8 voltage_type, u16 *voltage_step) |
| 3471 | { |
| 3472 | int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo); |
| 3473 | u8 frev, crev; |
| 3474 | u16 data_offset, size; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3475 | union voltage_object_info *voltage_info; |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3476 | union voltage_object *voltage_object = NULL; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3477 | |
| 3478 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3479 | &frev, &crev, &data_offset)) { |
| 3480 | voltage_info = (union voltage_object_info *) |
| 3481 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3482 | |
| 3483 | switch (crev) { |
| 3484 | case 1: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3485 | voltage_object = (union voltage_object *) |
| 3486 | atom_lookup_voltage_object_v1(&voltage_info->v1, voltage_type); |
| 3487 | if (voltage_object) { |
| 3488 | ATOM_VOLTAGE_FORMULA *formula = |
| 3489 | &voltage_object->v1.asFormula; |
| 3490 | if (formula->ucFlag & 1) |
| 3491 | *voltage_step = |
| 3492 | (le16_to_cpu(formula->usVoltageStep) + 1) / 2; |
| 3493 | else |
| 3494 | *voltage_step = |
| 3495 | le16_to_cpu(formula->usVoltageStep); |
| 3496 | return 0; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3497 | } |
| 3498 | break; |
| 3499 | case 2: |
| 3500 | return -EINVAL; |
| 3501 | default: |
| 3502 | DRM_ERROR("unknown voltage object table\n"); |
| 3503 | return -EINVAL; |
| 3504 | } |
| 3505 | |
| 3506 | } |
| 3507 | return -EINVAL; |
| 3508 | } |
| 3509 | |
| 3510 | int radeon_atom_round_to_true_voltage(struct radeon_device *rdev, |
| 3511 | u8 voltage_type, |
| 3512 | u16 nominal_voltage, |
| 3513 | u16 *true_voltage) |
| 3514 | { |
| 3515 | u16 min_voltage, max_voltage, voltage_step; |
| 3516 | |
| 3517 | if (radeon_atom_get_max_voltage(rdev, voltage_type, &max_voltage)) |
| 3518 | return -EINVAL; |
| 3519 | if (radeon_atom_get_min_voltage(rdev, voltage_type, &min_voltage)) |
| 3520 | return -EINVAL; |
| 3521 | if (radeon_atom_get_voltage_step(rdev, voltage_type, &voltage_step)) |
| 3522 | return -EINVAL; |
| 3523 | |
| 3524 | if (nominal_voltage <= min_voltage) |
| 3525 | *true_voltage = min_voltage; |
| 3526 | else if (nominal_voltage >= max_voltage) |
| 3527 | *true_voltage = max_voltage; |
| 3528 | else |
| 3529 | *true_voltage = min_voltage + |
| 3530 | ((nominal_voltage - min_voltage) / voltage_step) * |
| 3531 | voltage_step; |
| 3532 | |
| 3533 | return 0; |
| 3534 | } |
| 3535 | |
| 3536 | int radeon_atom_get_voltage_table(struct radeon_device *rdev, |
Alex Deucher | 6517194 | 2013-02-13 17:29:54 -0500 | [diff] [blame] | 3537 | u8 voltage_type, u8 voltage_mode, |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3538 | struct atom_voltage_table *voltage_table) |
| 3539 | { |
| 3540 | int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo); |
| 3541 | u8 frev, crev; |
| 3542 | u16 data_offset, size; |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3543 | int i, ret; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3544 | union voltage_object_info *voltage_info; |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3545 | union voltage_object *voltage_object = NULL; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3546 | |
| 3547 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3548 | &frev, &crev, &data_offset)) { |
| 3549 | voltage_info = (union voltage_object_info *) |
| 3550 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3551 | |
Alex Deucher | 6517194 | 2013-02-13 17:29:54 -0500 | [diff] [blame] | 3552 | switch (frev) { |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3553 | case 1: |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3554 | case 2: |
Alex Deucher | 6517194 | 2013-02-13 17:29:54 -0500 | [diff] [blame] | 3555 | switch (crev) { |
| 3556 | case 1: |
| 3557 | DRM_ERROR("old table version %d, %d\n", frev, crev); |
| 3558 | return -EINVAL; |
| 3559 | case 2: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3560 | voltage_object = (union voltage_object *) |
| 3561 | atom_lookup_voltage_object_v2(&voltage_info->v2, voltage_type); |
| 3562 | if (voltage_object) { |
| 3563 | ATOM_VOLTAGE_FORMULA_V2 *formula = |
| 3564 | &voltage_object->v2.asFormula; |
| 3565 | if (formula->ucNumOfVoltageEntries > MAX_VOLTAGE_ENTRIES) |
| 3566 | return -EINVAL; |
| 3567 | for (i = 0; i < formula->ucNumOfVoltageEntries; i++) { |
| 3568 | voltage_table->entries[i].value = |
| 3569 | le16_to_cpu(formula->asVIDAdjustEntries[i].usVoltageValue); |
| 3570 | ret = radeon_atom_get_voltage_gpio_settings(rdev, |
| 3571 | voltage_table->entries[i].value, |
| 3572 | voltage_type, |
| 3573 | &voltage_table->entries[i].smio_low, |
| 3574 | &voltage_table->mask_low); |
| 3575 | if (ret) |
| 3576 | return ret; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3577 | } |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3578 | voltage_table->count = formula->ucNumOfVoltageEntries; |
| 3579 | return 0; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3580 | } |
Alex Deucher | 6517194 | 2013-02-13 17:29:54 -0500 | [diff] [blame] | 3581 | break; |
| 3582 | default: |
| 3583 | DRM_ERROR("unknown voltage object table\n"); |
| 3584 | return -EINVAL; |
| 3585 | } |
| 3586 | break; |
| 3587 | case 3: |
| 3588 | switch (crev) { |
| 3589 | case 1: |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3590 | voltage_object = (union voltage_object *) |
| 3591 | atom_lookup_voltage_object_v3(&voltage_info->v3, |
| 3592 | voltage_type, voltage_mode); |
| 3593 | if (voltage_object) { |
| 3594 | ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio = |
| 3595 | &voltage_object->v3.asGpioVoltageObj; |
| 3596 | if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES) |
| 3597 | return -EINVAL; |
| 3598 | for (i = 0; i < gpio->ucGpioEntryNum; i++) { |
| 3599 | voltage_table->entries[i].value = |
| 3600 | le16_to_cpu(gpio->asVolGpioLut[i].usVoltageValue); |
| 3601 | voltage_table->entries[i].smio_low = |
| 3602 | le32_to_cpu(gpio->asVolGpioLut[i].ulVoltageId); |
Alex Deucher | 6517194 | 2013-02-13 17:29:54 -0500 | [diff] [blame] | 3603 | } |
Alex Deucher | 779187f | 2013-03-28 14:47:34 -0400 | [diff] [blame] | 3604 | voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal); |
| 3605 | voltage_table->count = gpio->ucGpioEntryNum; |
| 3606 | voltage_table->phase_delay = gpio->ucPhaseDelay; |
| 3607 | return 0; |
Alex Deucher | 6517194 | 2013-02-13 17:29:54 -0500 | [diff] [blame] | 3608 | } |
| 3609 | break; |
| 3610 | default: |
| 3611 | DRM_ERROR("unknown voltage object table\n"); |
| 3612 | return -EINVAL; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3613 | } |
| 3614 | break; |
| 3615 | default: |
| 3616 | DRM_ERROR("unknown voltage object table\n"); |
| 3617 | return -EINVAL; |
| 3618 | } |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3619 | } |
| 3620 | return -EINVAL; |
| 3621 | } |
| 3622 | |
| 3623 | union vram_info { |
| 3624 | struct _ATOM_VRAM_INFO_V3 v1_3; |
| 3625 | struct _ATOM_VRAM_INFO_V4 v1_4; |
| 3626 | struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1; |
| 3627 | }; |
| 3628 | |
| 3629 | int radeon_atom_get_memory_info(struct radeon_device *rdev, |
| 3630 | u8 module_index, struct atom_memory_info *mem_info) |
| 3631 | { |
| 3632 | int index = GetIndexIntoMasterTable(DATA, VRAM_Info); |
| 3633 | u8 frev, crev, i; |
| 3634 | u16 data_offset, size; |
| 3635 | union vram_info *vram_info; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3636 | |
| 3637 | memset(mem_info, 0, sizeof(struct atom_memory_info)); |
| 3638 | |
| 3639 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3640 | &frev, &crev, &data_offset)) { |
| 3641 | vram_info = (union vram_info *) |
| 3642 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3643 | switch (frev) { |
| 3644 | case 1: |
| 3645 | switch (crev) { |
| 3646 | case 3: |
| 3647 | /* r6xx */ |
| 3648 | if (module_index < vram_info->v1_3.ucNumOfVRAMModule) { |
| 3649 | ATOM_VRAM_MODULE_V3 *vram_module = |
| 3650 | (ATOM_VRAM_MODULE_V3 *)vram_info->v1_3.aVramInfo; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3651 | |
| 3652 | for (i = 0; i < module_index; i++) { |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3653 | if (le16_to_cpu(vram_module->usSize) == 0) |
| 3654 | return -EINVAL; |
Alex Deucher | 77c7d50 | 2013-07-17 10:52:43 -0400 | [diff] [blame] | 3655 | vram_module = (ATOM_VRAM_MODULE_V3 *) |
| 3656 | ((u8 *)vram_module + le16_to_cpu(vram_module->usSize)); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3657 | } |
| 3658 | mem_info->mem_vendor = vram_module->asMemory.ucMemoryVenderID & 0xf; |
| 3659 | mem_info->mem_type = vram_module->asMemory.ucMemoryType & 0xf0; |
| 3660 | } else |
| 3661 | return -EINVAL; |
| 3662 | break; |
| 3663 | case 4: |
| 3664 | /* r7xx, evergreen */ |
| 3665 | if (module_index < vram_info->v1_4.ucNumOfVRAMModule) { |
| 3666 | ATOM_VRAM_MODULE_V4 *vram_module = |
| 3667 | (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3668 | |
| 3669 | for (i = 0; i < module_index; i++) { |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3670 | if (le16_to_cpu(vram_module->usModuleSize) == 0) |
| 3671 | return -EINVAL; |
Alex Deucher | 77c7d50 | 2013-07-17 10:52:43 -0400 | [diff] [blame] | 3672 | vram_module = (ATOM_VRAM_MODULE_V4 *) |
| 3673 | ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize)); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3674 | } |
| 3675 | mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf; |
| 3676 | mem_info->mem_type = vram_module->ucMemoryType & 0xf0; |
| 3677 | } else |
| 3678 | return -EINVAL; |
| 3679 | break; |
| 3680 | default: |
| 3681 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3682 | return -EINVAL; |
| 3683 | } |
| 3684 | break; |
| 3685 | case 2: |
| 3686 | switch (crev) { |
| 3687 | case 1: |
| 3688 | /* ni */ |
| 3689 | if (module_index < vram_info->v2_1.ucNumOfVRAMModule) { |
| 3690 | ATOM_VRAM_MODULE_V7 *vram_module = |
| 3691 | (ATOM_VRAM_MODULE_V7 *)vram_info->v2_1.aVramInfo; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3692 | |
| 3693 | for (i = 0; i < module_index; i++) { |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3694 | if (le16_to_cpu(vram_module->usModuleSize) == 0) |
| 3695 | return -EINVAL; |
Alex Deucher | 77c7d50 | 2013-07-17 10:52:43 -0400 | [diff] [blame] | 3696 | vram_module = (ATOM_VRAM_MODULE_V7 *) |
| 3697 | ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize)); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3698 | } |
| 3699 | mem_info->mem_vendor = vram_module->ucMemoryVenderID & 0xf; |
| 3700 | mem_info->mem_type = vram_module->ucMemoryType & 0xf0; |
| 3701 | } else |
| 3702 | return -EINVAL; |
| 3703 | break; |
| 3704 | default: |
| 3705 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3706 | return -EINVAL; |
| 3707 | } |
| 3708 | break; |
| 3709 | default: |
| 3710 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3711 | return -EINVAL; |
| 3712 | } |
| 3713 | return 0; |
| 3714 | } |
| 3715 | return -EINVAL; |
| 3716 | } |
| 3717 | |
| 3718 | int radeon_atom_get_mclk_range_table(struct radeon_device *rdev, |
| 3719 | bool gddr5, u8 module_index, |
| 3720 | struct atom_memory_clock_range_table *mclk_range_table) |
| 3721 | { |
| 3722 | int index = GetIndexIntoMasterTable(DATA, VRAM_Info); |
| 3723 | u8 frev, crev, i; |
| 3724 | u16 data_offset, size; |
| 3725 | union vram_info *vram_info; |
| 3726 | u32 mem_timing_size = gddr5 ? |
| 3727 | sizeof(ATOM_MEMORY_TIMING_FORMAT_V2) : sizeof(ATOM_MEMORY_TIMING_FORMAT); |
| 3728 | u8 *p; |
| 3729 | |
| 3730 | memset(mclk_range_table, 0, sizeof(struct atom_memory_clock_range_table)); |
| 3731 | |
| 3732 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3733 | &frev, &crev, &data_offset)) { |
| 3734 | vram_info = (union vram_info *) |
| 3735 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3736 | switch (frev) { |
| 3737 | case 1: |
| 3738 | switch (crev) { |
| 3739 | case 3: |
| 3740 | DRM_ERROR("old table version %d, %d\n", frev, crev); |
| 3741 | return -EINVAL; |
| 3742 | case 4: |
| 3743 | /* r7xx, evergreen */ |
| 3744 | if (module_index < vram_info->v1_4.ucNumOfVRAMModule) { |
| 3745 | ATOM_VRAM_MODULE_V4 *vram_module = |
| 3746 | (ATOM_VRAM_MODULE_V4 *)vram_info->v1_4.aVramInfo; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3747 | |
| 3748 | for (i = 0; i < module_index; i++) { |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3749 | if (le16_to_cpu(vram_module->usModuleSize) == 0) |
| 3750 | return -EINVAL; |
Alex Deucher | 77c7d50 | 2013-07-17 10:52:43 -0400 | [diff] [blame] | 3751 | vram_module = (ATOM_VRAM_MODULE_V4 *) |
| 3752 | ((u8 *)vram_module + le16_to_cpu(vram_module->usModuleSize)); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3753 | } |
| 3754 | mclk_range_table->num_entries = (u8) |
Alex Deucher | 1fa4252 | 2013-07-17 10:18:52 -0400 | [diff] [blame] | 3755 | ((le16_to_cpu(vram_module->usModuleSize) - offsetof(ATOM_VRAM_MODULE_V4, asMemTiming)) / |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3756 | mem_timing_size); |
Alex Deucher | 77c7d50 | 2013-07-17 10:52:43 -0400 | [diff] [blame] | 3757 | p = (u8 *)&vram_module->asMemTiming[0]; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3758 | for (i = 0; i < mclk_range_table->num_entries; i++) { |
Alex Deucher | 77c7d50 | 2013-07-17 10:52:43 -0400 | [diff] [blame] | 3759 | ATOM_MEMORY_TIMING_FORMAT *format = (ATOM_MEMORY_TIMING_FORMAT *)p; |
Alex Deucher | e631227 | 2013-07-03 11:18:08 -0400 | [diff] [blame] | 3760 | mclk_range_table->mclk[i] = le32_to_cpu(format->ulClkRange); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3761 | p += mem_timing_size; |
| 3762 | } |
| 3763 | } else |
| 3764 | return -EINVAL; |
| 3765 | break; |
| 3766 | default: |
| 3767 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3768 | return -EINVAL; |
| 3769 | } |
| 3770 | break; |
| 3771 | case 2: |
| 3772 | DRM_ERROR("new table version %d, %d\n", frev, crev); |
| 3773 | return -EINVAL; |
| 3774 | default: |
| 3775 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3776 | return -EINVAL; |
| 3777 | } |
| 3778 | return 0; |
| 3779 | } |
| 3780 | return -EINVAL; |
| 3781 | } |
| 3782 | |
| 3783 | #define MEM_ID_MASK 0xff000000 |
| 3784 | #define MEM_ID_SHIFT 24 |
| 3785 | #define CLOCK_RANGE_MASK 0x00ffffff |
| 3786 | #define CLOCK_RANGE_SHIFT 0 |
| 3787 | #define LOW_NIBBLE_MASK 0xf |
| 3788 | #define DATA_EQU_PREV 0 |
| 3789 | #define DATA_FROM_TABLE 4 |
| 3790 | |
| 3791 | int radeon_atom_init_mc_reg_table(struct radeon_device *rdev, |
| 3792 | u8 module_index, |
| 3793 | struct atom_mc_reg_table *reg_table) |
| 3794 | { |
| 3795 | int index = GetIndexIntoMasterTable(DATA, VRAM_Info); |
| 3796 | u8 frev, crev, num_entries, t_mem_id, num_ranges = 0; |
| 3797 | u32 i = 0, j; |
| 3798 | u16 data_offset, size; |
| 3799 | union vram_info *vram_info; |
| 3800 | |
| 3801 | memset(reg_table, 0, sizeof(struct atom_mc_reg_table)); |
| 3802 | |
| 3803 | if (atom_parse_data_header(rdev->mode_info.atom_context, index, &size, |
| 3804 | &frev, &crev, &data_offset)) { |
| 3805 | vram_info = (union vram_info *) |
| 3806 | (rdev->mode_info.atom_context->bios + data_offset); |
| 3807 | switch (frev) { |
| 3808 | case 1: |
| 3809 | DRM_ERROR("old table version %d, %d\n", frev, crev); |
| 3810 | return -EINVAL; |
| 3811 | case 2: |
| 3812 | switch (crev) { |
| 3813 | case 1: |
| 3814 | if (module_index < vram_info->v2_1.ucNumOfVRAMModule) { |
| 3815 | ATOM_INIT_REG_BLOCK *reg_block = |
| 3816 | (ATOM_INIT_REG_BLOCK *) |
| 3817 | ((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset)); |
| 3818 | ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data = |
| 3819 | (ATOM_MEMORY_SETTING_DATA_BLOCK *) |
| 3820 | ((u8 *)reg_block + (2 * sizeof(u16)) + |
| 3821 | le16_to_cpu(reg_block->usRegIndexTblSize)); |
Alex Deucher | f90555c | 2013-07-17 16:34:12 -0400 | [diff] [blame] | 3822 | ATOM_INIT_REG_INDEX_FORMAT *format = ®_block->asRegIndexBuf[0]; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3823 | num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) / |
| 3824 | sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1; |
| 3825 | if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE) |
| 3826 | return -EINVAL; |
Andre Heider | 48fa04c | 2013-07-17 14:02:23 -0400 | [diff] [blame] | 3827 | while (i < num_entries) { |
Alex Deucher | f90555c | 2013-07-17 16:34:12 -0400 | [diff] [blame] | 3828 | if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER) |
Andre Heider | 48fa04c | 2013-07-17 14:02:23 -0400 | [diff] [blame] | 3829 | break; |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3830 | reg_table->mc_reg_address[i].s1 = |
Alex Deucher | f90555c | 2013-07-17 16:34:12 -0400 | [diff] [blame] | 3831 | (u16)(le16_to_cpu(format->usRegIndex)); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3832 | reg_table->mc_reg_address[i].pre_reg_data = |
Alex Deucher | f90555c | 2013-07-17 16:34:12 -0400 | [diff] [blame] | 3833 | (u8)(format->ucPreRegDataLength); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3834 | i++; |
Alex Deucher | f90555c | 2013-07-17 16:34:12 -0400 | [diff] [blame] | 3835 | format = (ATOM_INIT_REG_INDEX_FORMAT *) |
| 3836 | ((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT)); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3837 | } |
| 3838 | reg_table->last = i; |
| 3839 | while ((*(u32 *)reg_data != END_OF_REG_DATA_BLOCK) && |
| 3840 | (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) { |
| 3841 | t_mem_id = (u8)((*(u32 *)reg_data & MEM_ID_MASK) >> MEM_ID_SHIFT); |
| 3842 | if (module_index == t_mem_id) { |
| 3843 | reg_table->mc_reg_table_entry[num_ranges].mclk_max = |
| 3844 | (u32)((*(u32 *)reg_data & CLOCK_RANGE_MASK) >> CLOCK_RANGE_SHIFT); |
| 3845 | for (i = 0, j = 1; i < reg_table->last; i++) { |
| 3846 | if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) { |
| 3847 | reg_table->mc_reg_table_entry[num_ranges].mc_data[i] = |
| 3848 | (u32)*((u32 *)reg_data + j); |
| 3849 | j++; |
| 3850 | } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) { |
| 3851 | reg_table->mc_reg_table_entry[num_ranges].mc_data[i] = |
| 3852 | reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1]; |
| 3853 | } |
| 3854 | } |
| 3855 | num_ranges++; |
| 3856 | } |
Alex Deucher | 4da18e2 | 2013-07-01 13:33:53 -0400 | [diff] [blame] | 3857 | reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *) |
| 3858 | ((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize)); |
Alex Deucher | ae5b0ab | 2013-06-24 10:50:34 -0400 | [diff] [blame] | 3859 | } |
| 3860 | if (*(u32 *)reg_data != END_OF_REG_DATA_BLOCK) |
| 3861 | return -EINVAL; |
| 3862 | reg_table->num_entries = num_ranges; |
| 3863 | } else |
| 3864 | return -EINVAL; |
| 3865 | break; |
| 3866 | default: |
| 3867 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3868 | return -EINVAL; |
| 3869 | } |
| 3870 | break; |
| 3871 | default: |
| 3872 | DRM_ERROR("Unknown table version %d, %d\n", frev, crev); |
| 3873 | return -EINVAL; |
| 3874 | } |
| 3875 | return 0; |
| 3876 | } |
| 3877 | return -EINVAL; |
| 3878 | } |
| 3879 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3880 | void radeon_atom_initialize_bios_scratch_regs(struct drm_device *dev) |
| 3881 | { |
| 3882 | struct radeon_device *rdev = dev->dev_private; |
| 3883 | uint32_t bios_2_scratch, bios_6_scratch; |
| 3884 | |
| 3885 | if (rdev->family >= CHIP_R600) { |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 3886 | bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3887 | bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH); |
| 3888 | } else { |
Dave Airlie | 4ce001a | 2009-08-13 16:32:14 +1000 | [diff] [blame] | 3889 | bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3890 | bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH); |
| 3891 | } |
| 3892 | |
| 3893 | /* let the bios control the backlight */ |
| 3894 | bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE; |
| 3895 | |
| 3896 | /* tell the bios not to handle mode switching */ |
Alex Deucher | 8736476 | 2011-02-02 19:46:06 -0500 | [diff] [blame] | 3897 | bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH; |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3898 | |
| 3899 | if (rdev->family >= CHIP_R600) { |
| 3900 | WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch); |
| 3901 | WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch); |
| 3902 | } else { |
| 3903 | WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch); |
| 3904 | WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch); |
| 3905 | } |
| 3906 | |
| 3907 | } |
| 3908 | |
Yang Zhao | f657c2a | 2009-09-15 12:21:01 +1000 | [diff] [blame] | 3909 | void radeon_save_bios_scratch_regs(struct radeon_device *rdev) |
| 3910 | { |
| 3911 | uint32_t scratch_reg; |
| 3912 | int i; |
| 3913 | |
| 3914 | if (rdev->family >= CHIP_R600) |
| 3915 | scratch_reg = R600_BIOS_0_SCRATCH; |
| 3916 | else |
| 3917 | scratch_reg = RADEON_BIOS_0_SCRATCH; |
| 3918 | |
| 3919 | for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++) |
| 3920 | rdev->bios_scratch[i] = RREG32(scratch_reg + (i * 4)); |
| 3921 | } |
| 3922 | |
| 3923 | void radeon_restore_bios_scratch_regs(struct radeon_device *rdev) |
| 3924 | { |
| 3925 | uint32_t scratch_reg; |
| 3926 | int i; |
| 3927 | |
| 3928 | if (rdev->family >= CHIP_R600) |
| 3929 | scratch_reg = R600_BIOS_0_SCRATCH; |
| 3930 | else |
| 3931 | scratch_reg = RADEON_BIOS_0_SCRATCH; |
| 3932 | |
| 3933 | for (i = 0; i < RADEON_BIOS_NUM_SCRATCH; i++) |
| 3934 | WREG32(scratch_reg + (i * 4), rdev->bios_scratch[i]); |
| 3935 | } |
| 3936 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3937 | void radeon_atom_output_lock(struct drm_encoder *encoder, bool lock) |
| 3938 | { |
| 3939 | struct drm_device *dev = encoder->dev; |
| 3940 | struct radeon_device *rdev = dev->dev_private; |
| 3941 | uint32_t bios_6_scratch; |
| 3942 | |
| 3943 | if (rdev->family >= CHIP_R600) |
| 3944 | bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH); |
| 3945 | else |
| 3946 | bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH); |
| 3947 | |
Alex Deucher | 8736476 | 2011-02-02 19:46:06 -0500 | [diff] [blame] | 3948 | if (lock) { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3949 | bios_6_scratch |= ATOM_S6_CRITICAL_STATE; |
Alex Deucher | 8736476 | 2011-02-02 19:46:06 -0500 | [diff] [blame] | 3950 | bios_6_scratch &= ~ATOM_S6_ACC_MODE; |
| 3951 | } else { |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3952 | bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE; |
Alex Deucher | 8736476 | 2011-02-02 19:46:06 -0500 | [diff] [blame] | 3953 | bios_6_scratch |= ATOM_S6_ACC_MODE; |
| 3954 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3955 | |
| 3956 | if (rdev->family >= CHIP_R600) |
| 3957 | WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch); |
| 3958 | else |
| 3959 | WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch); |
| 3960 | } |
| 3961 | |
| 3962 | /* at some point we may want to break this out into individual functions */ |
| 3963 | void |
| 3964 | radeon_atombios_connected_scratch_regs(struct drm_connector *connector, |
| 3965 | struct drm_encoder *encoder, |
| 3966 | bool connected) |
| 3967 | { |
| 3968 | struct drm_device *dev = connector->dev; |
| 3969 | struct radeon_device *rdev = dev->dev_private; |
| 3970 | struct radeon_connector *radeon_connector = |
| 3971 | to_radeon_connector(connector); |
| 3972 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 3973 | uint32_t bios_0_scratch, bios_3_scratch, bios_6_scratch; |
| 3974 | |
| 3975 | if (rdev->family >= CHIP_R600) { |
| 3976 | bios_0_scratch = RREG32(R600_BIOS_0_SCRATCH); |
| 3977 | bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH); |
| 3978 | bios_6_scratch = RREG32(R600_BIOS_6_SCRATCH); |
| 3979 | } else { |
| 3980 | bios_0_scratch = RREG32(RADEON_BIOS_0_SCRATCH); |
| 3981 | bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH); |
| 3982 | bios_6_scratch = RREG32(RADEON_BIOS_6_SCRATCH); |
| 3983 | } |
| 3984 | |
| 3985 | if ((radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) && |
| 3986 | (radeon_connector->devices & ATOM_DEVICE_TV1_SUPPORT)) { |
| 3987 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 3988 | DRM_DEBUG_KMS("TV1 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3989 | bios_3_scratch |= ATOM_S3_TV1_ACTIVE; |
| 3990 | bios_6_scratch |= ATOM_S6_ACC_REQ_TV1; |
| 3991 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 3992 | DRM_DEBUG_KMS("TV1 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 3993 | bios_0_scratch &= ~ATOM_S0_TV1_MASK; |
| 3994 | bios_3_scratch &= ~ATOM_S3_TV1_ACTIVE; |
| 3995 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_TV1; |
| 3996 | } |
| 3997 | } |
| 3998 | if ((radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) && |
| 3999 | (radeon_connector->devices & ATOM_DEVICE_CV_SUPPORT)) { |
| 4000 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4001 | DRM_DEBUG_KMS("CV connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4002 | bios_3_scratch |= ATOM_S3_CV_ACTIVE; |
| 4003 | bios_6_scratch |= ATOM_S6_ACC_REQ_CV; |
| 4004 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4005 | DRM_DEBUG_KMS("CV disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4006 | bios_0_scratch &= ~ATOM_S0_CV_MASK; |
| 4007 | bios_3_scratch &= ~ATOM_S3_CV_ACTIVE; |
| 4008 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_CV; |
| 4009 | } |
| 4010 | } |
| 4011 | if ((radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) && |
| 4012 | (radeon_connector->devices & ATOM_DEVICE_LCD1_SUPPORT)) { |
| 4013 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4014 | DRM_DEBUG_KMS("LCD1 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4015 | bios_0_scratch |= ATOM_S0_LCD1; |
| 4016 | bios_3_scratch |= ATOM_S3_LCD1_ACTIVE; |
| 4017 | bios_6_scratch |= ATOM_S6_ACC_REQ_LCD1; |
| 4018 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4019 | DRM_DEBUG_KMS("LCD1 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4020 | bios_0_scratch &= ~ATOM_S0_LCD1; |
| 4021 | bios_3_scratch &= ~ATOM_S3_LCD1_ACTIVE; |
| 4022 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_LCD1; |
| 4023 | } |
| 4024 | } |
| 4025 | if ((radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) && |
| 4026 | (radeon_connector->devices & ATOM_DEVICE_CRT1_SUPPORT)) { |
| 4027 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4028 | DRM_DEBUG_KMS("CRT1 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4029 | bios_0_scratch |= ATOM_S0_CRT1_COLOR; |
| 4030 | bios_3_scratch |= ATOM_S3_CRT1_ACTIVE; |
| 4031 | bios_6_scratch |= ATOM_S6_ACC_REQ_CRT1; |
| 4032 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4033 | DRM_DEBUG_KMS("CRT1 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4034 | bios_0_scratch &= ~ATOM_S0_CRT1_MASK; |
| 4035 | bios_3_scratch &= ~ATOM_S3_CRT1_ACTIVE; |
| 4036 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT1; |
| 4037 | } |
| 4038 | } |
| 4039 | if ((radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) && |
| 4040 | (radeon_connector->devices & ATOM_DEVICE_CRT2_SUPPORT)) { |
| 4041 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4042 | DRM_DEBUG_KMS("CRT2 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4043 | bios_0_scratch |= ATOM_S0_CRT2_COLOR; |
| 4044 | bios_3_scratch |= ATOM_S3_CRT2_ACTIVE; |
| 4045 | bios_6_scratch |= ATOM_S6_ACC_REQ_CRT2; |
| 4046 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4047 | DRM_DEBUG_KMS("CRT2 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4048 | bios_0_scratch &= ~ATOM_S0_CRT2_MASK; |
| 4049 | bios_3_scratch &= ~ATOM_S3_CRT2_ACTIVE; |
| 4050 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_CRT2; |
| 4051 | } |
| 4052 | } |
| 4053 | if ((radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) && |
| 4054 | (radeon_connector->devices & ATOM_DEVICE_DFP1_SUPPORT)) { |
| 4055 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4056 | DRM_DEBUG_KMS("DFP1 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4057 | bios_0_scratch |= ATOM_S0_DFP1; |
| 4058 | bios_3_scratch |= ATOM_S3_DFP1_ACTIVE; |
| 4059 | bios_6_scratch |= ATOM_S6_ACC_REQ_DFP1; |
| 4060 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4061 | DRM_DEBUG_KMS("DFP1 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4062 | bios_0_scratch &= ~ATOM_S0_DFP1; |
| 4063 | bios_3_scratch &= ~ATOM_S3_DFP1_ACTIVE; |
| 4064 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP1; |
| 4065 | } |
| 4066 | } |
| 4067 | if ((radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) && |
| 4068 | (radeon_connector->devices & ATOM_DEVICE_DFP2_SUPPORT)) { |
| 4069 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4070 | DRM_DEBUG_KMS("DFP2 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4071 | bios_0_scratch |= ATOM_S0_DFP2; |
| 4072 | bios_3_scratch |= ATOM_S3_DFP2_ACTIVE; |
| 4073 | bios_6_scratch |= ATOM_S6_ACC_REQ_DFP2; |
| 4074 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4075 | DRM_DEBUG_KMS("DFP2 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4076 | bios_0_scratch &= ~ATOM_S0_DFP2; |
| 4077 | bios_3_scratch &= ~ATOM_S3_DFP2_ACTIVE; |
| 4078 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP2; |
| 4079 | } |
| 4080 | } |
| 4081 | if ((radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) && |
| 4082 | (radeon_connector->devices & ATOM_DEVICE_DFP3_SUPPORT)) { |
| 4083 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4084 | DRM_DEBUG_KMS("DFP3 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4085 | bios_0_scratch |= ATOM_S0_DFP3; |
| 4086 | bios_3_scratch |= ATOM_S3_DFP3_ACTIVE; |
| 4087 | bios_6_scratch |= ATOM_S6_ACC_REQ_DFP3; |
| 4088 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4089 | DRM_DEBUG_KMS("DFP3 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4090 | bios_0_scratch &= ~ATOM_S0_DFP3; |
| 4091 | bios_3_scratch &= ~ATOM_S3_DFP3_ACTIVE; |
| 4092 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP3; |
| 4093 | } |
| 4094 | } |
| 4095 | if ((radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) && |
| 4096 | (radeon_connector->devices & ATOM_DEVICE_DFP4_SUPPORT)) { |
| 4097 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4098 | DRM_DEBUG_KMS("DFP4 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4099 | bios_0_scratch |= ATOM_S0_DFP4; |
| 4100 | bios_3_scratch |= ATOM_S3_DFP4_ACTIVE; |
| 4101 | bios_6_scratch |= ATOM_S6_ACC_REQ_DFP4; |
| 4102 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4103 | DRM_DEBUG_KMS("DFP4 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4104 | bios_0_scratch &= ~ATOM_S0_DFP4; |
| 4105 | bios_3_scratch &= ~ATOM_S3_DFP4_ACTIVE; |
| 4106 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP4; |
| 4107 | } |
| 4108 | } |
| 4109 | if ((radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) && |
| 4110 | (radeon_connector->devices & ATOM_DEVICE_DFP5_SUPPORT)) { |
| 4111 | if (connected) { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4112 | DRM_DEBUG_KMS("DFP5 connected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4113 | bios_0_scratch |= ATOM_S0_DFP5; |
| 4114 | bios_3_scratch |= ATOM_S3_DFP5_ACTIVE; |
| 4115 | bios_6_scratch |= ATOM_S6_ACC_REQ_DFP5; |
| 4116 | } else { |
Dave Airlie | d9fdaaf | 2010-08-02 10:42:55 +1000 | [diff] [blame] | 4117 | DRM_DEBUG_KMS("DFP5 disconnected\n"); |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4118 | bios_0_scratch &= ~ATOM_S0_DFP5; |
| 4119 | bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE; |
| 4120 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5; |
| 4121 | } |
| 4122 | } |
Alex Deucher | 6f9f8a6 | 2012-02-13 08:59:41 -0500 | [diff] [blame] | 4123 | if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) && |
| 4124 | (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) { |
| 4125 | if (connected) { |
| 4126 | DRM_DEBUG_KMS("DFP6 connected\n"); |
| 4127 | bios_0_scratch |= ATOM_S0_DFP6; |
| 4128 | bios_3_scratch |= ATOM_S3_DFP6_ACTIVE; |
| 4129 | bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6; |
| 4130 | } else { |
| 4131 | DRM_DEBUG_KMS("DFP6 disconnected\n"); |
| 4132 | bios_0_scratch &= ~ATOM_S0_DFP6; |
| 4133 | bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE; |
| 4134 | bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6; |
| 4135 | } |
| 4136 | } |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4137 | |
| 4138 | if (rdev->family >= CHIP_R600) { |
| 4139 | WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch); |
| 4140 | WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch); |
| 4141 | WREG32(R600_BIOS_6_SCRATCH, bios_6_scratch); |
| 4142 | } else { |
| 4143 | WREG32(RADEON_BIOS_0_SCRATCH, bios_0_scratch); |
| 4144 | WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch); |
| 4145 | WREG32(RADEON_BIOS_6_SCRATCH, bios_6_scratch); |
| 4146 | } |
| 4147 | } |
| 4148 | |
| 4149 | void |
| 4150 | radeon_atombios_encoder_crtc_scratch_regs(struct drm_encoder *encoder, int crtc) |
| 4151 | { |
| 4152 | struct drm_device *dev = encoder->dev; |
| 4153 | struct radeon_device *rdev = dev->dev_private; |
| 4154 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 4155 | uint32_t bios_3_scratch; |
| 4156 | |
Alex Deucher | 6f9f8a6 | 2012-02-13 08:59:41 -0500 | [diff] [blame] | 4157 | if (ASIC_IS_DCE4(rdev)) |
| 4158 | return; |
| 4159 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4160 | if (rdev->family >= CHIP_R600) |
| 4161 | bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH); |
| 4162 | else |
| 4163 | bios_3_scratch = RREG32(RADEON_BIOS_3_SCRATCH); |
| 4164 | |
| 4165 | if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) { |
| 4166 | bios_3_scratch &= ~ATOM_S3_TV1_CRTC_ACTIVE; |
| 4167 | bios_3_scratch |= (crtc << 18); |
| 4168 | } |
| 4169 | if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) { |
| 4170 | bios_3_scratch &= ~ATOM_S3_CV_CRTC_ACTIVE; |
| 4171 | bios_3_scratch |= (crtc << 24); |
| 4172 | } |
| 4173 | if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) { |
| 4174 | bios_3_scratch &= ~ATOM_S3_CRT1_CRTC_ACTIVE; |
| 4175 | bios_3_scratch |= (crtc << 16); |
| 4176 | } |
| 4177 | if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) { |
| 4178 | bios_3_scratch &= ~ATOM_S3_CRT2_CRTC_ACTIVE; |
| 4179 | bios_3_scratch |= (crtc << 20); |
| 4180 | } |
| 4181 | if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) { |
| 4182 | bios_3_scratch &= ~ATOM_S3_LCD1_CRTC_ACTIVE; |
| 4183 | bios_3_scratch |= (crtc << 17); |
| 4184 | } |
| 4185 | if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) { |
| 4186 | bios_3_scratch &= ~ATOM_S3_DFP1_CRTC_ACTIVE; |
| 4187 | bios_3_scratch |= (crtc << 19); |
| 4188 | } |
| 4189 | if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) { |
| 4190 | bios_3_scratch &= ~ATOM_S3_DFP2_CRTC_ACTIVE; |
| 4191 | bios_3_scratch |= (crtc << 23); |
| 4192 | } |
| 4193 | if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) { |
| 4194 | bios_3_scratch &= ~ATOM_S3_DFP3_CRTC_ACTIVE; |
| 4195 | bios_3_scratch |= (crtc << 25); |
| 4196 | } |
| 4197 | |
| 4198 | if (rdev->family >= CHIP_R600) |
| 4199 | WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch); |
| 4200 | else |
| 4201 | WREG32(RADEON_BIOS_3_SCRATCH, bios_3_scratch); |
| 4202 | } |
| 4203 | |
| 4204 | void |
| 4205 | radeon_atombios_encoder_dpms_scratch_regs(struct drm_encoder *encoder, bool on) |
| 4206 | { |
| 4207 | struct drm_device *dev = encoder->dev; |
| 4208 | struct radeon_device *rdev = dev->dev_private; |
| 4209 | struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); |
| 4210 | uint32_t bios_2_scratch; |
| 4211 | |
Alex Deucher | 3ac0eb6 | 2012-02-19 21:42:03 -0500 | [diff] [blame] | 4212 | if (ASIC_IS_DCE4(rdev)) |
| 4213 | return; |
| 4214 | |
Jerome Glisse | 771fe6b | 2009-06-05 14:42:42 +0200 | [diff] [blame] | 4215 | if (rdev->family >= CHIP_R600) |
| 4216 | bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH); |
| 4217 | else |
| 4218 | bios_2_scratch = RREG32(RADEON_BIOS_2_SCRATCH); |
| 4219 | |
| 4220 | if (radeon_encoder->devices & ATOM_DEVICE_TV1_SUPPORT) { |
| 4221 | if (on) |
| 4222 | bios_2_scratch &= ~ATOM_S2_TV1_DPMS_STATE; |
| 4223 | else |
| 4224 | bios_2_scratch |= ATOM_S2_TV1_DPMS_STATE; |
| 4225 | } |
| 4226 | if (radeon_encoder->devices & ATOM_DEVICE_CV_SUPPORT) { |
| 4227 | if (on) |
| 4228 | bios_2_scratch &= ~ATOM_S2_CV_DPMS_STATE; |
| 4229 | else |
| 4230 | bios_2_scratch |= ATOM_S2_CV_DPMS_STATE; |
| 4231 | } |
| 4232 | if (radeon_encoder->devices & ATOM_DEVICE_CRT1_SUPPORT) { |
| 4233 | if (on) |
| 4234 | bios_2_scratch &= ~ATOM_S2_CRT1_DPMS_STATE; |
| 4235 | else |
| 4236 | bios_2_scratch |= ATOM_S2_CRT1_DPMS_STATE; |
| 4237 | } |
| 4238 | if (radeon_encoder->devices & ATOM_DEVICE_CRT2_SUPPORT) { |
| 4239 | if (on) |
| 4240 | bios_2_scratch &= ~ATOM_S2_CRT2_DPMS_STATE; |
| 4241 | else |
| 4242 | bios_2_scratch |= ATOM_S2_CRT2_DPMS_STATE; |
| 4243 | } |
| 4244 | if (radeon_encoder->devices & ATOM_DEVICE_LCD1_SUPPORT) { |
| 4245 | if (on) |
| 4246 | bios_2_scratch &= ~ATOM_S2_LCD1_DPMS_STATE; |
| 4247 | else |
| 4248 | bios_2_scratch |= ATOM_S2_LCD1_DPMS_STATE; |
| 4249 | } |
| 4250 | if (radeon_encoder->devices & ATOM_DEVICE_DFP1_SUPPORT) { |
| 4251 | if (on) |
| 4252 | bios_2_scratch &= ~ATOM_S2_DFP1_DPMS_STATE; |
| 4253 | else |
| 4254 | bios_2_scratch |= ATOM_S2_DFP1_DPMS_STATE; |
| 4255 | } |
| 4256 | if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) { |
| 4257 | if (on) |
| 4258 | bios_2_scratch &= ~ATOM_S2_DFP2_DPMS_STATE; |
| 4259 | else |
| 4260 | bios_2_scratch |= ATOM_S2_DFP2_DPMS_STATE; |
| 4261 | } |
| 4262 | if (radeon_encoder->devices & ATOM_DEVICE_DFP3_SUPPORT) { |
| 4263 | if (on) |
| 4264 | bios_2_scratch &= ~ATOM_S2_DFP3_DPMS_STATE; |
| 4265 | else |
| 4266 | bios_2_scratch |= ATOM_S2_DFP3_DPMS_STATE; |
| 4267 | } |
| 4268 | if (radeon_encoder->devices & ATOM_DEVICE_DFP4_SUPPORT) { |
| 4269 | if (on) |
| 4270 | bios_2_scratch &= ~ATOM_S2_DFP4_DPMS_STATE; |
| 4271 | else |
| 4272 | bios_2_scratch |= ATOM_S2_DFP4_DPMS_STATE; |
| 4273 | } |
| 4274 | if (radeon_encoder->devices & ATOM_DEVICE_DFP5_SUPPORT) { |
| 4275 | if (on) |
| 4276 | bios_2_scratch &= ~ATOM_S2_DFP5_DPMS_STATE; |
| 4277 | else |
| 4278 | bios_2_scratch |= ATOM_S2_DFP5_DPMS_STATE; |
| 4279 | } |
| 4280 | |
| 4281 | if (rdev->family >= CHIP_R600) |
| 4282 | WREG32(R600_BIOS_2_SCRATCH, bios_2_scratch); |
| 4283 | else |
| 4284 | WREG32(RADEON_BIOS_2_SCRATCH, bios_2_scratch); |
| 4285 | } |