Subversion Repositories Kolibri OS

Rev

Rev 1986 | Rev 3764 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1986 Rev 2997
Line 21... Line 21...
21
 * OTHER DEALINGS IN THE SOFTWARE.
21
 * OTHER DEALINGS IN THE SOFTWARE.
22
 *
22
 *
23
 * Authors: Dave Airlie
23
 * Authors: Dave Airlie
24
 *          Alex Deucher
24
 *          Alex Deucher
25
 */
25
 */
26
#include "drmP.h"
26
#include 
27
#include "radeon_drm.h"
27
#include 
28
#include "radeon.h"
28
#include "radeon.h"
Line 29... Line 29...
29
 
29
 
30
#include "atom.h"
30
#include "atom.h"
Line 54... Line 54...
54
/* from radeon_legacy_encoder.c */
54
/* from radeon_legacy_encoder.c */
55
extern void
55
extern void
56
radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
56
radeon_add_legacy_encoder(struct drm_device *dev, uint32_t encoder_enum,
57
			  uint32_t supported_device);
57
			  uint32_t supported_device);
Line -... Line 58...
-
 
58
 
-
 
59
/* local */
-
 
60
static int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
-
 
61
				    u16 voltage_id, u16 *voltage);
58
 
62
 
59
union atom_supported_devices {
63
union atom_supported_devices {
60
	struct _ATOM_SUPPORTED_DEVICES_INFO info;
64
	struct _ATOM_SUPPORTED_DEVICES_INFO info;
61
	struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
65
	struct _ATOM_SUPPORTED_DEVICES_INFO_2 info_2;
62
	struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
66
	struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 info_2d1;
Line 63... Line 67...
63
};
67
};
-
 
68
 
64
 
69
static void radeon_lookup_i2c_gpio_quirks(struct radeon_device *rdev,
65
static inline struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
70
					  ATOM_GPIO_I2C_ASSIGMENT *gpio,
66
							       uint8_t id)
71
					  u8 index)
67
{
72
{
68
	struct atom_context *ctx = rdev->mode_info.atom_context;
73
	/* r4xx mask is technically not used by the hw, so patch in the legacy mask bits */
69
	ATOM_GPIO_I2C_ASSIGMENT *gpio;
74
	if ((rdev->family == CHIP_R420) ||
70
	struct radeon_i2c_bus_rec i2c;
75
	    (rdev->family == CHIP_R423) ||
71
	int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
76
	    (rdev->family == CHIP_RV410)) {
72
	struct _ATOM_GPIO_I2C_INFO *i2c_info;
-
 
73
	uint16_t data_offset, size;
-
 
74
	int i, num_indices;
77
		if ((le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0018) ||
75
 
78
		    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x0019) ||
76
	memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
-
 
77
	i2c.valid = false;
-
 
78
 
79
		    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x001a)) {
79
	if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
80
			gpio->ucClkMaskShift = 0x19;
80
	i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
-
 
81
 
-
 
82
		num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
81
			gpio->ucDataMaskShift = 0x18;
83
			sizeof(ATOM_GPIO_I2C_ASSIGMENT);
-
 
84
 
-
 
Line 85... Line 82...
85
		for (i = 0; i < num_indices; i++) {
82
		}
86
		gpio = &i2c_info->asGPIO_Info[i];
83
	}
87
 
84
 
88
			/* some evergreen boards have bad data for this entry */
85
			/* some evergreen boards have bad data for this entry */
89
			if (ASIC_IS_DCE4(rdev)) {
86
			if (ASIC_IS_DCE4(rdev)) {
90
				if ((i == 7) &&
87
		if ((index == 7) &&
91
				    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
88
				    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
92
				    (gpio->sucI2cId.ucAccess == 0)) {
89
				    (gpio->sucI2cId.ucAccess == 0)) {
Line 98... Line 95...
98
				}
95
				}
99
			}
96
			}
Line 100... Line 97...
100
 
97
 
101
			/* some DCE3 boards have bad data for this entry */
98
			/* some DCE3 boards have bad data for this entry */
102
			if (ASIC_IS_DCE3(rdev)) {
99
			if (ASIC_IS_DCE3(rdev)) {
103
				if ((i == 4) &&
100
		if ((index == 4) &&
104
				    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
101
				    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
105
				    (gpio->sucI2cId.ucAccess == 0x94))
102
				    (gpio->sucI2cId.ucAccess == 0x94))
106
					gpio->sucI2cId.ucAccess = 0x14;
103
					gpio->sucI2cId.ucAccess = 0x14;
-
 
104
			}
-
 
105
}
-
 
106
 
-
 
107
static struct radeon_i2c_bus_rec radeon_get_bus_rec_for_i2c_gpio(ATOM_GPIO_I2C_ASSIGMENT *gpio)
-
 
108
{
-
 
109
	struct radeon_i2c_bus_rec i2c;
-
 
110
 
Line 107... Line -...
107
			}
-
 
108
 
111
	memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
109
		if (gpio->sucI2cId.ucAccess == id) {
112
 
110
			i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
113
			i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
111
			i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
114
			i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
112
			i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
115
			i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
Line 136... Line 139...
136
 
139
 
Line 137... Line 140...
137
			i2c.i2c_id = gpio->sucI2cId.ucAccess;
140
			i2c.i2c_id = gpio->sucI2cId.ucAccess;
138
 
141
 
139
				if (i2c.mask_clk_reg)
142
				if (i2c.mask_clk_reg)
140
	i2c.valid = true;
143
	i2c.valid = true;
141
			break;
-
 
142
		}
-
 
Line 143... Line 144...
143
	}
144
	else
144
	}
145
		i2c.valid = false;
Line 145... Line 146...
145
 
146
 
-
 
147
	return i2c;
146
	return i2c;
148
}
147
}
149
 
148
 
150
static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev,
149
void radeon_atombios_i2c_init(struct radeon_device *rdev)
151
							       uint8_t id)
