Subversion Repositories Kolibri OS

Rev

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

Rev 1430 Rev 1963
Line 33... Line 33...
33
/*
33
/*
34
 * check if the chipset is supported
34
 * check if the chipset is supported
35
 */
35
 */
36
static int r600_audio_chipset_supported(struct radeon_device *rdev)
36
static int r600_audio_chipset_supported(struct radeon_device *rdev)
37
{
37
{
38
	return rdev->family >= CHIP_R600
38
	return (rdev->family >= CHIP_R600 && rdev->family < CHIP_CEDAR)
39
		|| rdev->family == CHIP_RS600
39
		|| rdev->family == CHIP_RS600
40
		|| rdev->family == CHIP_RS690
40
		|| rdev->family == CHIP_RS690
41
		|| rdev->family == CHIP_RS740;
41
		|| rdev->family == CHIP_RS740;
42
}
42
}
Line 43... Line 43...
43
 
43
 
44
/*
44
/*
45
 * current number of channels
45
 * current number of channels
46
 */
46
 */
47
static int r600_audio_channels(struct radeon_device *rdev)
47
int r600_audio_channels(struct radeon_device *rdev)
48
{
48
{
49
	return (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0x7) + 1;
49
	return (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0x7) + 1;
Line 50... Line 50...
50
}
50
}
51
 
51
 
52
/*
52
/*
53
 * current bits per sample
53
 * current bits per sample
54
 */
54
 */
55
static int r600_audio_bits_per_sample(struct radeon_device *rdev)
55
int r600_audio_bits_per_sample(struct radeon_device *rdev)
56
{
56
{
57
	uint32_t value = (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0xF0) >> 4;
57
	uint32_t value = (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0xF0) >> 4;
58
	switch (value) {
58
	switch (value) {
59
	case 0x0: return  8;
59
	case 0x0: return  8;
60
	case 0x1: return 16;
60
	case 0x1: return 16;
61
	case 0x2: return 20;
61
	case 0x2: return 20;
62
	case 0x3: return 24;
62
	case 0x3: return 24;
Line 63... Line 63...
63
	case 0x4: return 32;
63
	case 0x4: return 32;
-
 
64
	}
Line 64... Line 65...
64
	}
65
 
65
 
66
	dev_err(rdev->dev, "Unknown bits per sample 0x%x using 16 instead\n",
Line 66... Line 67...
66
	DRM_ERROR("Unknown bits per sample 0x%x using 16 instead.\n", (int)value);
67
		(int)value);
67
 
68
 
68
	return 16;
69
	return 16;
69
}
70
}
70
 
71
 
71
/*
72
/*
72
 * current sampling rate in HZ
73
 * current sampling rate in HZ
Line 73... Line 74...
73
 */
74
 */
Line 88... Line 89...
88
}
89
}
Line 89... Line 90...
89
 
90
 
90
/*
91
/*
91
 * iec 60958 status bits
92
 * iec 60958 status bits
92
 */
93
 */
93
static uint8_t r600_audio_status_bits(struct radeon_device *rdev)
94
uint8_t r600_audio_status_bits(struct radeon_device *rdev)
94
{
95
{
95
	return RREG32(R600_AUDIO_STATUS_BITS) & 0xff;
96
	return RREG32(R600_AUDIO_STATUS_BITS) & 0xff;
Line 96... Line 97...
96
}
97
}
97
 
98
 
98
/*
99
/*
99
 * iec 60958 category code
100
 * iec 60958 category code
100
 */
101
 */
