Subversion Repositories Kolibri OS

Rev

Rev 1430 | Rev 2005 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1403 serge 1
/*
2
 * Copyright 2008 Advanced Micro Devices, Inc.
3
 * Copyright 2008 Red Hat Inc.
4
 * Copyright 2009 Christian König.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a
7
 * copy of this software and associated documentation files (the "Software"),
8
 * to deal in the Software without restriction, including without limitation
9
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
 * and/or sell copies of the Software, and to permit persons to whom the
11
 * Software is furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
 * OTHER DEALINGS IN THE SOFTWARE.
23
 *
24
 * Authors: Christian König
25
 */
26
#include "drmP.h"
27
#include "radeon.h"
28
#include "radeon_reg.h"
29
#include "atom.h"
30
 
31
#define AUDIO_TIMER_INTERVALL 100 /* 1/10 sekund should be enough */
32
 
33
/*
34
 * check if the chipset is supported
35
 */
36
static int r600_audio_chipset_supported(struct radeon_device *rdev)
37
{
1963 serge 38
	return (rdev->family >= CHIP_R600 && rdev->family < CHIP_CEDAR)
1403 serge 39
		|| rdev->family == CHIP_RS600
40
		|| rdev->family == CHIP_RS690
41
		|| rdev->family == CHIP_RS740;
42
}
43
 
44
/*
45
 * current number of channels
46
 */
1963 serge 47
int r600_audio_channels(struct radeon_device *rdev)
1403 serge 48
{
49
	return (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0x7) + 1;
50
}
51
 
52
/*
53
 * current bits per sample
54
 */
1963 serge 55
int r600_audio_bits_per_sample(struct radeon_device *rdev)
1403 serge 56
{
57
	uint32_t value = (RREG32(R600_AUDIO_RATE_BPS_CHANNEL) & 0xF0) >> 4;
58
	switch (value) {
59
	case 0x0: return  8;
60
	case 0x1: return 16;
61
	case 0x2: return 20;
62
	case 0x3: return 24;
63
	case 0x4: return 32;
64
	}
65
 
1963 serge 66
	dev_err(rdev->dev, "Unknown bits per sample 0x%x using 16 instead\n",
67
		(int)value);
1403 serge 68
 
69
	return 16;
70
}
71
 
72
/*
73
 * current sampling rate in HZ
74
 */
1963 serge 75
int r600_audio_rate(struct radeon_device *rdev)
1403 serge 76
{
77
	uint32_t value = RREG32(R600_AUDIO_RATE_BPS_CHANNEL);
78
	uint32_t result;
79
 
80
	if (value & 0x4000)
81
		result = 44100;
82
	else
83
		result = 48000;
84
 
85
	result *= ((value >> 11) & 0x7) + 1;
86
	result /= ((value >> 8) & 0x7) + 1;
87
 
88
	return result;
89
}
90
 
91
/*
92
 * iec 60958 status bits
93
 */
1963 serge 94
uint8_t r600_audio_status_bits(struct radeon_device *rdev)
1403 serge 95
{
96
	return RREG32(R600_AUDIO_STATUS_BITS) & 0xff;
97
}
98
 
99
/*
100
 * iec 60958 category code
101
 */
1963 serge 102
uint8_t r600_audio_category_code(struct radeon_device *rdev)
1403 serge 103
{
104
	return (RREG32(R600_AUDIO_STATUS_BITS) >> 8) & 0xff;
105
}
106
 
107
/*
108
 * update all hdmi interfaces with current audio parameters
109
 */
110
static void r600_audio_update_hdmi(unsigned long param)
111
{
112
	struct radeon_device *rdev = (struct radeon_device *)param;
113
	struct drm_device *dev = rdev->ddev;
114
 
115
	int channels = r600_audio_channels(rdev);
116
	int rate = r600_audio_rate(rdev);
117
	int bps = r600_audio_bits_per_sample(rdev);
118
	uint8_t status_bits = r600_audio_status_bits(rdev);
119
	uint8_t category_code = r600_audio_category_code(rdev);
120
 
121
	struct drm_encoder *encoder;
1963 serge 122
	int changes = 0, still_going = 0;
1403 serge 123
 
124
	changes |= channels != rdev->audio_channels;
125
	changes |= rate != rdev->audio_rate;
126
	changes |= bps != rdev->audio_bits_per_sample;
127
	changes |= status_bits != rdev->audio_status_bits;
128
	changes |= category_code != rdev->audio_category_code;
129
 
130
	if (changes) {
131
		rdev->audio_channels = channels;
132
		rdev->audio_rate = rate;
133
		rdev->audio_bits_per_sample = bps;
134
		rdev->audio_status_bits = status_bits;
135
		rdev->audio_category_code = category_code;
136
	}
137
 
138
	list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
1963 serge 139
		struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
140
		still_going |= radeon_encoder->audio_polling_active;
1403 serge 141
		if (changes || r600_hdmi_buffer_status_changed(encoder))
1963 serge 142
			r600_hdmi_update_audio_settings(encoder);
1403 serge 143
	}