150
{
152
{
151
	struct atom_context *ctx = rdev->mode_info.atom_context;
153
	struct atom_context *ctx = rdev->mode_info.atom_context;
152
	ATOM_GPIO_I2C_ASSIGMENT *gpio;
154
	ATOM_GPIO_I2C_ASSIGMENT *gpio;
153
	struct radeon_i2c_bus_rec i2c;
155
	struct radeon_i2c_bus_rec i2c;
154
	int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
-
 
Line 155... Line 156...
155
	struct _ATOM_GPIO_I2C_INFO *i2c_info;
156
	int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
-
 
157
	struct _ATOM_GPIO_I2C_INFO *i2c_info;
Line 156... Line 158...
156
	uint16_t data_offset, size;
158
	uint16_t data_offset, size;
157
	int i, num_indices;
159
	int i, num_indices;
Line 158... Line 160...
158
	char stmp[32];
160
 
159
 
161
	memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
Line 160... Line 162...
160
	memset(&i2c, 0, sizeof(struct radeon_i2c_bus_rec));
162
	i2c.valid = false;
161
 
163
 
162
	if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
-
 
Line 163... Line -...
163
		i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
-
 
164
 
-
 
165
		num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
-
 
166
			sizeof(ATOM_GPIO_I2C_ASSIGMENT);
164
	if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
-
 
165
		i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
167
 
166
 
168
		for (i = 0; i < num_indices; i++) {
167
		num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
169
			gpio = &i2c_info->asGPIO_Info[i];
168
			sizeof(ATOM_GPIO_I2C_ASSIGMENT);
170
			i2c.valid = false;
-
 
171
 
-
 
172
			/* some evergreen boards have bad data for this entry */
169
 
173
			if (ASIC_IS_DCE4(rdev)) {
170
		for (i = 0; i < num_indices; i++) {
174
				if ((i == 7) &&
171
			gpio = &i2c_info->asGPIO_Info[i];
Line 175... Line -...
175
				    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1936) &&
-
 
176
				    (gpio->sucI2cId.ucAccess == 0)) {
-
 
177
					gpio->sucI2cId.ucAccess = 0x97;
172
 
178
					gpio->ucDataMaskShift = 8;
-
 
179
					gpio->ucDataEnShift = 8;
-
 
180
					gpio->ucDataY_Shift = 8;
-
 
181
					gpio->ucDataA_Shift = 8;
173
			radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
Line 182... Line -...
182
				}
-
 
183
			}
-
 
184
 
-
 
185
			/* some DCE3 boards have bad data for this entry */
-
 
186
			if (ASIC_IS_DCE3(rdev)) {
-
 
187
				if ((i == 4) &&
-
 
188
				    (le16_to_cpu(gpio->usClkMaskRegisterIndex) == 0x1fda) &&
-
 
189
				    (gpio->sucI2cId.ucAccess == 0x94))
174
 
-
 
175
			if (gpio->sucI2cId.ucAccess == id) {
190
					gpio->sucI2cId.ucAccess = 0x14;
176
				i2c = radeon_get_bus_rec_for_i2c_gpio(gpio);
191
			}
177
				break;
192
 
178
			}
193
			i2c.mask_clk_reg = le16_to_cpu(gpio->usClkMaskRegisterIndex) * 4;
179
				}
194
			i2c.mask_data_reg = le16_to_cpu(gpio->usDataMaskRegisterIndex) * 4;
180
			}
195
			i2c.en_clk_reg = le16_to_cpu(gpio->usClkEnRegisterIndex) * 4;
181
 
196
			i2c.en_data_reg = le16_to_cpu(gpio->usDataEnRegisterIndex) * 4;
182
	return i2c;
197
			i2c.y_clk_reg = le16_to_cpu(gpio->usClkY_RegisterIndex) * 4;
183
}
Line 198... Line 184...
198
			i2c.y_data_reg = le16_to_cpu(gpio->usDataY_RegisterIndex) * 4;
184
 
199
			i2c.a_clk_reg = le16_to_cpu(gpio->usClkA_RegisterIndex) * 4;
-
 
200
			i2c.a_data_reg = le16_to_cpu(gpio->usDataA_RegisterIndex) * 4;
-
 
201
			i2c.mask_clk_mask = (1 << gpio->ucClkMaskShift);
185
void radeon_atombios_i2c_init(struct radeon_device *rdev)
Line 202... Line 186...
202
			i2c.mask_data_mask = (1 << gpio->ucDataMaskShift);
186
{
203
			i2c.en_clk_mask = (1 << gpio->ucClkEnShift);
-
 
204
			i2c.en_data_mask = (1 << gpio->ucDataEnShift);
-
 
205
			i2c.y_clk_mask = (1 << gpio->ucClkY_Shift);
187
	struct atom_context *ctx = rdev->mode_info.atom_context;
Line -... Line 188...
-
 
188
	ATOM_GPIO_I2C_ASSIGMENT *gpio;
206
			i2c.y_data_mask = (1 << gpio->ucDataY_Shift);
189
	struct radeon_i2c_bus_rec i2c;
Line 207... Line 190...
207
			i2c.a_clk_mask = (1 << gpio->ucClkA_Shift);
190
	int index = GetIndexIntoMasterTable(DATA, GPIO_I2C_Info);
-
 
191
	struct _ATOM_GPIO_I2C_INFO *i2c_info;
-
 
192
	uint16_t data_offset, size;
-
 
193
	int i, num_indices;
208
			i2c.a_data_mask = (1 << gpio->ucDataA_Shift);
194
	char stmp[32];
209
 
195
 
210
			if (gpio->sucI2cId.sbfAccess.bfHW_Capable)
196
	if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) {
211
				i2c.hw_capable = true;
197
		i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset);
212
			else
198
 
213
				i2c.hw_capable = false;
199
		num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) /
214
 
200
			sizeof(ATOM_GPIO_I2C_ASSIGMENT);
Line 215... Line 201...
215
			if (gpio->sucI2cId.ucAccess == 0xa0)
201
 
216
				i2c.mm_i2c = true;