101
static uint8_t r600_audio_category_code(struct radeon_device *rdev)
102
uint8_t r600_audio_category_code(struct radeon_device *rdev)
102
{
103
{
Line 103... Line 104...
103
	return (RREG32(R600_AUDIO_STATUS_BITS) >> 8) & 0xff;
104
	return (RREG32(R600_AUDIO_STATUS_BITS) >> 8) & 0xff;
Line 116... Line 117...
116
	int bps = r600_audio_bits_per_sample(rdev);
117
	int bps = r600_audio_bits_per_sample(rdev);
117
	uint8_t status_bits = r600_audio_status_bits(rdev);
118
	uint8_t status_bits = r600_audio_status_bits(rdev);
118
	uint8_t category_code = r600_audio_category_code(rdev);
119
	uint8_t category_code = r600_audio_category_code(rdev);
Line 119... Line 120...
119
 
120
 
120
	struct drm_encoder *encoder;
121
	struct drm_encoder *encoder;
Line 121... Line 122...
121
	int changes = 0;
122
	int changes = 0, still_going = 0;
122
 
123
 
123
	changes |= channels != rdev->audio_channels;
124
	changes |= channels != rdev->audio_channels;
124
	changes |= rate != rdev->audio_rate;
125
	changes |= rate != rdev->audio_rate;
Line 133... Line 134...
133
		rdev->audio_status_bits = status_bits;
134
		rdev->audio_status_bits = status_bits;
134
		rdev->audio_category_code = category_code;
135
		rdev->audio_category_code = category_code;
135
	}
136
	}
Line 136... Line 137...
136
 
137
 
-
 
138
	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
-
 
139
		struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
137
	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
140
		still_going |= radeon_encoder->audio_polling_active;
138
		if (changes || r600_hdmi_buffer_status_changed(encoder))
141
		if (changes || r600_hdmi_buffer_status_changed(encoder))
139
			r600_hdmi_update_audio_settings(
-
 
140
				encoder, channels,
-
 
141
				rate, bps, status_bits,
-
 
142
				category_code);
142
			r600_hdmi_update_audio_settings(encoder);
Line 143... Line 143...
143
	}
143
	}
144
 
144
 
145
//   mod_timer(&rdev->audio_timer,
145
//   mod_timer(&rdev->audio_timer,
Line 149... Line 149...
149
/*
149
/*
150
 * turn on/off audio engine
150
 * turn on/off audio engine
151
 */
151
 */
152
static void r600_audio_engine_enable(struct radeon_device *rdev, bool enable)
152
static void r600_audio_engine_enable(struct radeon_device *rdev, bool enable)
153
{
153
{
154
	DRM_INFO("%s audio support", enable ? "Enabling" : "Disabling");
154
	DRM_INFO("%s audio support\n", enable ? "Enabling" : "Disabling");
155
	WREG32_P(R600_AUDIO_ENABLE, enable ? 0x81000000 : 0x0, ~0x81000000);
155
	WREG32_P(R600_AUDIO_ENABLE, enable ? 0x81000000 : 0x0, ~0x81000000);
-
 
156
	rdev->audio_enabled = enable;
156
}
157
}
Line 157... Line 158...
157
 
158
 
158
/*
159
/*
159
 * initialize the audio vars and register the update timer
160
 * initialize the audio vars and register the update timer
Line 180... Line 181...
180
 
181
 
181
	return 0;
182
	return 0;
Line 182... Line 183...
182
}
183
}
183
 
-
 
184
/*
-
 
185
 * determin how the encoders and audio interface is wired together
-
 
186
 */
-
 
187
int r600_audio_tmds_index(struct drm_encoder *encoder)
-
 
188
{
-
 
189
	struct drm_device *dev = encoder->dev;
-
 
190
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
-
 
191
	struct drm_encoder *other;
-
 
192
 
-
 
193
	switch (radeon_encoder->encoder_id) {
-
 
194
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
-
 
195
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
-
 
196
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
-
 
197
		return 0;
-
 
198
 
-
 
199
	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
-
 
200
		/* special case check if an TMDS1 is present */
-
 
201
		list_for_each_entry(other, &dev->mode_config.encoder_list, head) {
-
 
202
			if (to_radeon_encoder(other)->encoder_id ==
-
 
203
				ENCODER_OBJECT_ID_INTERNAL_TMDS1)
-
 
204
				return 1;
-
 
205
		}
-
 
206
		return 0;
-
 
207
 
-
 
208
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
-
 
209
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
-
 
210
		return 1;
-
 
211
 
-
 
212
	default:
-
 
213
		DRM_ERROR("Unsupported encoder type 0x%02X\n",
-
 
214
			  radeon_encoder->encoder_id);
-
 
215
		return -1;
-
 
216
	}
-
 
217
}
-
 
