2 * Copyright 2007-8 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
23 * Authors: Dave Airlie
27 #include <drm/amdgpu_drm.h>
29 #include "amdgpu_atombios.h"
30 #include "amdgpu_i2c.h"
33 #include "atom-bits.h"
34 #include "atombios_encoders.h"
35 #include "bif/bif_4_1_d.h"
37 static void amdgpu_atombios_lookup_i2c_gpio_quirks(struct amdgpu_device *adev,
38 ATOM_GPIO_I2C_ASSIGMENT *gpio,
44 static struct amdgpu_i2c_bus_rec amdgpu_atombios_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
46 struct amdgpu_i2c_bus_rec i2c;
48 memset(&i2c, 0, sizeof(struct amdgpu_i2c_bus_rec));
50 i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex);
51 i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex);
52 i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex);
53 i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex);
54 i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex);
55 i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex);
56 i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex);
57 i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex);
58 i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
59 i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
60 i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
61 i2c.en_data_mask = (1 << gpio->ucDataEnShift);
62 i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
63 i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
64 i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
65 i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
67 if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
68 i2c.hw_capable = true;
70 i2c.hw_capable = false;
72 if (gpio->sucI2cId.ucAccess == 0xa0)
77 i2c.i2c_id = gpio->sucI2cId.ucAccess;
87 struct amdgpu_i2c_bus_rec amdgpu_atombios_lookup_i2c_gpio(struct amdgpu_device *adev,
90 struct atom_context *ctx = adev->mode_info.atom_context;
91 ATOM_GPIO_I2C_ASSIGMENT *gpio;
92 struct amdgpu_i2c_bus_rec i2c;
93 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
94 struct _ATOM_GPIO_I2C_INFO *i2c_info;
95 uint16_t data_offset, size;
98 memset(&i2c, 0, sizeof(struct amdgpu_i2c_bus_rec));
101 if (amdgpu_atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
102 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
104 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
105 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
107 gpio = &i2c_info->asGPIO_Info[0];
108 for (i = 0; i < num_indices; i++) {
110 amdgpu_atombios_lookup_i2c_gpio_quirks(adev, gpio, i);
112 if (gpio->sucI2cId.ucAccess == id) {
113 i2c = amdgpu_atombios_get_bus_rec_for_i2c_gpio(gpio);
116 gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
117 ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
124 void amdgpu_atombios_i2c_init(struct amdgpu_device *adev)
126 struct atom_context *ctx = adev->mode_info.atom_context;
127 ATOM_GPIO_I2C_ASSIGMENT *gpio;
128 struct amdgpu_i2c_bus_rec i2c;
129 int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
130 struct _ATOM_GPIO_I2C_INFO *i2c_info;
131 uint16_t data_offset, size;
135 if (amdgpu_atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
136 i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
138 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
139 sizeof(ATOM_GPIO_I2C_ASSIGMENT);
141 gpio = &i2c_info->asGPIO_Info[0];
142 for (i = 0; i < num_indices; i++) {
143 amdgpu_atombios_lookup_i2c_gpio_quirks(adev, gpio, i);
145 i2c = amdgpu_atombios_get_bus_rec_for_i2c_gpio(gpio);
148 sprintf(stmp, "0x%x", i2c.i2c_id);
149 adev->i2c_bus[i] = amdgpu_i2c_create(adev->ddev, &i2c, stmp);
151 gpio = (ATOM_GPIO_I2C_ASSIGMENT *)
152 ((u8 *)gpio + sizeof(ATOM_GPIO_I2C_ASSIGMENT));
157 struct amdgpu_gpio_rec
158 amdgpu_atombios_lookup_gpio(struct amdgpu_device *adev,
161 struct atom_context *ctx = adev->mode_info.atom_context;
162 struct amdgpu_gpio_rec gpio;
163 int index = GetIndexIntoMasterTable(DATA, GPIO_Pin_LUT);
164 struct _ATOM_GPIO_PIN_LUT *gpio_info;
165 ATOM_GPIO_PIN_ASSIGNMENT *pin;
166 u16 data_offset, size;
169 memset(&gpio, 0, sizeof(struct amdgpu_gpio_rec));
172 if (amdgpu_atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
173 gpio_info = (struct _ATOM_GPIO_PIN_LUT *)(ctx->bios + data_offset);
175 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
176 sizeof(ATOM_GPIO_PIN_ASSIGNMENT);
178 pin = gpio_info->asGPIO_Pin;
179 for (i = 0; i < num_indices; i++) {
180 if (id == pin->ucGPIO_ID) {
181 gpio.id = pin->ucGPIO_ID;
182 gpio.reg = le16_to_cpu(pin->usGpioPin_AIndex);
183 gpio.shift = pin->ucGpioPinBitShift;
184 gpio.mask = (1 << pin->ucGpioPinBitShift);
188 pin = (ATOM_GPIO_PIN_ASSIGNMENT *)
189 ((u8 *)pin + sizeof(ATOM_GPIO_PIN_ASSIGNMENT));
196 static struct amdgpu_hpd
197 amdgpu_atombios_get_hpd_info_from_gpio(struct amdgpu_device *adev,
198 struct amdgpu_gpio_rec *gpio)
200 struct amdgpu_hpd hpd;
203 memset(&hpd, 0, sizeof(struct amdgpu_hpd));
205 reg = amdgpu_display_hpd_get_gpio_reg(adev);
208 if (gpio->reg == reg) {
211 hpd.hpd = AMDGPU_HPD_1;
214 hpd.hpd = AMDGPU_HPD_2;
217 hpd.hpd = AMDGPU_HPD_3;
220 hpd.hpd = AMDGPU_HPD_4;
223 hpd.hpd = AMDGPU_HPD_5;
226 hpd.hpd = AMDGPU_HPD_6;
229 hpd.hpd = AMDGPU_HPD_NONE;
233 hpd.hpd = AMDGPU_HPD_NONE;
237 static const int object_connector_convert[] = {
238 DRM_MODE_CONNECTOR_Unknown,
239 DRM_MODE_CONNECTOR_DVII,
240 DRM_MODE_CONNECTOR_DVII,
241 DRM_MODE_CONNECTOR_DVID,
242 DRM_MODE_CONNECTOR_DVID,
243 DRM_MODE_CONNECTOR_VGA,
244 DRM_MODE_CONNECTOR_Composite,
245 DRM_MODE_CONNECTOR_SVIDEO,
246 DRM_MODE_CONNECTOR_Unknown,
247 DRM_MODE_CONNECTOR_Unknown,
248 DRM_MODE_CONNECTOR_9PinDIN,
249 DRM_MODE_CONNECTOR_Unknown,
250 DRM_MODE_CONNECTOR_HDMIA,
251 DRM_MODE_CONNECTOR_HDMIB,
252 DRM_MODE_CONNECTOR_LVDS,
253 DRM_MODE_CONNECTOR_9PinDIN,
254 DRM_MODE_CONNECTOR_Unknown,
255 DRM_MODE_CONNECTOR_Unknown,
256 DRM_MODE_CONNECTOR_Unknown,
257 DRM_MODE_CONNECTOR_DisplayPort,
258 DRM_MODE_CONNECTOR_eDP,
259 DRM_MODE_CONNECTOR_Unknown
262 bool amdgpu_atombios_has_dce_engine_info(struct amdgpu_device *adev)
264 struct amdgpu_mode_info *mode_info = &adev->mode_info;
265 struct atom_context *ctx = mode_info->atom_context;
266 int index = GetIndexIntoMasterTable(DATA, Object_Header);
267 u16 size, data_offset;
269 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
270 ATOM_OBJECT_HEADER *obj_header;
272 if (!amdgpu_atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
278 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
279 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
280 (ctx->bios + data_offset +
281 le16_to_cpu(obj_header->usDisplayPathTableOffset));
283 if (path_obj->ucNumOfDispPath)
289 bool amdgpu_atombios_get_connector_info_from_object_table(struct amdgpu_device *adev)
291 struct amdgpu_mode_info *mode_info = &adev->mode_info;
292 struct atom_context *ctx = mode_info->atom_context;
293 int index = GetIndexIntoMasterTable(DATA, Object_Header);
294 u16 size, data_offset;
296 ATOM_CONNECTOR_OBJECT_TABLE *con_obj;
297 ATOM_ENCODER_OBJECT_TABLE *enc_obj;
298 ATOM_OBJECT_TABLE *router_obj;
299 ATOM_DISPLAY_OBJECT_PATH_TABLE *path_obj;
300 ATOM_OBJECT_HEADER *obj_header;
301 int i, j, k, path_size, device_support;
303 u16 conn_id, connector_object_id;
304 struct amdgpu_i2c_bus_rec ddc_bus;
305 struct amdgpu_router router;
306 struct amdgpu_gpio_rec gpio;
307 struct amdgpu_hpd hpd;
309 if (!amdgpu_atom_parse_data_header(ctx, index, &size, &frev, &crev, &data_offset))
315 obj_header = (ATOM_OBJECT_HEADER *) (ctx->bios + data_offset);
316 path_obj = (ATOM_DISPLAY_OBJECT_PATH_TABLE *)
317 (ctx->bios + data_offset +
318 le16_to_cpu(obj_header->usDisplayPathTableOffset));
319 con_obj = (ATOM_CONNECTOR_OBJECT_TABLE *)
320 (ctx->bios + data_offset +
321 le16_to_cpu(obj_header->usConnectorObjectTableOffset));
322 enc_obj = (ATOM_ENCODER_OBJECT_TABLE *)
323 (ctx->bios + data_offset +
324 le16_to_cpu(obj_header->usEncoderObjectTableOffset));
325 router_obj = (ATOM_OBJECT_TABLE *)
326 (ctx->bios + data_offset +
327 le16_to_cpu(obj_header->usRouterObjectTableOffset));
328 device_support = le16_to_cpu(obj_header->usDeviceSupport);
331 for (i = 0; i < path_obj->ucNumOfDispPath; i++) {
332 uint8_t *addr = (uint8_t *) path_obj->asDispPath;
333 ATOM_DISPLAY_OBJECT_PATH *path;
335 path = (ATOM_DISPLAY_OBJECT_PATH *) addr;
336 path_size += le16_to_cpu(path->usSize);
338 if (device_support & le16_to_cpu(path->usDeviceTag)) {
340 (le16_to_cpu(path->usConnObjectId) & OBJECT_ID_MASK)
343 /* Skip TV/CV support */
344 if ((le16_to_cpu(path->usDeviceTag) ==
345 ATOM_DEVICE_TV1_SUPPORT) ||
346 (le16_to_cpu(path->usDeviceTag) ==
347 ATOM_DEVICE_CV_SUPPORT))
350 if (con_obj_id >= ARRAY_SIZE(object_connector_convert)) {
351 DRM_ERROR("invalid con_obj_id %d for device tag 0x%04x\n",
352 con_obj_id, le16_to_cpu(path->usDeviceTag));
357 object_connector_convert[con_obj_id];
358 connector_object_id = con_obj_id;
360 if (connector_type == DRM_MODE_CONNECTOR_Unknown)
363 router.ddc_valid = false;
364 router.cd_valid = false;
365 for (j = 0; j < ((le16_to_cpu(path->usSize) - 8) / 2); j++) {
366 uint8_t grph_obj_type =
367 (le16_to_cpu(path->usGraphicObjIds[j]) &
368 OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
370 if (grph_obj_type == GRAPH_OBJECT_TYPE_ENCODER) {
371 for (k = 0; k < enc_obj->ucNumberOfObjects; k++) {
372 u16 encoder_obj = le16_to_cpu(enc_obj->asObjects[k].usObjectID);
373 if (le16_to_cpu(path->usGraphicObjIds[j]) == encoder_obj) {
374 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
375 (ctx->bios + data_offset +
376 le16_to_cpu(enc_obj->asObjects[k].usRecordOffset));
377 ATOM_ENCODER_CAP_RECORD *cap_record;
380 while (record->ucRecordSize > 0 &&
381 record->ucRecordType > 0 &&
382 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
383 switch (record->ucRecordType) {
384 case ATOM_ENCODER_CAP_RECORD_TYPE:
385 cap_record =(ATOM_ENCODER_CAP_RECORD *)
387 caps = le16_to_cpu(cap_record->usEncoderCap);
390 record = (ATOM_COMMON_RECORD_HEADER *)
391 ((char *)record + record->ucRecordSize);
393 amdgpu_display_add_encoder(adev, encoder_obj,
394 le16_to_cpu(path->usDeviceTag),
398 } else if (grph_obj_type == GRAPH_OBJECT_TYPE_ROUTER) {
399 for (k = 0; k < router_obj->ucNumberOfObjects; k++) {
400 u16 router_obj_id = le16_to_cpu(router_obj->asObjects[k].usObjectID);
401 if (le16_to_cpu(path->usGraphicObjIds[j]) == router_obj_id) {
402 ATOM_COMMON_RECORD_HEADER *record = (ATOM_COMMON_RECORD_HEADER *)
403 (ctx->bios + data_offset +
404 le16_to_cpu(router_obj->asObjects[k].usRecordOffset));
405 ATOM_I2C_RECORD *i2c_record;
406 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
407 ATOM_ROUTER_DDC_PATH_SELECT_RECORD *ddc_path;
408 ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *cd_path;
409 ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *router_src_dst_table =
410 (ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT *)
411 (ctx->bios + data_offset +
412 le16_to_cpu(router_obj->asObjects[k].usSrcDstTableOffset));
413 u8 *num_dst_objs = (u8 *)
414 ((u8 *)router_src_dst_table + 1 +
415 (router_src_dst_table->ucNumberOfSrc * 2));
416 u16 *dst_objs = (u16 *)(num_dst_objs + 1);
419 router.router_id = router_obj_id;
420 for (enum_id = 0; enum_id < (*num_dst_objs); enum_id++) {
421 if (le16_to_cpu(path->usConnObjectId) ==
422 le16_to_cpu(dst_objs[enum_id]))
426 while (record->ucRecordSize > 0 &&
427 record->ucRecordType > 0 &&
428 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
429 switch (record->ucRecordType) {
430 case ATOM_I2C_RECORD_TYPE:
435 (ATOM_I2C_ID_CONFIG_ACCESS *)
436 &i2c_record->sucI2cId;
438 amdgpu_atombios_lookup_i2c_gpio(adev,
441 router.i2c_addr = i2c_record->ucI2CAddr >> 1;
443 case ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE:
444 ddc_path = (ATOM_ROUTER_DDC_PATH_SELECT_RECORD *)
446 router.ddc_valid = true;
447 router.ddc_mux_type = ddc_path->ucMuxType;
448 router.ddc_mux_control_pin = ddc_path->ucMuxControlPin;
449 router.ddc_mux_state = ddc_path->ucMuxState[enum_id];
451 case ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE:
452 cd_path = (ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD *)
454 router.cd_valid = true;
455 router.cd_mux_type = cd_path->ucMuxType;
456 router.cd_mux_control_pin = cd_path->ucMuxControlPin;
457 router.cd_mux_state = cd_path->ucMuxState[enum_id];
460 record = (ATOM_COMMON_RECORD_HEADER *)
461 ((char *)record + record->ucRecordSize);
468 /* look up gpio for ddc, hpd */
469 ddc_bus.valid = false;
470 hpd.hpd = AMDGPU_HPD_NONE;
471 if ((le16_to_cpu(path->usDeviceTag) &
472 (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT)) == 0) {
473 for (j = 0; j < con_obj->ucNumberOfObjects; j++) {
474 if (le16_to_cpu(path->usConnObjectId) ==
475 le16_to_cpu(con_obj->asObjects[j].
477 ATOM_COMMON_RECORD_HEADER
479 (ATOM_COMMON_RECORD_HEADER
481 (ctx->bios + data_offset +
482 le16_to_cpu(con_obj->
485 ATOM_I2C_RECORD *i2c_record;
486 ATOM_HPD_INT_RECORD *hpd_record;
487 ATOM_I2C_ID_CONFIG_ACCESS *i2c_config;
489 while (record->ucRecordSize > 0 &&
490 record->ucRecordType > 0 &&
491 record->ucRecordType <= ATOM_MAX_OBJECT_RECORD_NUMBER) {
492 switch (record->ucRecordType) {
493 case ATOM_I2C_RECORD_TYPE:
498 (ATOM_I2C_ID_CONFIG_ACCESS *)
499 &i2c_record->sucI2cId;
500 ddc_bus = amdgpu_atombios_lookup_i2c_gpio(adev,
504 case ATOM_HPD_INT_RECORD_TYPE:
506 (ATOM_HPD_INT_RECORD *)
508 gpio = amdgpu_atombios_lookup_gpio(adev,
509 hpd_record->ucHPDIntGPIOID);
510 hpd = amdgpu_atombios_get_hpd_info_from_gpio(adev, &gpio);
511 hpd.plugged_state = hpd_record->ucPlugged_PinState;
515 (ATOM_COMMON_RECORD_HEADER
526 /* needed for aux chan transactions */
527 ddc_bus.hpd = hpd.hpd;
529 conn_id = le16_to_cpu(path->usConnObjectId);
531 amdgpu_display_add_connector(adev,
533 le16_to_cpu(path->usDeviceTag),
534 connector_type, &ddc_bus,
542 amdgpu_link_encoder_connector(adev->ddev);
547 union firmware_info {
548 ATOM_FIRMWARE_INFO info;
549 ATOM_FIRMWARE_INFO_V1_2 info_12;
550 ATOM_FIRMWARE_INFO_V1_3 info_13;
551 ATOM_FIRMWARE_INFO_V1_4 info_14;
552 ATOM_FIRMWARE_INFO_V2_1 info_21;
553 ATOM_FIRMWARE_INFO_V2_2 info_22;
556 int amdgpu_atombios_get_clock_info(struct amdgpu_device *adev)
558 struct amdgpu_mode_info *mode_info = &adev->mode_info;
559 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
561 uint16_t data_offset;
564 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
565 &frev, &crev, &data_offset)) {
567 struct amdgpu_pll *ppll = &adev->clock.ppll[0];
568 struct amdgpu_pll *spll = &adev->clock.spll;
569 struct amdgpu_pll *mpll = &adev->clock.mpll;
570 union firmware_info *firmware_info =
571 (union firmware_info *)(mode_info->atom_context->bios +
574 ppll->reference_freq =
575 le16_to_cpu(firmware_info->info.usReferenceClock);
576 ppll->reference_div = 0;
579 le32_to_cpu(firmware_info->info_12.ulMinPixelClockPLL_Output);
581 le32_to_cpu(firmware_info->info.ulMaxPixelClockPLL_Output);
583 ppll->lcd_pll_out_min =
584 le16_to_cpu(firmware_info->info_14.usLcdMinPixelClockPLL_Output) * 100;
585 if (ppll->lcd_pll_out_min == 0)
586 ppll->lcd_pll_out_min = ppll->pll_out_min;
587 ppll->lcd_pll_out_max =
588 le16_to_cpu(firmware_info->info_14.usLcdMaxPixelClockPLL_Output) * 100;
589 if (ppll->lcd_pll_out_max == 0)
590 ppll->lcd_pll_out_max = ppll->pll_out_max;
592 if (ppll->pll_out_min == 0)
593 ppll->pll_out_min = 64800;
596 le16_to_cpu(firmware_info->info.usMinPixelClockPLL_Input);
598 le16_to_cpu(firmware_info->info.usMaxPixelClockPLL_Input);
600 ppll->min_post_div = 2;
601 ppll->max_post_div = 0x7f;
602 ppll->min_frac_feedback_div = 0;
603 ppll->max_frac_feedback_div = 9;
604 ppll->min_ref_div = 2;
605 ppll->max_ref_div = 0x3ff;
606 ppll->min_feedback_div = 4;
607 ppll->max_feedback_div = 0xfff;
610 for (i = 1; i < AMDGPU_MAX_PPLL; i++)
611 adev->clock.ppll[i] = *ppll;
614 spll->reference_freq =
615 le16_to_cpu(firmware_info->info_21.usCoreReferenceClock);
616 spll->reference_div = 0;
619 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Output);
621 le32_to_cpu(firmware_info->info.ulMaxEngineClockPLL_Output);
624 if (spll->pll_out_min == 0)
625 spll->pll_out_min = 64800;
628 le16_to_cpu(firmware_info->info.usMinEngineClockPLL_Input);
630 le16_to_cpu(firmware_info->info.usMaxEngineClockPLL_Input);
632 spll->min_post_div = 1;
633 spll->max_post_div = 1;
634 spll->min_ref_div = 2;
635 spll->max_ref_div = 0xff;
636 spll->min_feedback_div = 4;
637 spll->max_feedback_div = 0xff;
641 mpll->reference_freq =
642 le16_to_cpu(firmware_info->info_21.usMemoryReferenceClock);
643 mpll->reference_div = 0;
646 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Output);
648 le32_to_cpu(firmware_info->info.ulMaxMemoryClockPLL_Output);
651 if (mpll->pll_out_min == 0)
652 mpll->pll_out_min = 64800;
655 le16_to_cpu(firmware_info->info.usMinMemoryClockPLL_Input);
657 le16_to_cpu(firmware_info->info.usMaxMemoryClockPLL_Input);
659 adev->clock.default_sclk =
660 le32_to_cpu(firmware_info->info.ulDefaultEngineClock);
661 adev->clock.default_mclk =
662 le32_to_cpu(firmware_info->info.ulDefaultMemoryClock);
664 mpll->min_post_div = 1;
665 mpll->max_post_div = 1;
666 mpll->min_ref_div = 2;
667 mpll->max_ref_div = 0xff;
668 mpll->min_feedback_div = 4;
669 mpll->max_feedback_div = 0xff;
673 adev->clock.default_dispclk =
674 le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq);
675 /* set a reasonable default for DP */
676 if (adev->clock.default_dispclk < 53900) {
677 DRM_INFO("Changing default dispclk from %dMhz to 600Mhz\n",
678 adev->clock.default_dispclk / 100);
679 adev->clock.default_dispclk = 60000;
680 } else if (adev->clock.default_dispclk <= 60000) {
681 DRM_INFO("Changing default dispclk from %dMhz to 625Mhz\n",
682 adev->clock.default_dispclk / 100);
683 adev->clock.default_dispclk = 62500;
685 adev->clock.dp_extclk =
686 le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq);
687 adev->clock.current_dispclk = adev->clock.default_dispclk;
689 adev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
690 if (adev->clock.max_pixel_clock == 0)
691 adev->clock.max_pixel_clock = 40000;
693 /* not technically a clock, but... */
694 adev->mode_info.firmware_flags =
695 le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess);
700 adev->pm.current_sclk = adev->clock.default_sclk;
701 adev->pm.current_mclk = adev->clock.default_mclk;
707 ATOM_GFX_INFO_V2_1 info;
710 int amdgpu_atombios_get_gfx_info(struct amdgpu_device *adev)
712 struct amdgpu_mode_info *mode_info = &adev->mode_info;
713 int index = GetIndexIntoMasterTable(DATA, GFX_Info);
715 uint16_t data_offset;
718 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
719 &frev, &crev, &data_offset)) {
720 union gfx_info *gfx_info = (union gfx_info *)
721 (mode_info->atom_context->bios + data_offset);
723 adev->gfx.config.max_shader_engines = gfx_info->info.max_shader_engines;
724 adev->gfx.config.max_tile_pipes = gfx_info->info.max_tile_pipes;
725 adev->gfx.config.max_cu_per_sh = gfx_info->info.max_cu_per_sh;
726 adev->gfx.config.max_sh_per_se = gfx_info->info.max_sh_per_se;
727 adev->gfx.config.max_backends_per_se = gfx_info->info.max_backends_per_se;
728 adev->gfx.config.max_texture_channel_caches =
729 gfx_info->info.max_texture_channel_caches;
737 struct _ATOM_INTEGRATED_SYSTEM_INFO info;
738 struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
739 struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
740 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
741 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
742 struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_9 info_9;
746 * Return vram width from integrated system info table, if available,
749 int amdgpu_atombios_get_vram_width(struct amdgpu_device *adev)
751 struct amdgpu_mode_info *mode_info = &adev->mode_info;
752 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
753 u16 data_offset, size;
754 union igp_info *igp_info;
757 /* get any igp specific overrides */
758 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, &size,
759 &frev, &crev, &data_offset)) {
760 igp_info = (union igp_info *)
761 (mode_info->atom_context->bios + data_offset);
765 return igp_info->info_8.ucUMAChannelNumber * 64;
774 static void amdgpu_atombios_get_igp_ss_overrides(struct amdgpu_device *adev,
775 struct amdgpu_atom_ss *ss,
778 struct amdgpu_mode_info *mode_info = &adev->mode_info;
779 int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
780 u16 data_offset, size;
781 union igp_info *igp_info;
783 u16 percentage = 0, rate = 0;
785 /* get any igp specific overrides */
786 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, &size,
787 &frev, &crev, &data_offset)) {
788 igp_info = (union igp_info *)
789 (mode_info->atom_context->bios + data_offset);
793 case ASIC_INTERNAL_SS_ON_TMDS:
794 percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage);
795 rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz);
797 case ASIC_INTERNAL_SS_ON_HDMI:
798 percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage);
799 rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz);
801 case ASIC_INTERNAL_SS_ON_LVDS:
802 percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage);
803 rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz);
809 case ASIC_INTERNAL_SS_ON_TMDS:
810 percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage);
811 rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz);
813 case ASIC_INTERNAL_SS_ON_HDMI:
814 percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage);
815 rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz);
817 case ASIC_INTERNAL_SS_ON_LVDS:
818 percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage);
819 rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz);
825 case ASIC_INTERNAL_SS_ON_TMDS:
826 percentage = le16_to_cpu(igp_info->info_8.usDVISSPercentage);
827 rate = le16_to_cpu(igp_info->info_8.usDVISSpreadRateIn10Hz);
829 case ASIC_INTERNAL_SS_ON_HDMI:
830 percentage = le16_to_cpu(igp_info->info_8.usHDMISSPercentage);
831 rate = le16_to_cpu(igp_info->info_8.usHDMISSpreadRateIn10Hz);
833 case ASIC_INTERNAL_SS_ON_LVDS:
834 percentage = le16_to_cpu(igp_info->info_8.usLvdsSSPercentage);
835 rate = le16_to_cpu(igp_info->info_8.usLvdsSSpreadRateIn10Hz);
841 case ASIC_INTERNAL_SS_ON_TMDS:
842 percentage = le16_to_cpu(igp_info->info_9.usDVISSPercentage);
843 rate = le16_to_cpu(igp_info->info_9.usDVISSpreadRateIn10Hz);
845 case ASIC_INTERNAL_SS_ON_HDMI:
846 percentage = le16_to_cpu(igp_info->info_9.usHDMISSPercentage);
847 rate = le16_to_cpu(igp_info->info_9.usHDMISSpreadRateIn10Hz);
849 case ASIC_INTERNAL_SS_ON_LVDS:
850 percentage = le16_to_cpu(igp_info->info_9.usLvdsSSPercentage);
851 rate = le16_to_cpu(igp_info->info_9.usLvdsSSpreadRateIn10Hz);
856 DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
860 ss->percentage = percentage;
867 struct _ATOM_ASIC_INTERNAL_SS_INFO info;
868 struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 info_2;
869 struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 info_3;
872 union asic_ss_assignment {
873 struct _ATOM_ASIC_SS_ASSIGNMENT v1;
874 struct _ATOM_ASIC_SS_ASSIGNMENT_V2 v2;
875 struct _ATOM_ASIC_SS_ASSIGNMENT_V3 v3;
878 bool amdgpu_atombios_get_asic_ss_info(struct amdgpu_device *adev,
879 struct amdgpu_atom_ss *ss,
882 struct amdgpu_mode_info *mode_info = &adev->mode_info;
883 int index = GetIndexIntoMasterTable(DATA, ASIC_InternalSS_Info);
884 uint16_t data_offset, size;
885 union asic_ss_info *ss_info;
886 union asic_ss_assignment *ss_assign;
890 if (id == ASIC_INTERNAL_MEMORY_SS) {
891 if (!(adev->mode_info.firmware_flags & ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT))
894 if (id == ASIC_INTERNAL_ENGINE_SS) {
895 if (!(adev->mode_info.firmware_flags & ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT))
899 memset(ss, 0, sizeof(struct amdgpu_atom_ss));
900 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, &size,
901 &frev, &crev, &data_offset)) {
904 (union asic_ss_info *)(mode_info->atom_context->bios + data_offset);
908 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
909 sizeof(ATOM_ASIC_SS_ASSIGNMENT);
911 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info.asSpreadSpectrum[0]);
912 for (i = 0; i < num_indices; i++) {
913 if ((ss_assign->v1.ucClockIndication == id) &&
914 (clock <= le32_to_cpu(ss_assign->v1.ulTargetClockRange))) {
916 le16_to_cpu(ss_assign->v1.usSpreadSpectrumPercentage);
917 ss->type = ss_assign->v1.ucSpreadSpectrumMode;
918 ss->rate = le16_to_cpu(ss_assign->v1.usSpreadRateInKhz);
919 ss->percentage_divider = 100;
922 ss_assign = (union asic_ss_assignment *)
923 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT));
927 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
928 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2);
929 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_2.asSpreadSpectrum[0]);
930 for (i = 0; i < num_indices; i++) {
931 if ((ss_assign->v2.ucClockIndication == id) &&
932 (clock <= le32_to_cpu(ss_assign->v2.ulTargetClockRange))) {
934 le16_to_cpu(ss_assign->v2.usSpreadSpectrumPercentage);
935 ss->type = ss_assign->v2.ucSpreadSpectrumMode;
936 ss->rate = le16_to_cpu(ss_assign->v2.usSpreadRateIn10Hz);
937 ss->percentage_divider = 100;
939 ((id == ASIC_INTERNAL_ENGINE_SS) ||
940 (id == ASIC_INTERNAL_MEMORY_SS)))
944 ss_assign = (union asic_ss_assignment *)
945 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V2));
949 num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
950 sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3);
951 ss_assign = (union asic_ss_assignment *)((u8 *)&ss_info->info_3.asSpreadSpectrum[0]);
952 for (i = 0; i < num_indices; i++) {
953 if ((ss_assign->v3.ucClockIndication == id) &&
954 (clock <= le32_to_cpu(ss_assign->v3.ulTargetClockRange))) {
956 le16_to_cpu(ss_assign->v3.usSpreadSpectrumPercentage);
957 ss->type = ss_assign->v3.ucSpreadSpectrumMode;
958 ss->rate = le16_to_cpu(ss_assign->v3.usSpreadRateIn10Hz);
959 if (ss_assign->v3.ucSpreadSpectrumMode &
960 SS_MODE_V3_PERCENTAGE_DIV_BY_1000_MASK)
961 ss->percentage_divider = 1000;
963 ss->percentage_divider = 100;
964 if ((id == ASIC_INTERNAL_ENGINE_SS) ||
965 (id == ASIC_INTERNAL_MEMORY_SS))
967 if (adev->flags & AMD_IS_APU)
968 amdgpu_atombios_get_igp_ss_overrides(adev, ss, id);
971 ss_assign = (union asic_ss_assignment *)
972 ((u8 *)ss_assign + sizeof(ATOM_ASIC_SS_ASSIGNMENT_V3));
976 DRM_ERROR("Unsupported ASIC_InternalSS_Info table: %d %d\n", frev, crev);
984 union get_clock_dividers {
985 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS v1;
986 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 v2;
987 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 v3;
988 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 v4;
989 struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V5 v5;
990 struct _COMPUTE_GPU_CLOCK_INPUT_PARAMETERS_V1_6 v6_in;
991 struct _COMPUTE_GPU_CLOCK_OUTPUT_PARAMETERS_V1_6 v6_out;
994 int amdgpu_atombios_get_clock_dividers(struct amdgpu_device *adev,
998 struct atom_clock_dividers *dividers)
1000 union get_clock_dividers args;
1001 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryEnginePLL);
1004 memset(&args, 0, sizeof(args));
1005 memset(dividers, 0, sizeof(struct atom_clock_dividers));
1007 if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
1014 /* r6xx, r7xx, evergreen, ni, si.
1015 * TODO: add support for asic_type <= CHIP_RV770*/
1016 if (clock_type == COMPUTE_ENGINE_PLL_PARAM) {
1017 args.v3.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
1019 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1021 dividers->post_div = args.v3.ucPostDiv;
1022 dividers->enable_post_div = (args.v3.ucCntlFlag &
1023 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
1024 dividers->enable_dithen = (args.v3.ucCntlFlag &
1025 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
1026 dividers->whole_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDiv);
1027 dividers->frac_fb_div = le16_to_cpu(args.v3.ulFbDiv.usFbDivFrac);
1028 dividers->ref_div = args.v3.ucRefDiv;
1029 dividers->vco_mode = (args.v3.ucCntlFlag &
1030 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
1032 /* for SI we use ComputeMemoryClockParam for memory plls */
1033 if (adev->asic_type >= CHIP_TAHITI)
1035 args.v5.ulClockParams = cpu_to_le32((clock_type << 24) | clock);
1037 args.v5.ucInputFlag = ATOM_PLL_INPUT_FLAG_PLL_STROBE_MODE_EN;
1039 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1041 dividers->post_div = args.v5.ucPostDiv;
1042 dividers->enable_post_div = (args.v5.ucCntlFlag &
1043 ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN) ? true : false;
1044 dividers->enable_dithen = (args.v5.ucCntlFlag &
1045 ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE) ? false : true;
1046 dividers->whole_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDiv);
1047 dividers->frac_fb_div = le16_to_cpu(args.v5.ulFbDiv.usFbDivFrac);
1048 dividers->ref_div = args.v5.ucRefDiv;
1049 dividers->vco_mode = (args.v5.ucCntlFlag &
1050 ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE) ? 1 : 0;
1055 args.v4.ulClock = cpu_to_le32(clock); /* 10 khz */
1057 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1059 dividers->post_divider = dividers->post_div = args.v4.ucPostDiv;
1060 dividers->real_clock = le32_to_cpu(args.v4.ulClock);
1064 /* COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK, COMPUTE_GPUCLK_INPUT_FLAG_SCLK */
1065 args.v6_in.ulClock.ulComputeClockFlag = clock_type;
1066 args.v6_in.ulClock.ulClockFreq = cpu_to_le32(clock); /* 10 khz */
1068 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1070 dividers->whole_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDiv);
1071 dividers->frac_fb_div = le16_to_cpu(args.v6_out.ulFbDiv.usFbDivFrac);
1072 dividers->ref_div = args.v6_out.ucPllRefDiv;
1073 dividers->post_div = args.v6_out.ucPllPostDiv;
1074 dividers->flags = args.v6_out.ucPllCntlFlag;
1075 dividers->real_clock = le32_to_cpu(args.v6_out.ulClock.ulClock);
1076 dividers->post_divider = args.v6_out.ulClock.ucPostDiv;
1084 int amdgpu_atombios_get_memory_pll_dividers(struct amdgpu_device *adev,
1087 struct atom_mpll_param *mpll_param)
1089 COMPUTE_MEMORY_CLOCK_PARAM_PARAMETERS_V2_1 args;
1090 int index = GetIndexIntoMasterTable(COMMAND, ComputeMemoryClockParam);
1093 memset(&args, 0, sizeof(args));
1094 memset(mpll_param, 0, sizeof(struct atom_mpll_param));
1096 if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
1104 args.ulClock = cpu_to_le32(clock); /* 10 khz */
1105 args.ucInputFlag = 0;
1107 args.ucInputFlag |= MPLL_INPUT_FLAG_STROBE_MODE_EN;
1109 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1111 mpll_param->clkfrac = le16_to_cpu(args.ulFbDiv.usFbDivFrac);
1112 mpll_param->clkf = le16_to_cpu(args.ulFbDiv.usFbDiv);
1113 mpll_param->post_div = args.ucPostDiv;
1114 mpll_param->dll_speed = args.ucDllSpeed;
1115 mpll_param->bwcntl = args.ucBWCntl;
1116 mpll_param->vco_mode =
1117 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_VCO_MODE_MASK);
1118 mpll_param->yclk_sel =
1119 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_BYPASS_DQ_PLL) ? 1 : 0;
1121 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_QDR_ENABLE) ? 1 : 0;
1122 mpll_param->half_rate =
1123 (args.ucPllCntlFlag & MPLL_CNTL_FLAG_AD_HALF_RATE) ? 1 : 0;
1135 void amdgpu_atombios_set_engine_dram_timings(struct amdgpu_device *adev,
1136 u32 eng_clock, u32 mem_clock)
1138 SET_ENGINE_CLOCK_PS_ALLOCATION args;
1139 int index = GetIndexIntoMasterTable(COMMAND, DynamicMemorySettings);
1142 memset(&args, 0, sizeof(args));
1144 tmp = eng_clock & SET_CLOCK_FREQ_MASK;
1145 tmp |= (COMPUTE_ENGINE_PLL_PARAM << 24);
1147 args.ulTargetEngineClock = cpu_to_le32(tmp);
1149 args.sReserved.ulClock = cpu_to_le32(mem_clock & SET_CLOCK_FREQ_MASK);
1151 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1154 void amdgpu_atombios_get_default_voltages(struct amdgpu_device *adev,
1155 u16 *vddc, u16 *vddci, u16 *mvdd)
1157 struct amdgpu_mode_info *mode_info = &adev->mode_info;
1158 int index = GetIndexIntoMasterTable(DATA, FirmwareInfo);
1161 union firmware_info *firmware_info;
1167 if (amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
1168 &frev, &crev, &data_offset)) {
1170 (union firmware_info *)(mode_info->atom_context->bios +
1172 *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage);
1173 if ((frev == 2) && (crev >= 2)) {
1174 *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage);
1175 *mvdd = le16_to_cpu(firmware_info->info_22.usBootUpMVDDCVoltage);
1181 struct _SET_VOLTAGE_PS_ALLOCATION alloc;
1182 struct _SET_VOLTAGE_PARAMETERS v1;
1183 struct _SET_VOLTAGE_PARAMETERS_V2 v2;
1184 struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
1187 int amdgpu_atombios_get_max_vddc(struct amdgpu_device *adev, u8 voltage_type,
1188 u16 voltage_id, u16 *voltage)
1190 union set_voltage args;
1191 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
1194 if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
1201 args.v2.ucVoltageType = SET_VOLTAGE_GET_MAX_VOLTAGE;
1202 args.v2.ucVoltageMode = 0;
1203 args.v2.usVoltageLevel = 0;
1205 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1207 *voltage = le16_to_cpu(args.v2.usVoltageLevel);
1210 args.v3.ucVoltageType = voltage_type;
1211 args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
1212 args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
1214 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1216 *voltage = le16_to_cpu(args.v3.usVoltageLevel);
1219 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1226 int amdgpu_atombios_get_leakage_vddc_based_on_leakage_idx(struct amdgpu_device *adev,
1230 return amdgpu_atombios_get_max_vddc(adev, VOLTAGE_TYPE_VDDC, leakage_idx, voltage);
1233 int amdgpu_atombios_get_leakage_id_from_vbios(struct amdgpu_device *adev,
1236 union set_voltage args;
1237 int index = GetIndexIntoMasterTable(COMMAND, SetVoltage);
1240 if (!amdgpu_atom_parse_cmd_header(adev->mode_info.atom_context, index, &frev, &crev))
1246 args.v3.ucVoltageType = 0;
1247 args.v3.ucVoltageMode = ATOM_GET_LEAKAGE_ID;
1248 args.v3.usVoltageLevel = 0;
1250 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1252 *leakage_id = le16_to_cpu(args.v3.usVoltageLevel);
1255 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1262 int amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct amdgpu_device *adev,
1263 u16 *vddc, u16 *vddci,
1264 u16 virtual_voltage_id,
1265 u16 vbios_voltage_id)
1267 int index = GetIndexIntoMasterTable(DATA, ASIC_ProfilingInfo);
1269 u16 data_offset, size;
1271 ATOM_ASIC_PROFILING_INFO_V2_1 *profile;
1272 u16 *leakage_bin, *vddc_id_buf, *vddc_buf, *vddci_id_buf, *vddci_buf;
1277 if (!amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
1278 &frev, &crev, &data_offset))
1281 profile = (ATOM_ASIC_PROFILING_INFO_V2_1 *)
1282 (adev->mode_info.atom_context->bios + data_offset);
1290 if (size < sizeof(ATOM_ASIC_PROFILING_INFO_V2_1))
1292 leakage_bin = (u16 *)
1293 (adev->mode_info.atom_context->bios + data_offset +
1294 le16_to_cpu(profile->usLeakageBinArrayOffset));
1295 vddc_id_buf = (u16 *)
1296 (adev->mode_info.atom_context->bios + data_offset +
1297 le16_to_cpu(profile->usElbVDDC_IdArrayOffset));
1299 (adev->mode_info.atom_context->bios + data_offset +
1300 le16_to_cpu(profile->usElbVDDC_LevelArrayOffset));
1301 vddci_id_buf = (u16 *)
1302 (adev->mode_info.atom_context->bios + data_offset +
1303 le16_to_cpu(profile->usElbVDDCI_IdArrayOffset));
1305 (adev->mode_info.atom_context->bios + data_offset +
1306 le16_to_cpu(profile->usElbVDDCI_LevelArrayOffset));
1308 if (profile->ucElbVDDC_Num > 0) {
1309 for (i = 0; i < profile->ucElbVDDC_Num; i++) {
1310 if (vddc_id_buf[i] == virtual_voltage_id) {
1311 for (j = 0; j < profile->ucLeakageBinNum; j++) {
1312 if (vbios_voltage_id <= leakage_bin[j]) {
1313 *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];
1321 if (profile->ucElbVDDCI_Num > 0) {
1322 for (i = 0; i < profile->ucElbVDDCI_Num; i++) {
1323 if (vddci_id_buf[i] == virtual_voltage_id) {
1324 for (j = 0; j < profile->ucLeakageBinNum; j++) {
1325 if (vbios_voltage_id <= leakage_bin[j]) {
1326 *vddci = vddci_buf[j * profile->ucElbVDDCI_Num + i];
1336 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1341 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1348 union get_voltage_info {
1349 struct _GET_VOLTAGE_INFO_INPUT_PARAMETER_V1_2 in;
1350 struct _GET_EVV_VOLTAGE_INFO_OUTPUT_PARAMETER_V1_2 evv_out;
1353 int amdgpu_atombios_get_voltage_evv(struct amdgpu_device *adev,
1354 u16 virtual_voltage_id,
1357 int index = GetIndexIntoMasterTable(COMMAND, GetVoltageInfo);
1359 u32 count = adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.count;
1360 union get_voltage_info args;
1362 for (entry_id = 0; entry_id < count; entry_id++) {
1363 if (adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].v ==
1368 if (entry_id >= count)
1371 args.in.ucVoltageType = VOLTAGE_TYPE_VDDC;
1372 args.in.ucVoltageMode = ATOM_GET_VOLTAGE_EVV_VOLTAGE;
1373 args.in.usVoltageLevel = cpu_to_le16(virtual_voltage_id);
1374 args.in.ulSCLKFreq =
1375 cpu_to_le32(adev->pm.dpm.dyn_state.vddc_dependency_on_sclk.entries[entry_id].clk);
1377 amdgpu_atom_execute_table(adev->mode_info.atom_context, index, (uint32_t *)&args);
1379 *voltage = le16_to_cpu(args.evv_out.usVoltageLevel);
1384 union voltage_object_info {
1385 struct _ATOM_VOLTAGE_OBJECT_INFO v1;
1386 struct _ATOM_VOLTAGE_OBJECT_INFO_V2 v2;
1387 struct _ATOM_VOLTAGE_OBJECT_INFO_V3_1 v3;
1390 union voltage_object {
1391 struct _ATOM_VOLTAGE_OBJECT v1;
1392 struct _ATOM_VOLTAGE_OBJECT_V2 v2;
1393 union _ATOM_VOLTAGE_OBJECT_V3 v3;
1397 static ATOM_VOLTAGE_OBJECT_V3 *amdgpu_atombios_lookup_voltage_object_v3(ATOM_VOLTAGE_OBJECT_INFO_V3_1 *v3,
1398 u8 voltage_type, u8 voltage_mode)
1400 u32 size = le16_to_cpu(v3->sHeader.usStructureSize);
1401 u32 offset = offsetof(ATOM_VOLTAGE_OBJECT_INFO_V3_1, asVoltageObj[0]);
1402 u8 *start = (u8*)v3;
1404 while (offset < size) {
1405 ATOM_VOLTAGE_OBJECT_V3 *vo = (ATOM_VOLTAGE_OBJECT_V3 *)(start + offset);
1406 if ((vo->asGpioVoltageObj.sHeader.ucVoltageType == voltage_type) &&
1407 (vo->asGpioVoltageObj.sHeader.ucVoltageMode == voltage_mode))
1409 offset += le16_to_cpu(vo->asGpioVoltageObj.sHeader.usSize);
1414 int amdgpu_atombios_get_svi2_info(struct amdgpu_device *adev,
1416 u8 *svd_gpio_id, u8 *svc_gpio_id)
1418 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
1420 u16 data_offset, size;
1421 union voltage_object_info *voltage_info;
1422 union voltage_object *voltage_object = NULL;
1424 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
1425 &frev, &crev, &data_offset)) {
1426 voltage_info = (union voltage_object_info *)
1427 (adev->mode_info.atom_context->bios + data_offset);
1433 voltage_object = (union voltage_object *)
1434 amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
1437 if (voltage_object) {
1438 *svd_gpio_id = voltage_object->v3.asSVID2Obj.ucSVDGpioId;
1439 *svc_gpio_id = voltage_object->v3.asSVID2Obj.ucSVCGpioId;
1445 DRM_ERROR("unknown voltage object table\n");
1450 DRM_ERROR("unknown voltage object table\n");
1459 amdgpu_atombios_is_voltage_gpio(struct amdgpu_device *adev,
1460 u8 voltage_type, u8 voltage_mode)
1462 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
1464 u16 data_offset, size;
1465 union voltage_object_info *voltage_info;
1467 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
1468 &frev, &crev, &data_offset)) {
1469 voltage_info = (union voltage_object_info *)
1470 (adev->mode_info.atom_context->bios + data_offset);
1476 if (amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
1477 voltage_type, voltage_mode))
1481 DRM_ERROR("unknown voltage object table\n");
1486 DRM_ERROR("unknown voltage object table\n");
1494 int amdgpu_atombios_get_voltage_table(struct amdgpu_device *adev,
1495 u8 voltage_type, u8 voltage_mode,
1496 struct atom_voltage_table *voltage_table)
1498 int index = GetIndexIntoMasterTable(DATA, VoltageObjectInfo);
1500 u16 data_offset, size;
1502 union voltage_object_info *voltage_info;
1503 union voltage_object *voltage_object = NULL;
1505 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
1506 &frev, &crev, &data_offset)) {
1507 voltage_info = (union voltage_object_info *)
1508 (adev->mode_info.atom_context->bios + data_offset);
1514 voltage_object = (union voltage_object *)
1515 amdgpu_atombios_lookup_voltage_object_v3(&voltage_info->v3,
1516 voltage_type, voltage_mode);
1517 if (voltage_object) {
1518 ATOM_GPIO_VOLTAGE_OBJECT_V3 *gpio =
1519 &voltage_object->v3.asGpioVoltageObj;
1520 VOLTAGE_LUT_ENTRY_V2 *lut;
1521 if (gpio->ucGpioEntryNum > MAX_VOLTAGE_ENTRIES)
1523 lut = &gpio->asVolGpioLut[0];
1524 for (i = 0; i < gpio->ucGpioEntryNum; i++) {
1525 voltage_table->entries[i].value =
1526 le16_to_cpu(lut->usVoltageValue);
1527 voltage_table->entries[i].smio_low =
1528 le32_to_cpu(lut->ulVoltageId);
1529 lut = (VOLTAGE_LUT_ENTRY_V2 *)
1530 ((u8 *)lut + sizeof(VOLTAGE_LUT_ENTRY_V2));
1532 voltage_table->mask_low = le32_to_cpu(gpio->ulGpioMaskVal);
1533 voltage_table->count = gpio->ucGpioEntryNum;
1534 voltage_table->phase_delay = gpio->ucPhaseDelay;
1539 DRM_ERROR("unknown voltage object table\n");
1544 DRM_ERROR("unknown voltage object table\n");
1552 struct _ATOM_VRAM_INFO_V3 v1_3;
1553 struct _ATOM_VRAM_INFO_V4 v1_4;
1554 struct _ATOM_VRAM_INFO_HEADER_V2_1 v2_1;
1557 #define MEM_ID_MASK 0xff000000
1558 #define MEM_ID_SHIFT 24
1559 #define CLOCK_RANGE_MASK 0x00ffffff
1560 #define CLOCK_RANGE_SHIFT 0
1561 #define LOW_NIBBLE_MASK 0xf
1562 #define DATA_EQU_PREV 0
1563 #define DATA_FROM_TABLE 4
1565 int amdgpu_atombios_init_mc_reg_table(struct amdgpu_device *adev,
1567 struct atom_mc_reg_table *reg_table)
1569 int index = GetIndexIntoMasterTable(DATA, VRAM_Info);
1570 u8 frev, crev, num_entries, t_mem_id, num_ranges = 0;
1572 u16 data_offset, size;
1573 union vram_info *vram_info;
1575 memset(reg_table, 0, sizeof(struct atom_mc_reg_table));
1577 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
1578 &frev, &crev, &data_offset)) {
1579 vram_info = (union vram_info *)
1580 (adev->mode_info.atom_context->bios + data_offset);
1583 DRM_ERROR("old table version %d, %d\n", frev, crev);
1588 if (module_index < vram_info->v2_1.ucNumOfVRAMModule) {
1589 ATOM_INIT_REG_BLOCK *reg_block =
1590 (ATOM_INIT_REG_BLOCK *)
1591 ((u8 *)vram_info + le16_to_cpu(vram_info->v2_1.usMemClkPatchTblOffset));
1592 ATOM_MEMORY_SETTING_DATA_BLOCK *reg_data =
1593 (ATOM_MEMORY_SETTING_DATA_BLOCK *)
1594 ((u8 *)reg_block + (2 * sizeof(u16)) +
1595 le16_to_cpu(reg_block->usRegIndexTblSize));
1596 ATOM_INIT_REG_INDEX_FORMAT *format = ®_block->asRegIndexBuf[0];
1597 num_entries = (u8)((le16_to_cpu(reg_block->usRegIndexTblSize)) /
1598 sizeof(ATOM_INIT_REG_INDEX_FORMAT)) - 1;
1599 if (num_entries > VBIOS_MC_REGISTER_ARRAY_SIZE)
1601 while (i < num_entries) {
1602 if (format->ucPreRegDataLength & ACCESS_PLACEHOLDER)
1604 reg_table->mc_reg_address[i].s1 =
1605 (u16)(le16_to_cpu(format->usRegIndex));
1606 reg_table->mc_reg_address[i].pre_reg_data =
1607 (u8)(format->ucPreRegDataLength);
1609 format = (ATOM_INIT_REG_INDEX_FORMAT *)
1610 ((u8 *)format + sizeof(ATOM_INIT_REG_INDEX_FORMAT));
1612 reg_table->last = i;
1613 while ((le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK) &&
1614 (num_ranges < VBIOS_MAX_AC_TIMING_ENTRIES)) {
1615 t_mem_id = (u8)((le32_to_cpu(*(u32 *)reg_data) & MEM_ID_MASK)
1617 if (module_index == t_mem_id) {
1618 reg_table->mc_reg_table_entry[num_ranges].mclk_max =
1619 (u32)((le32_to_cpu(*(u32 *)reg_data) & CLOCK_RANGE_MASK)
1620 >> CLOCK_RANGE_SHIFT);
1621 for (i = 0, j = 1; i < reg_table->last; i++) {
1622 if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_FROM_TABLE) {
1623 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
1624 (u32)le32_to_cpu(*((u32 *)reg_data + j));
1626 } else if ((reg_table->mc_reg_address[i].pre_reg_data & LOW_NIBBLE_MASK) == DATA_EQU_PREV) {
1627 reg_table->mc_reg_table_entry[num_ranges].mc_data[i] =
1628 reg_table->mc_reg_table_entry[num_ranges].mc_data[i - 1];
1633 reg_data = (ATOM_MEMORY_SETTING_DATA_BLOCK *)
1634 ((u8 *)reg_data + le16_to_cpu(reg_block->usRegDataBlkSize));
1636 if (le32_to_cpu(*(u32 *)reg_data) != END_OF_REG_DATA_BLOCK)
1638 reg_table->num_entries = num_ranges;
1643 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1648 DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
1656 bool amdgpu_atombios_has_gpu_virtualization_table(struct amdgpu_device *adev)
1658 int index = GetIndexIntoMasterTable(DATA, GPUVirtualizationInfo);
1660 u16 data_offset, size;
1662 if (amdgpu_atom_parse_data_header(adev->mode_info.atom_context, index, &size,
1663 &frev, &crev, &data_offset))
1669 void amdgpu_atombios_scratch_regs_lock(struct amdgpu_device *adev, bool lock)
1671 uint32_t bios_6_scratch;
1673 bios_6_scratch = RREG32(adev->bios_scratch_reg_offset + 6);
1676 bios_6_scratch |= ATOM_S6_CRITICAL_STATE;
1677 bios_6_scratch &= ~ATOM_S6_ACC_MODE;
1679 bios_6_scratch &= ~ATOM_S6_CRITICAL_STATE;
1680 bios_6_scratch |= ATOM_S6_ACC_MODE;
1683 WREG32(adev->bios_scratch_reg_offset + 6, bios_6_scratch);
1686 void amdgpu_atombios_scratch_regs_init(struct amdgpu_device *adev)
1688 uint32_t bios_2_scratch, bios_6_scratch;
1690 adev->bios_scratch_reg_offset = mmBIOS_SCRATCH_0;
1692 bios_2_scratch = RREG32(adev->bios_scratch_reg_offset + 2);
1693 bios_6_scratch = RREG32(adev->bios_scratch_reg_offset + 6);
1695 /* let the bios control the backlight */
1696 bios_2_scratch &= ~ATOM_S2_VRI_BRIGHT_ENABLE;
1698 /* tell the bios not to handle mode switching */
1699 bios_6_scratch |= ATOM_S6_ACC_BLOCK_DISPLAY_SWITCH;
1701 /* clear the vbios dpms state */
1702 bios_2_scratch &= ~ATOM_S2_DEVICE_DPMS_STATE;
1704 WREG32(adev->bios_scratch_reg_offset + 2, bios_2_scratch);
1705 WREG32(adev->bios_scratch_reg_offset + 6, bios_6_scratch);
1708 void amdgpu_atombios_scratch_regs_save(struct amdgpu_device *adev)
1712 for (i = 0; i < AMDGPU_BIOS_NUM_SCRATCH; i++)
1713 adev->bios_scratch[i] = RREG32(adev->bios_scratch_reg_offset + i);
1716 void amdgpu_atombios_scratch_regs_restore(struct amdgpu_device *adev)
1721 * VBIOS will check ASIC_INIT_COMPLETE bit to decide if
1722 * execute ASIC_Init posting via driver
1724 adev->bios_scratch[7] &= ~ATOM_S7_ASIC_INIT_COMPLETE_MASK;
1726 for (i = 0; i < AMDGPU_BIOS_NUM_SCRATCH; i++)
1727 WREG32(adev->bios_scratch_reg_offset + i, adev->bios_scratch[i]);
1730 void amdgpu_atombios_scratch_regs_engine_hung(struct amdgpu_device *adev,
1733 u32 tmp = RREG32(adev->bios_scratch_reg_offset + 3);
1736 tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1738 tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
1740 WREG32(adev->bios_scratch_reg_offset + 3, tmp);
1743 bool amdgpu_atombios_scratch_need_asic_init(struct amdgpu_device *adev)
1745 u32 tmp = RREG32(adev->bios_scratch_reg_offset + 7);
1747 if (tmp & ATOM_S7_ASIC_INIT_COMPLETE_MASK)
1753 /* Atom needs data in little endian format so swap as appropriate when copying
1754 * data to or from atom. Note that atom operates on dw units.
1756 * Use to_le=true when sending data to atom and provide at least
1757 * ALIGN(num_bytes,4) bytes in the dst buffer.
1759 * Use to_le=false when receiving data from atom and provide ALIGN(num_bytes,4)
1760 * byes in the src buffer.
1762 void amdgpu_atombios_copy_swap(u8 *dst, u8 *src, u8 num_bytes, bool to_le)
1765 u32 src_tmp[5], dst_tmp[5];
1767 u8 align_num_bytes = ALIGN(num_bytes, 4);
1770 memcpy(src_tmp, src, num_bytes);
1771 for (i = 0; i < align_num_bytes / 4; i++)
1772 dst_tmp[i] = cpu_to_le32(src_tmp[i]);
1773 memcpy(dst, dst_tmp, align_num_bytes);
1775 memcpy(src_tmp, src, align_num_bytes);
1776 for (i = 0; i < align_num_bytes / 4; i++)
1777 dst_tmp[i] = le32_to_cpu(src_tmp[i]);
1778 memcpy(dst, dst_tmp, num_bytes);
1781 memcpy(dst, src, num_bytes);
1785 int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev)
1787 struct atom_context *ctx = adev->mode_info.atom_context;
1788 int index = GetIndexIntoMasterTable(DATA, VRAM_UsageByFirmware);
1789 uint16_t data_offset;
1790 int usage_bytes = 0;
1791 struct _ATOM_VRAM_USAGE_BY_FIRMWARE *firmware_usage;
1793 if (amdgpu_atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) {
1794 firmware_usage = (struct _ATOM_VRAM_USAGE_BY_FIRMWARE *)(ctx->bios + data_offset);
1796 DRM_DEBUG("atom firmware requested %08x %dkb\n",
1797 le32_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware),
1798 le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb));
1800 usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024;
1802 ctx->scratch_size_bytes = 0;
1803 if (usage_bytes == 0)
1804 usage_bytes = 20 * 1024;
1805 /* allocate some scratch memory */
1806 ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL);
1809 ctx->scratch_size_bytes = usage_bytes;