202
		for (i = 0; i < num_indices; i++) {
217
			else
203
			gpio = &i2c_info->asGPIO_Info[i];
218
				i2c.mm_i2c = false;
204
 
219
 
205
			radeon_lookup_i2c_gpio_quirks(rdev, gpio, i);
220
			i2c.i2c_id = gpio->sucI2cId.ucAccess;
206
 
Line 269... Line 255...
269
	struct radeon_hpd hpd;
255
	struct radeon_hpd hpd;
270
	u32 reg;
256
	u32 reg;
Line 271... Line 257...
271
 
257
 
Line 272... Line 258...
272
	memset(&hpd, 0, sizeof(struct radeon_hpd));
258
	memset(&hpd, 0, sizeof(struct radeon_hpd));
-
 
259
 
-
 
260
	if (ASIC_IS_DCE6(rdev))
273
 
261
		reg = SI_DC_GPIO_HPD_A;
274
	if (ASIC_IS_DCE4(rdev))
262
	else if (ASIC_IS_DCE4(rdev))
275
		reg = EVERGREEN_DC_GPIO_HPD_A;
263
		reg = EVERGREEN_DC_GPIO_HPD_A;
Line 276... Line 264...
276
	else
264
	else
Line 454... Line 442...
454
	/* XFX Pine Group device rv730 reports no VGA DDC lines
442
	/* XFX Pine Group device rv730 reports no VGA DDC lines
455
	 * even though they are wired up to record 0x93
443
	 * even though they are wired up to record 0x93
456
	 */
444
	 */
457
	if ((dev->pdev->device == 0x9498) &&
445
	if ((dev->pdev->device == 0x9498) &&
458
	    (dev->pdev->subsystem_vendor == 0x1682) &&
446
	    (dev->pdev->subsystem_vendor == 0x1682) &&
459
	    (dev->pdev->subsystem_device == 0x2452)) {
447
	    (dev->pdev->subsystem_device == 0x2452) &&
-
 
448
	    (i2c_bus->valid == false) &&
-
 
449
	    !(supported_device & (ATOM_DEVICE_TV_SUPPORT | ATOM_DEVICE_CV_SUPPORT))) {
460
		struct radeon_device *rdev = dev->dev_private;
450
		struct radeon_device *rdev = dev->dev_private;
461
		*i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
451
		*i2c_bus = radeon_lookup_i2c_gpio(rdev, 0x93);
462
	}
452
	}
-
 
453
 
-
 
454
	/* Fujitsu D3003-S2 board lists DVI-I as DVI-D and VGA */
-
 
455
	if (((dev->pdev->device == 0x9802) || (dev->pdev->device == 0x9806)) &&
-
 
456
	    (dev->pdev->subsystem_vendor == 0x1734) &&
-
 
457
	    (dev->pdev->subsystem_device == 0x11bd)) {
-
 
458
		if (*connector_type == DRM_MODE_CONNECTOR_VGA) {
-
 
459
			*connector_type = DRM_MODE_CONNECTOR_DVII;
-
 
460
			*line_mux = 0x3103;
-
 
461
		} else if (*connector_type == DRM_MODE_CONNECTOR_DVID) {
-
 
462
			*connector_type = DRM_MODE_CONNECTOR_DVII;
-
 
463
		}
-
 
464
	}
-
 
465
 
-
 
466
 
463
	return true;
467
	return true;
464
}
468
}
Line 465... Line 469...
465
 
469
 
466
const int supported_devices_connector_convert[] = {
470
const int supported_devices_connector_convert[] = {
Line 1248... Line 1252...
1248
 
1252
 
1249
		rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
1253
		rdev->clock.max_pixel_clock = le16_to_cpu(firmware_info->info.usMaxPixelClock);
1250
		if (rdev->clock.max_pixel_clock == 0)
1254
		if (rdev->clock.max_pixel_clock == 0)
Line -... Line 1255...
-
 
1255
			rdev->clock.max_pixel_clock = 40000;
-
 
1256
 
-
 
1257
		/* not technically a clock, but... */
-
 
1258
		rdev->mode_info.firmware_flags =
1251
			rdev->clock.max_pixel_clock = 40000;
1259
			le16_to_cpu(firmware_info->info.usFirmwareCapability.susAccess);
1252
 
1260
 
Line 1253... Line 1261...
1253
		return true;
1261
		return true;
1254
	}
1262
	}
Line 1255... Line 1263...
1255
 
1263
 
1256
	return false;
1264
	return false;
1257
}
1265
}
-
 
1266
 
-
 
1267
union igp_info {
1258
 
1268
	struct _ATOM_INTEGRATED_SYSTEM_INFO info;
Line 1259... Line 1269...
1259
union igp_info {
1269
	struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1260
	struct _ATOM_INTEGRATED_SYSTEM_INFO info;
1270
	struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
1261
	struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
1271
	struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
Line 1384... Line 1394...
1384
						 int id)
1394
						 int id)