218
 
184
 
219
/*
185
/*
220
 * atach the audio codec to the clock source of the encoder
186
 * atach the audio codec to the clock source of the encoder
221
 */
187
 */
222
void r600_audio_set_clock(struct drm_encoder *encoder, int clock)
188
void r600_audio_set_clock(struct drm_encoder *encoder, int clock)
223
{
189
{
224
	struct drm_device *dev = encoder->dev;
190
	struct drm_device *dev = encoder->dev;
-
 
191
	struct radeon_device *rdev = dev->dev_private;
225
	struct radeon_device *rdev = dev->dev_private;
192
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
Line 226... Line 193...
226
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
193
	struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
227
	int base_rate = 48000;
194
	int base_rate = 48000;
228
 
195
 
229
	switch (radeon_encoder->encoder_id) {
196
	switch (radeon_encoder->encoder_id) {
230
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
197
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
231
	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
-
 
232
		WREG32_P(R600_AUDIO_TIMING, 0, ~0x301);
198
	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
233
		break;
199
		WREG32_P(R600_AUDIO_TIMING, 0, ~0x301);
234
 
200
		break;
235
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
201
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
236
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
202
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
237
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
203
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
238
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
-
 
239
		WREG32_P(R600_AUDIO_TIMING, 0x100, ~0x301);
204
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
240
		break;
205
		WREG32_P(R600_AUDIO_TIMING, 0x100, ~0x301);
241
 
206
		break;
242
	default:
207
	default:
243
		DRM_ERROR("Unsupported encoder type 0x%02X\n",
208
		dev_err(rdev->dev, "Unsupported encoder type 0x%02X\n",
Line 244... Line 209...
244
			  radeon_encoder->encoder_id);
209
			  radeon_encoder->encoder_id);
245
		return;
210
		return;
246
	}
211
	}
247
 
212
 
248
	switch (r600_audio_tmds_index(encoder)) {
213
	switch (dig->dig_encoder) {
249
	case 0:
214
	case 0:
Line 255... Line 220...
255
	case 1:
220
	case 1:
256
		WREG32(R600_AUDIO_PLL2_MUL, base_rate*50);
221
		WREG32(R600_AUDIO_PLL2_MUL, base_rate * 50);
257
		WREG32(R600_AUDIO_PLL2_DIV, clock*100);
222
		WREG32(R600_AUDIO_PLL2_DIV, clock * 100);
258
		WREG32(R600_AUDIO_CLK_SRCSEL, 1);
223
		WREG32(R600_AUDIO_CLK_SRCSEL, 1);
259
		break;
224
		break;
-
 
225
	default:
-
 
226
		dev_err(rdev->dev, "Unsupported DIG on encoder 0x%02X\n",
-
 
227
			  radeon_encoder->encoder_id);
-
 
228
		return;
260
	}
229
	}
261
}
230
}
Line 262... Line 231...
262
 
231
 
263
/*
232
/*
264
 * release the audio timer
233
 * release the audio timer
265
 * TODO: How to do this correctly on SMP systems?
234
 * TODO: How to do this correctly on SMP systems?
266
 */
235
 */
267
void r600_audio_fini(struct radeon_device *rdev)
236
void r600_audio_fini(struct radeon_device *rdev)
268
{
237
{
269
	if (!radeon_audio || !r600_audio_chipset_supported(rdev))
238
	if (!rdev->audio_enabled)
Line 270... Line 239...
270
		return;
239
		return;
Line 271... Line 240...
271
 
240