144
 
145
//   mod_timer(&rdev->audio_timer,
146
//       jiffies + msecs_to_jiffies(AUDIO_TIMER_INTERVALL));
147
}
148
 
149
/*
1430 serge 150
 * turn on/off audio engine
151
 */
152
static void r600_audio_engine_enable(struct radeon_device *rdev, bool enable)
153
{
1963 serge 154
	DRM_INFO("%s audio support\n", enable ? "Enabling" : "Disabling");
1430 serge 155
	WREG32_P(R600_AUDIO_ENABLE, enable ? 0x81000000 : 0x0, ~0x81000000);
1963 serge 156
	rdev->audio_enabled = enable;
1430 serge 157
}
158
 
159
/*
1403 serge 160
 * initialize the audio vars and register the update timer
161
 */
162
int r600_audio_init(struct radeon_device *rdev)
163
{
1430 serge 164
	if (!radeon_audio || !r600_audio_chipset_supported(rdev))
1403 serge 165
		return 0;
166
 
1430 serge 167
	r600_audio_engine_enable(rdev, true);
1403 serge 168
 
169
	rdev->audio_channels = -1;
170
	rdev->audio_rate = -1;
171
	rdev->audio_bits_per_sample = -1;
172
	rdev->audio_status_bits = 0;
173
	rdev->audio_category_code = 0;
174
 
175
//   setup_timer(
176
//       &rdev->audio_timer,
177
//       r600_audio_update_hdmi,
178
//       (unsigned long)rdev);
179
 
180
//   mod_timer(&rdev->audio_timer, jiffies + 1);
181
 
182
	return 0;
183
}
184
 
185
/*
186
 * atach the audio codec to the clock source of the encoder
187
 */
188
void r600_audio_set_clock(struct drm_encoder *encoder, int clock)
189
{
190
	struct drm_device *dev = encoder->dev;
191
	struct radeon_device *rdev = dev->dev_private;
192
	struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder);
1963 serge 193
	struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv;
1403 serge 194
	int base_rate = 48000;
195
 
196
	switch (radeon_encoder->encoder_id) {
197
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
198
	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
199
		WREG32_P(R600_AUDIO_TIMING, 0, ~0x301);
200
		break;
201
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
202
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
203
	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
204
	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
205
		WREG32_P(R600_AUDIO_TIMING, 0x100, ~0x301);
206
		break;
207
	default:
1963 serge 208
		dev_err(rdev->dev, "Unsupported encoder type 0x%02X\n",
1403 serge 209
			  radeon_encoder->encoder_id);
210
		return;
211
	}
212
 
1963 serge 213
	switch (dig->dig_encoder) {
1403 serge 214
	case 0:
1963 serge 215
		WREG32(R600_AUDIO_PLL1_MUL, base_rate * 50);
216
		WREG32(R600_AUDIO_PLL1_DIV, clock * 100);
1403 serge 217
		WREG32(R600_AUDIO_CLK_SRCSEL, 0);
218
		break;
219
 
220
	case 1:
1963 serge 221
		WREG32(R600_AUDIO_PLL2_MUL, base_rate * 50);
222
		WREG32(R600_AUDIO_PLL2_DIV, clock * 100);
1403 serge 223
		WREG32(R600_AUDIO_CLK_SRCSEL, 1);
224
		break;
1963 serge 225
	default:
226
		dev_err(rdev->dev, "Unsupported DIG on encoder 0x%02X\n",
227
			  radeon_encoder->encoder_id);
228
		return;
1403 serge 229
	}
230
}
231
 
232
/*
233
 * release the audio timer
234
 * TODO: How to do this correctly on SMP systems?
235
 */
236
void r600_audio_fini(struct radeon_device *rdev)
237
{
1963 serge 238
	if (!rdev->audio_enabled)
1403 serge 239
		return;
240
 
1430 serge 241
//	del_timer(&rdev->audio_timer);
1403 serge 242
 
1430 serge 243
	r600_audio_engine_enable(rdev, false);
1403 serge 244
}