1385
{
1395
{
1386
	struct radeon_mode_info *mode_info = &rdev->mode_info;
1396
	struct radeon_mode_info *mode_info = &rdev->mode_info;
1387
	int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1397
	int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
1388
	u16 data_offset, size;
1398
	u16 data_offset, size;
1389
	struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *igp_info;
1399
	union igp_info *igp_info;
1390
	u8 frev, crev;
1400
	u8 frev, crev;
1391
	u16 percentage = 0, rate = 0;
1401
	u16 percentage = 0, rate = 0;
Line 1392... Line 1402...
1392
 
1402
 
1393
	/* get any igp specific overrides */
1403
	/* get any igp specific overrides */
1394
	if (atom_parse_data_header(mode_info->atom_context, index, &size,
1404
	if (atom_parse_data_header(mode_info->atom_context, index, &size,
1395
				   &frev, &crev, &data_offset)) {
1405
				   &frev, &crev, &data_offset)) {
1396
		igp_info = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 *)
1406
		igp_info = (union igp_info *)
-
 
1407
			(mode_info->atom_context->bios + data_offset);
-
 
1408
		switch (crev) {
-
 
1409
		case 6:
-
 
1410
			switch (id) {
-
 
1411
			case ASIC_INTERNAL_SS_ON_TMDS:
-
 
1412
				percentage = le16_to_cpu(igp_info->info_6.usDVISSPercentage);
-
 
1413
				rate = le16_to_cpu(igp_info->info_6.usDVISSpreadRateIn10Hz);
-
 
1414
				break;
-
 
1415
			case ASIC_INTERNAL_SS_ON_HDMI:
-
 
1416
				percentage = le16_to_cpu(igp_info->info_6.usHDMISSPercentage);
-
 
1417
				rate = le16_to_cpu(igp_info->info_6.usHDMISSpreadRateIn10Hz);
-
 
1418
				break;
-
 
1419
			case ASIC_INTERNAL_SS_ON_LVDS:
-
 
1420
				percentage = le16_to_cpu(igp_info->info_6.usLvdsSSPercentage);
-
 
1421
				rate = le16_to_cpu(igp_info->info_6.usLvdsSSpreadRateIn10Hz);
-
 
1422
				break;
-
 
1423
			}
-
 
1424
			break;
1397
			(mode_info->atom_context->bios + data_offset);
1425
		case 7:
1398
		switch (id) {
1426
		switch (id) {
1399
		case ASIC_INTERNAL_SS_ON_TMDS:
1427
		case ASIC_INTERNAL_SS_ON_TMDS:
1400
			percentage = le16_to_cpu(igp_info->usDVISSPercentage);
1428
				percentage = le16_to_cpu(igp_info->info_7.usDVISSPercentage);
1401
			rate = le16_to_cpu(igp_info->usDVISSpreadRateIn10Hz);
1429
				rate = le16_to_cpu(igp_info->info_7.usDVISSpreadRateIn10Hz);
1402
			break;
1430
			break;
1403
		case ASIC_INTERNAL_SS_ON_HDMI:
1431
		case ASIC_INTERNAL_SS_ON_HDMI:
1404
			percentage = le16_to_cpu(igp_info->usHDMISSPercentage);
1432
				percentage = le16_to_cpu(igp_info->info_7.usHDMISSPercentage);
1405
			rate = le16_to_cpu(igp_info->usHDMISSpreadRateIn10Hz);
1433
				rate = le16_to_cpu(igp_info->info_7.usHDMISSpreadRateIn10Hz);
1406
			break;
1434
			break;
1407
		case ASIC_INTERNAL_SS_ON_LVDS:
1435
		case ASIC_INTERNAL_SS_ON_LVDS:
1408
			percentage = le16_to_cpu(igp_info->usLvdsSSPercentage);
1436
				percentage = le16_to_cpu(igp_info->info_7.usLvdsSSPercentage);
-
 
1437
				rate = le16_to_cpu(igp_info->info_7.usLvdsSSpreadRateIn10Hz);
-
 
1438
				break;
-
 
1439
			}
-
 
1440
			break;
-
 
1441
		default:
1409
			rate = le16_to_cpu(igp_info->usLvdsSSpreadRateIn10Hz);
1442
			DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
1410
			break;
1443
			break;
1411
		}
1444
		}
1412
		if (percentage)
1445
		if (percentage)
1413
			ss->percentage = percentage;
1446
			ss->percentage = percentage;
Line 1890... Line 1923...
1890
	"External GPIO",
1923
	"External GPIO",
1891
	"Evergreen",
1924
	"Evergreen",
1892
	"emc2103",
1925
	"emc2103",
1893
	"Sumo",
1926
	"Sumo",
1894
	"Northern Islands",
1927
	"Northern Islands",
-
 
1928
	"Southern Islands",
-
 
1929
	"lm96163",
1895
};
1930
};
Line 1896... Line 1931...
1896
 
1931
 
1897
union power_info {
1932
union power_info {
1898
	struct _ATOM_POWERPLAY_INFO info;
1933
	struct _ATOM_POWERPLAY_INFO info;
Line 1906... Line 1941...
1906
union pplib_clock_info {
1941
union pplib_clock_info {
1907
	struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
1942
	struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
1908
	struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
1943
	struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
1909
	struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
1944
	struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
1910
	struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
1945
	struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
-
 
1946
	struct _ATOM_PPLIB_SI_CLOCK_INFO si;
1911
};
1947
};
Line 1912... Line 1948...
1912
 
1948
 
1913
union pplib_power_state {
1949
union pplib_power_state {
1914
	struct _ATOM_PPLIB_STATE v1;
1950
	struct _ATOM_PPLIB_STATE v1;
Line 1971... Line 2007...
1971
				   &frev, &crev, &data_offset))
2007
				   &frev, &crev, &data_offset))
1972
		return state_index;
2008
		return state_index;
1973
	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2009
	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
Line 1974... Line 2010...
1974
 
2010
 
1975
			/* add the i2c bus for thermal/fan chip */
2011
			/* add the i2c bus for thermal/fan chip */
-
 
2012
	if ((power_info->info.ucOverdriveThermalController > 0) &&
1976
			if (power_info->info.ucOverdriveThermalController > 0) {
2013
	    (power_info->info.ucOverdriveThermalController < ARRAY_SIZE(thermal_controller_names))) {
1977
				DRM_INFO("Possible %s thermal controller at 0x%02x\n",
2014
				DRM_INFO("Possible %s thermal controller at 0x%02x\n",
1978
					 thermal_controller_names[power_info->info.ucOverdriveThermalController],
2015
					 thermal_controller_names[power_info->info.ucOverdriveThermalController],
1979
					 power_info->info.ucOverdriveControllerAddress >> 1);
2016
					 power_info->info.ucOverdriveControllerAddress >> 1);
1980
				i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
2017
				i2c_bus = radeon_lookup_i2c_gpio(rdev, power_info->info.ucOverdriveI2cLine);
Line 1994... Line 2031...
1994
	rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
2031
	rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) * num_modes, GFP_KERNEL);
1995
	if (!rdev->pm.power_state)
2032
	if (!rdev->pm.power_state)
1996
		return state_index;
2033
		return state_index;
1997
			/* last mode is usually default, array is low to high */
2034
			/* last mode is usually default, array is low to high */
1998
			for (i = 0; i < num_modes; i++) {
2035
			for (i = 0; i < num_modes; i++) {
-
 
2036
		rdev->pm.power_state[state_index].clock_info =
-
 
2037
			kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
-
 
2038
		if (!rdev->pm.power_state[state_index].clock_info)
-
 
2039
			return state_index;
-
 
2040
		rdev->pm.power_state[state_index].num_clock_modes = 1;
1999
				rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2041
				rdev->pm.power_state[state_index].clock_info[0].voltage.type = VOLTAGE_NONE;
2000
				switch (frev) {
2042
				switch (frev) {
2001
				case 1:
2043
				case 1:
2002
					rdev->pm.power_state[state_index].num_clock_modes = 1;
-
 
2003
					rdev->pm.power_state[state_index].clock_info[0].mclk =
2044
					rdev->pm.power_state[state_index].clock_info[0].mclk =
2004
						le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2045
						le16_to_cpu(power_info->info.asPowerPlayInfo[i].usMemoryClock);
2005
					rdev->pm.power_state[state_index].clock_info[0].sclk =
2046
					rdev->pm.power_state[state_index].clock_info[0].sclk =
2006
						le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
2047
						le16_to_cpu(power_info->info.asPowerPlayInfo[i].usEngineClock);
2007
					/* skip invalid modes */
2048
					/* skip invalid modes */
Line 2033... Line 2074...
2033
					rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2074
					rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2034
			radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
2075
			radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, 0);
2035
					state_index++;
2076
					state_index++;
2036
					break;
2077
					break;
2037
				case 2:
2078
				case 2:
2038
					rdev->pm.power_state[state_index].num_clock_modes = 1;
-
 
2039
					rdev->pm.power_state[state_index].clock_info[0].mclk =
2079
					rdev->pm.power_state[state_index].clock_info[0].mclk =
2040
						le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2080
						le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulMemoryClock);
2041
					rdev->pm.power_state[state_index].clock_info[0].sclk =
2081
					rdev->pm.power_state[state_index].clock_info[0].sclk =
2042
						le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
2082
						le32_to_cpu(power_info->info_2.asPowerPlayInfo[i].ulEngineClock);
2043
					/* skip invalid modes */
2083
					/* skip invalid modes */
Line 2070... Line 2110...
2070
					rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2110
					rdev->pm.power_state[state_index].flags = RADEON_PM_STATE_SINGLE_DISPLAY_ONLY;
2071
			radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2111
			radeon_atombios_parse_misc_flags_1_3(rdev, state_index, misc, misc2);
2072
					state_index++;
2112
					state_index++;
2073
					break;
2113
					break;
2074
				case 3:
2114
				case 3:
2075
					rdev->pm.power_state[state_index].num_clock_modes = 1;
-
 
2076
					rdev->pm.power_state[state_index].clock_info[0].mclk =
2115
					rdev->pm.power_state[state_index].clock_info[0].mclk =
2077
						le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2116
						le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulMemoryClock);
2078
					rdev->pm.power_state[state_index].clock_info[0].sclk =
2117
					rdev->pm.power_state[state_index].clock_info[0].sclk =
2079
						le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2118
						le32_to_cpu(power_info->info_3.asPowerPlayInfo[i].ulEngineClock);
2080
					/* skip invalid modes */
2119
					/* skip invalid modes */
Line 2161... Line 2200...
2161
		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2200
		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
2162
			DRM_INFO("Internal thermal controller %s fan control\n",
2201
			DRM_INFO("Internal thermal controller %s fan control\n",
2163
				 (controller->ucFanParameters &
2202
				 (controller->ucFanParameters &
2164
				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2203
				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2165
			rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
2204
			rdev->pm.int_thermal_type = THERMAL_TYPE_NI;
-
 
2205
		} else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
-
 
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_SI;
2166
				} else if ((controller->ucType ==
2210
				} else if ((controller->ucType ==
2167
					    ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2211
					    ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) ||
2168
					   (controller->ucType ==
2212
					   (controller->ucType ==
2169
			    ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
2213
			    ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) ||
2170
			   (controller->ucType ==
2214
			   (controller->ucType ==
2171
			    ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
2215
			    ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL)) {
2172
					DRM_INFO("Special thermal controller config\n");
2216
					DRM_INFO("Special thermal controller config\n");
2173
				} else {
2217
		} else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
2174
					DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2218
					DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
2175
						 pp_lib_thermal_controller_names[controller->ucType],
2219
						 pp_lib_thermal_controller_names[controller->ucType],
2176
						 controller->ucI2cAddress >> 1,
2220
						 controller->ucI2cAddress >> 1,
2177
						 (controller->ucFanParameters &
2221
						 (controller->ucFanParameters &
2178
						  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2222
						  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
Line 2183... Line 2227...
2183
						const char *name = pp_lib_thermal_controller_names[controller->ucType];
2227
						const char *name = pp_lib_thermal_controller_names[controller->ucType];
2184
						info.addr = controller->ucI2cAddress >> 1;
2228
						info.addr = controller->ucI2cAddress >> 1;
2185
						strlcpy(info.type, name, sizeof(info.type));
2229
						strlcpy(info.type, name, sizeof(info.type));
2186
						i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2230
						i2c_new_device(&rdev->pm.i2c_bus->adapter, &info);
2187
					}
2231
					}
-
 
2232
		} else {
-
 
2233
			DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
-
 
2234
				 controller->ucType,
-
 
2235
				 controller->ucI2cAddress >> 1,
-
 
2236
				 (controller->ucFanParameters &
-
 
2237
				  ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
2188
				}
2238
				}
2189
			}
2239
			}
2190
}
2240
}
Line 2191... Line 2241...
2191
 
2241
 
Line 2255... Line 2305...
2255
						rdev->pm.power_state[state_index].type =
2305
						rdev->pm.power_state[state_index].type =
2256
							POWER_STATE_TYPE_DEFAULT;
2306
							POWER_STATE_TYPE_DEFAULT;
2257
						rdev->pm.default_power_state_index = state_index;
2307
						rdev->pm.default_power_state_index = state_index;
2258
						rdev->pm.power_state[state_index].default_clock_mode =
2308
						rdev->pm.power_state[state_index].default_clock_mode =
2259
							&rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2309
							&rdev->pm.power_state[state_index].clock_info[mode_index - 1];
2260
		if (ASIC_IS_DCE5(rdev)) {
2310
		if (ASIC_IS_DCE5(rdev) && !(rdev->flags & RADEON_IS_IGP)) {
2261
			/* NI chips post without MC ucode, so default clocks are strobe mode only */
2311
			/* NI chips post without MC ucode, so default clocks are strobe mode only */
2262
			rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2312
			rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk;
2263
			rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2313
			rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk;
2264
			rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
2314
			rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage;
2265
			rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
2315
			rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci;
Line 2281... Line 2331...
2281
static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2331
static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev,
2282
						   int state_index, int mode_index,
2332
						   int state_index, int mode_index,
2283
						   union pplib_clock_info *clock_info)
2333
						   union pplib_clock_info *clock_info)
2284
{
2334
{
2285
	u32 sclk, mclk;
2335
	u32 sclk, mclk;
-
 
2336
	u16 vddc;
Line 2286... Line 2337...
2286
 
2337
 
2287
	if (rdev->flags & RADEON_IS_IGP) {
2338
	if (rdev->flags & RADEON_IS_IGP) {
2288
		if (rdev->family >= CHIP_PALM) {
2339
		if (rdev->family >= CHIP_PALM) {
2289
			sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2340
			sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
Line 2292... Line 2343...
2292
		} else {
2343
		} else {
2293
			sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2344
			sclk = le16_to_cpu(clock_info->rs780.usLowEngineClockLow);
2294
			sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2345
			sclk |= clock_info->rs780.ucLowEngineClockHigh << 16;
2295
			rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2346
			rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
2296
		}
2347
		}
-
 
2348
	} else if (ASIC_IS_DCE6(rdev)) {
-
 
2349
		sclk = le16_to_cpu(clock_info->si.usEngineClockLow);
-
 
2350
		sclk |= clock_info->si.ucEngineClockHigh << 16;
-
 
2351
		mclk = le16_to_cpu(clock_info->si.usMemoryClockLow);
-
 
2352
		mclk |= clock_info->si.ucMemoryClockHigh << 16;
-
 
2353
		rdev->pm.power_state[state_index].clock_info[mode_index].mclk = mclk;
-
 
2354
		rdev->pm.power_state[state_index].clock_info[mode_index].sclk = sclk;
-
 
2355
		rdev->pm.power_state[state_index].clock_info[mode_index].voltage.type =
-
 
2356
			VOLTAGE_SW;
-
 
2357
		rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
-
 
2358
			le16_to_cpu(clock_info->si.usVDDC);
-
 
2359
		rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci =
-
 
2360
			le16_to_cpu(clock_info->si.usVDDCI);
2297
	} else if (ASIC_IS_DCE4(rdev)) {
2361
	} else if (ASIC_IS_DCE4(rdev)) {
2298
		sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2362
		sclk = le16_to_cpu(clock_info->evergreen.usEngineClockLow);
2299
		sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2363
		sclk |= clock_info->evergreen.ucEngineClockHigh << 16;
2300
		mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2364
		mclk = le16_to_cpu(clock_info->evergreen.usMemoryClockLow);
2301
		mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
2365
		mclk |= clock_info->evergreen.ucMemoryClockHigh << 16;
Line 2319... Line 2383...
2319
		rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2383
		rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage =
2320
			le16_to_cpu(clock_info->r600.usVDDC);
2384
			le16_to_cpu(clock_info->r600.usVDDC);
2321
	}
2385
	}
Line 2322... Line 2386...
2322
 
2386
 
2323
	/* patch up vddc if necessary */
2387
	/* patch up vddc if necessary */
2324
	if (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage == 0xff01) {
2388
	switch (rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage) {
2325
		u16 vddc;
-
 
-
 
2389
	case ATOM_VIRTUAL_VOLTAGE_ID0:
-
 
2390
	case ATOM_VIRTUAL_VOLTAGE_ID1:
-
 
2391
	case ATOM_VIRTUAL_VOLTAGE_ID2:
2326
 
2392
	case ATOM_VIRTUAL_VOLTAGE_ID3:
-
 
2393
		if (radeon_atom_get_max_vddc(rdev, VOLTAGE_TYPE_VDDC,
-
 
2394
					     rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage,
2327
		if (radeon_atom_get_max_vddc(rdev, &vddc) == 0)
2395
					     &vddc) == 0)
-
 
2396
			rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
-
 
2397
		break;
-
 
2398
	default:
2328
			rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = vddc;
2399
		break;
Line 2329... Line 2400...
2329
	}
2400
	}
2330
 
2401
 
2331
	if (rdev->flags & RADEON_IS_IGP) {
2402
	if (rdev->flags & RADEON_IS_IGP) {
Line 2375... Line 2446...
2375
		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2446
		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2376
			(mode_info->atom_context->bios + data_offset +
2447
			(mode_info->atom_context->bios + data_offset +
2377
			 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2448
			 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset) +
2378
			 (power_state->v1.ucNonClockStateIndex *
2449
			 (power_state->v1.ucNonClockStateIndex *
2379
			  power_info->pplib.ucNonClockSize));
2450
			  power_info->pplib.ucNonClockSize));
-
 
2451
		rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
-
 
2452
							     ((power_info->pplib.ucStateEntrySize - 1) ?
-
 
2453
							      (power_info->pplib.ucStateEntrySize - 1) : 1),
-
 
2454
							     GFP_KERNEL);
-
 
2455
		if (!rdev->pm.power_state[i].clock_info)
-
 
2456
			return state_index;
-
 
2457
		if (power_info->pplib.ucStateEntrySize - 1) {
2380
		for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2458
		for (j = 0; j < (power_info->pplib.ucStateEntrySize - 1); j++) {
2381
			clock_info = (union pplib_clock_info *)
2459
			clock_info = (union pplib_clock_info *)
2382
				(mode_info->atom_context->bios + data_offset +
2460
				(mode_info->atom_context->bios + data_offset +
2383
				 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2461
				 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset) +
2384
				 (power_state->v1.ucClockStateIndices[j] *
2462
				 (power_state->v1.ucClockStateIndices[j] *
Line 2387... Line 2465...
2387
								       state_index, mode_index,
2465
								       state_index, mode_index,
2388
								       clock_info);
2466
								       clock_info);
2389
			if (valid)
2467
			if (valid)
2390
				mode_index++;
2468
				mode_index++;
2391
		}
2469
		}
-
 
2470
		} else {
-
 
2471
			rdev->pm.power_state[state_index].clock_info[0].mclk =
-
 
2472
				rdev->clock.default_mclk;
-
 
2473
			rdev->pm.power_state[state_index].clock_info[0].sclk =
-
 
2474
				rdev->clock.default_sclk;
-
 
2475
			mode_index++;
-
 
2476
		}
2392
		rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2477
		rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2393
		if (mode_index) {
2478
		if (mode_index) {
2394
			radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2479
			radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2395
								   non_clock_info);
2480
								   non_clock_info);
2396
			state_index++;
2481
			state_index++;
Line 2419... Line 2504...
2419
	struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2504
	struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2420
	union pplib_power_state *power_state;
2505
	union pplib_power_state *power_state;
2421
	int i, j, non_clock_array_index, clock_array_index;
2506
	int i, j, non_clock_array_index, clock_array_index;
2422
	int state_index = 0, mode_index = 0;
2507
	int state_index = 0, mode_index = 0;
2423
	union pplib_clock_info *clock_info;
2508
	union pplib_clock_info *clock_info;
2424
	struct StateArray *state_array;
2509
	struct _StateArray *state_array;
2425
	struct ClockInfoArray *clock_info_array;
2510
	struct _ClockInfoArray *clock_info_array;
2426
	struct NonClockInfoArray *non_clock_info_array;
2511
	struct _NonClockInfoArray *non_clock_info_array;
2427
	bool valid;
2512
	bool valid;
2428
	union power_info *power_info;
2513
	union power_info *power_info;
2429
	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2514
	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2430
        u16 data_offset;
2515
        u16 data_offset;
2431
	u8 frev, crev;
2516
	u8 frev, crev;
Line 2434... Line 2519...
2434
				   &frev, &crev, &data_offset))
2519
				   &frev, &crev, &data_offset))
2435
		return state_index;
2520
		return state_index;
2436
	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2521
	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
Line 2437... Line 2522...
2437
 
2522
 
2438
	radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2523
	radeon_atombios_add_pplib_thermal_controller(rdev, &power_info->pplib.sThermalController);
2439
	state_array = (struct StateArray *)
2524
	state_array = (struct _StateArray *)
2440
		(mode_info->atom_context->bios + data_offset +
2525
		(mode_info->atom_context->bios + data_offset +
2441
		 le16_to_cpu(power_info->pplib.usStateArrayOffset));
2526
		 le16_to_cpu(power_info->pplib.usStateArrayOffset));
2442
	clock_info_array = (struct ClockInfoArray *)
2527
	clock_info_array = (struct _ClockInfoArray *)
2443
		(mode_info->atom_context->bios + data_offset +
2528
		(mode_info->atom_context->bios + data_offset +
2444
		 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
2529
		 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
2445
	non_clock_info_array = (struct NonClockInfoArray *)
2530
	non_clock_info_array = (struct _NonClockInfoArray *)
2446
		(mode_info->atom_context->bios + data_offset +
2531
		(mode_info->atom_context->bios + data_offset +
2447
		 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
2532
		 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
2448
	rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2533
	rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state) *
2449
				       state_array->ucNumEntries, GFP_KERNEL);
2534
				       state_array->ucNumEntries, GFP_KERNEL);
Line 2454... Line 2539...
2454
		power_state = (union pplib_power_state *)&state_array->states[i];
2539
		power_state = (union pplib_power_state *)&state_array->states[i];
2455
		/* XXX this might be an inagua bug... */
2540
		/* XXX this might be an inagua bug... */
2456
		non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
2541
		non_clock_array_index = i; /* power_state->v2.nonClockInfoIndex */
2457
		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2542
		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2458
			&non_clock_info_array->nonClockInfo[non_clock_array_index];
2543
			&non_clock_info_array->nonClockInfo[non_clock_array_index];
-
 
2544
		rdev->pm.power_state[i].clock_info = kzalloc(sizeof(struct radeon_pm_clock_info) *
-
 
2545
							     (power_state->v2.ucNumDPMLevels ?
-
 
2546
							      power_state->v2.ucNumDPMLevels : 1),
-
 
2547
							     GFP_KERNEL);
-
 
2548
		if (!rdev->pm.power_state[i].clock_info)
-
 
2549
			return state_index;
-
 
2550
		if (power_state->v2.ucNumDPMLevels) {
2459
		for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2551
		for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2460
			clock_array_index = power_state->v2.clockInfoIndex[j];
2552
			clock_array_index = power_state->v2.clockInfoIndex[j];
2461
			/* XXX this might be an inagua bug... */
2553
			/* XXX this might be an inagua bug... */
2462
			if (clock_array_index >= clock_info_array->ucNumEntries)
2554
			if (clock_array_index >= clock_info_array->ucNumEntries)
2463
				continue;
2555
				continue;
2464
			clock_info = (union pplib_clock_info *)
2556
			clock_info = (union pplib_clock_info *)
2465
				&clock_info_array->clockInfo[clock_array_index];
2557
					&clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
2466
			valid = radeon_atombios_parse_pplib_clock_info(rdev,
2558
			valid = radeon_atombios_parse_pplib_clock_info(rdev,
2467
								       state_index, mode_index,
2559
								       state_index, mode_index,
2468
								       clock_info);
2560
								       clock_info);
2469
			if (valid)
2561
			if (valid)
2470
				mode_index++;
2562
				mode_index++;
2471
		}
2563
		}
-
 
2564
		} else {
-
 
2565
			rdev->pm.power_state[state_index].clock_info[0].mclk =
-
 
2566
				rdev->clock.default_mclk;
-
 
2567
			rdev->pm.power_state[state_index].clock_info[0].sclk =
-
 
2568
				rdev->clock.default_sclk;
-
 
2569
			mode_index++;
-
 
2570
		}
2472
		rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2571
		rdev->pm.power_state[state_index].num_clock_modes = mode_index;
2473
		if (mode_index) {
2572
		if (mode_index) {
2474
			radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2573
			radeon_atombios_parse_pplib_non_clock_info(rdev, state_index, mode_index,
2475
								   non_clock_info);
2574
								   non_clock_info);
2476
					state_index++;
2575
					state_index++;
Line 2522... Line 2621...
2522
			break;
2621
			break;
2523
		}
2622
		}
2524
	} else {
2623
	} else {
2525
		rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2624
		rdev->pm.power_state = kzalloc(sizeof(struct radeon_power_state), GFP_KERNEL);
2526
		if (rdev->pm.power_state) {
2625
		if (rdev->pm.power_state) {
-
 
2626
			rdev->pm.power_state[0].clock_info =
-
 
2627
				kzalloc(sizeof(struct radeon_pm_clock_info) * 1, GFP_KERNEL);
-
 
2628
			if (rdev->pm.power_state[0].clock_info) {
2527
		/* add the default mode */
2629
		/* add the default mode */
2528
		rdev->pm.power_state[state_index].type =
2630
		rdev->pm.power_state[state_index].type =
2529
			POWER_STATE_TYPE_DEFAULT;
2631
			POWER_STATE_TYPE_DEFAULT;
2530
		rdev->pm.power_state[state_index].num_clock_modes = 1;
2632
		rdev->pm.power_state[state_index].num_clock_modes = 1;
2531
		rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
2633
		rdev->pm.power_state[state_index].clock_info[0].mclk = rdev->clock.default_mclk;
Line 2537... Line 2639...
2537
		rdev->pm.default_power_state_index = state_index;
2639
		rdev->pm.default_power_state_index = state_index;
2538
		rdev->pm.power_state[state_index].flags = 0;
2640
		rdev->pm.power_state[state_index].flags = 0;
2539
		state_index++;
2641
		state_index++;
2540
	}
2642
	}
2541
	}
2643
	}
-
 
2644
	}
Line 2542... Line 2645...
2542
 
2645
 
Line 2543... Line 2646...
2543
	rdev->pm.num_power_states = state_index;
2646
	rdev->pm.num_power_states = state_index;
2544
 
2647
 
-
 
2648
	rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
-
 
2649
	rdev->pm.current_clock_mode_index = 0;
2545
	rdev->pm.current_power_state_index = rdev->pm.default_power_state_index;
2650
	if (rdev->pm.default_power_state_index >= 0)
-
 
2651
		rdev->pm.current_vddc =
-
 
2652
			rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2546
	rdev->pm.current_clock_mode_index = 0;
2653
	else
Line 2547... Line 2654...
2547
	rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage;
2654
		rdev->pm.current_vddc = 0;
2548
}
2655
}
2549
 
2656
 
Line 2602... Line 2709...
2602
 
2709
 
2603
union set_voltage {
2710
union set_voltage {
2604
	struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2711
	struct _SET_VOLTAGE_PS_ALLOCATION alloc;
2605
	struct _SET_VOLTAGE_PARAMETERS v1;
2712
	struct _SET_VOLTAGE_PARAMETERS v1;
-
 
2713
	struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2606
	struct _SET_VOLTAGE_PARAMETERS_V2 v2;
2714
	struct _SET_VOLTAGE_PARAMETERS_V1_3 v3;
Line 2607... Line 2715...
2607
};
2715
};
2608
 
2716
 
2609
void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
2717
void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type)
Line 2628... Line 2736...
2628
	case 2:
2736
	case 2:
2629
		args.v2.ucVoltageType = voltage_type;
2737
		args.v2.ucVoltageType = voltage_type;
2630
		args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2738
		args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE;
2631
		args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
2739
		args.v2.usVoltageLevel = cpu_to_le16(voltage_level);
2632
		break;
2740
		break;
-
 
2741
	case 3:
-
 
2742
		args.v3.ucVoltageType = voltage_type;
-
 
2743
		args.v3.ucVoltageMode = ATOM_SET_VOLTAGE;
-
 
2744
		args.v3.usVoltageLevel = cpu_to_le16(voltage_level);
-
 
2745
		break;
2633
	default:
2746
	default:
2634
		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2747
		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2635
		return;
2748
		return;
2636
	}
2749
	}
Line 2637... Line 2750...
2637
 
2750
 
2638
	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2751
	atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
Line 2639... Line 2752...
2639
}
2752
}
2640
 
2753
 
2641
int radeon_atom_get_max_vddc(struct radeon_device *rdev,
2754
static int radeon_atom_get_max_vddc(struct radeon_device *rdev, u8 voltage_type,
2642
			     u16 *voltage)
2755
				    u16 voltage_id, u16 *voltage)
2643
{
2756
{
2644
	union set_voltage args;
2757
	union set_voltage args;
Line 2658... Line 2771...
2658
 
2771
 
Line 2659... Line 2772...
2659
		atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2772
		atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
2660
 
2773
 
-
 
2774
		*voltage = le16_to_cpu(args.v2.usVoltageLevel);
-
 
2775
		break;
-
 
2776
	case 3:
-
 
2777
		args.v3.ucVoltageType = voltage_type;
-
 
2778
		args.v3.ucVoltageMode = ATOM_GET_VOLTAGE_LEVEL;
-
 
2779
		args.v3.usVoltageLevel = cpu_to_le16(voltage_id);
-
 
2780
 
-
 
2781
		atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args);
-
 
2782
 
2661
		*voltage = le16_to_cpu(args.v2.usVoltageLevel);
2783
		*voltage = le16_to_cpu(args.v3.usVoltageLevel);
2662
		break;
2784
		break;
2663
	default:
2785
	default:
2664
		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
2786
		DRM_ERROR("Unknown table version %d, %d\n", frev, crev);
Line 2909... Line 3031...
2909
			bios_0_scratch &= ~ATOM_S0_DFP5;
3031
			bios_0_scratch &= ~ATOM_S0_DFP5;
2910
			bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
3032
			bios_3_scratch &= ~ATOM_S3_DFP5_ACTIVE;
2911
			bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
3033
			bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP5;
2912
		}
3034
		}
2913
	}
3035
	}
-
 
3036
	if ((radeon_encoder->devices & ATOM_DEVICE_DFP6_SUPPORT) &&
-
 
3037
	    (radeon_connector->devices & ATOM_DEVICE_DFP6_SUPPORT)) {
-
 
3038
		if (connected) {
-
 
3039
			DRM_DEBUG_KMS("DFP6 connected\n");
-
 
3040
			bios_0_scratch |= ATOM_S0_DFP6;
-
 
3041
			bios_3_scratch |= ATOM_S3_DFP6_ACTIVE;
-
 
3042
			bios_6_scratch |= ATOM_S6_ACC_REQ_DFP6;
-
 
3043
		} else {
-
 
3044
			DRM_DEBUG_KMS("DFP6 disconnected\n");
-
 
3045
			bios_0_scratch &= ~ATOM_S0_DFP6;
-
 
3046
			bios_3_scratch &= ~ATOM_S3_DFP6_ACTIVE;
-
 
3047
			bios_6_scratch &= ~ATOM_S6_ACC_REQ_DFP6;
-
 
3048
		}
-
 
3049
	}
Line 2914... Line 3050...
2914
 
3050
 
2915
	if (rdev->family >= CHIP_R600) {
3051
	if (rdev->family >= CHIP_R600) {
2916
		WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
3052
		WREG32(R600_BIOS_0_SCRATCH, bios_0_scratch);
2917
		WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
3053
		WREG32(R600_BIOS_3_SCRATCH, bios_3_scratch);
Line 2929... Line 3065...
2929
	struct drm_device *dev = encoder->dev;
3065
	struct drm_device *dev = encoder->dev;
2930
	struct radeon_device *rdev = dev->dev_private;
3066
	struct radeon_device *rdev = dev->dev_private;
2931
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3067
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2932
	uint32_t bios_3_scratch;
3068
	uint32_t bios_3_scratch;
Line -... Line 3069...
-
 
3069
 
-
 
3070
	if (ASIC_IS_DCE4(rdev))
-
 
3071
		return;
2933
 
3072
 
2934
	if (rdev->family >= CHIP_R600)
3073
	if (rdev->family >= CHIP_R600)
2935
		bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
3074
		bios_3_scratch = RREG32(R600_BIOS_3_SCRATCH);
2936
	else
3075
	else
Line 2981... Line 3120...
2981
	struct drm_device *dev = encoder->dev;
3120
	struct drm_device *dev = encoder->dev;
2982
	struct radeon_device *rdev = dev->dev_private;
3121
	struct radeon_device *rdev = dev->dev_private;
2983
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
3122
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
2984
	uint32_t bios_2_scratch;
3123
	uint32_t bios_2_scratch;
Line -... Line 3124...
-
 
3124
 
-
 
3125
	if (ASIC_IS_DCE4(rdev))
-
 
3126
		return;
2985
 
3127
 
2986
	if (rdev->family >= CHIP_R600)
3128
	if (rdev->family >= CHIP_R600)
2987
		bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
3129
		bios_2_scratch = RREG32(R600_BIOS_2_SCRATCH);
2988
	else
3130
	else