1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
/*
* drivers/sound/vidc_audio.c
*
* Audio routines for the VIDC
*
* Copyright (C) 1997 Russell King <rmk@arm.uk.linux.org>
*/
#include <asm/hardware.h>
#include <asm/io.h>
#include <asm/system.h>
#include <asm/iomd.h>
#include "sound_config.h"
#include "vidc.h"
/*
* VIDC sound
*
* When using SERIAL SOUND mode (external DAC), the number of physical
* channels is fixed at 2. Therefore, the sample rate = vidc sample rate.
*/
static int vidc_adev;
static int vidc_audio_volume;
static int vidc_audio_rate;
static char vidc_audio_format;
static char vidc_audio_channels;
extern void vidc_update_filler(int bits, int channels);
int vidc_audio_get_volume(void)
{
return vidc_audio_volume;
}
int vidc_audio_set_volume(int newvol)
{
vidc_audio_volume = newvol;
return vidc_audio_volume;
}
static int vidc_audio_set_bits(int fmt)
{
switch (fmt)
{
case AFMT_QUERY:
break;
case AFMT_U8:
case AFMT_S8:
case AFMT_S16_LE:
vidc_audio_format = fmt;
vidc_update_filler(vidc_audio_format, vidc_audio_channels);
break;
default:
vidc_audio_format = AFMT_S16_LE;
vidc_update_filler(vidc_audio_format, vidc_audio_channels);
break;
}
return vidc_audio_format;
}
static int vidc_audio_set_rate(int rate)
{
if (rate)
{
int newsize, new2size;
vidc_audio_rate = ((500000 / rate) + 1) >> 1;
if (vidc_audio_rate < 3)
vidc_audio_rate = 3;
if (vidc_audio_rate > 255)
vidc_audio_rate = 255;
outl((vidc_audio_rate - 2) | 0xb0000000, IO_VIDC_BASE);
outl(0xb1000003, IO_VIDC_BASE);
newsize = (10000 / vidc_audio_rate) & ~3;
if (newsize < 208)
newsize = 208;
if (newsize > 4096)
newsize = 4096;
for (new2size = 128; new2size < newsize; new2size <<= 1);
if (new2size - newsize > newsize - (new2size >> 1))
new2size >>= 1;
dma_bufsize = new2size;
}
return 250000 / vidc_audio_rate;
}
static int vidc_audio_set_channels(int channels)
{
switch (channels)
{
case 0:
break;
case 1:
case 2:
vidc_audio_channels = channels;
vidc_update_filler(vidc_audio_format, vidc_audio_channels);
break;
default:
vidc_audio_channels = 2;
vidc_update_filler(vidc_audio_format, vidc_audio_channels);
break;
}
return vidc_audio_channels;
}
/*
* Open the device
*
* dev - device
* mode - mode to open device (logical OR of OPEN_READ and OPEN_WRITE)
*
* Called when opening the DMAbuf (dmabuf.c:259)
*/
static int vidc_audio_open(int dev, int mode)
{
if (vidc_busy)
return -EBUSY;
if ((mode & OPEN_READ) && (!mode & OPEN_WRITE))
{
/* This audio device doesn't have recording capability */
return -EIO;
}
vidc_busy = 1;
return 0;
}
/*
* Close the device
*
* dev - device
*
* Called when closing the DMAbuf (dmabuf.c:477)
* after halt_xfer
*/
static void vidc_audio_close(int dev)
{
vidc_busy = 0;
}
static int vidc_audio_ioctl(int dev, unsigned int cmd, caddr_t arg)
{
int ret;
switch (cmd)
{
case SOUND_PCM_WRITE_RATE:
if (get_user(ret, (int *) arg))
return -EFAULT;
ret = vidc_audio_set_rate(ret);
break;
case SOUND_PCM_READ_RATE:
ret = vidc_audio_set_rate(0);
break;
case SNDCTL_DSP_STEREO:
if (get_user(ret, (int *) arg))
return -EFAULT;
ret = vidc_audio_set_channels(ret + 1) - 1;
break;
case SOUND_PCM_WRITE_CHANNELS:
if (get_user(ret, (int *) arg))
return -EFAULT;
ret = vidc_audio_set_channels(ret);
break;
case SOUND_PCM_READ_CHANNELS:
ret = vidc_audio_set_channels(0);
break;
case SNDCTL_DSP_SETFMT:
if (get_user(ret, (int *) arg))
return -EFAULT;
ret = vidc_audio_set_bits(ret);
break;
case SOUND_PCM_READ_BITS:
ret = vidc_audio_set_bits(0);
break;
case SOUND_PCM_WRITE_FILTER:
case SOUND_PCM_READ_FILTER:
return -EINVAL;
default:
return -EINVAL;
}
return put_user(ret, (int *) arg);
}
/*
* Output a block via DMA to sound device
*
* dev - device number
* buf - physical address of buffer
* total_count - total byte count in buffer
* intrflag - set if this has been called from an interrupt (via DMAbuf_outputintr)
* restart_dma - set if DMA needs to be re-initialised
*
* Called when:
* 1. Starting output (dmabuf.c:1327)
* 2. (dmabuf.c:1504)
* 3. A new buffer needs to be sent to the device (dmabuf.c:1579)
*/
static void vidc_audio_output_block(int dev, unsigned long buf, int total_count,
int intrflag)
{
struct audio_operations *adev = audio_devs[dev];
struct dma_buffparms *dmap = adev->dmap_out;
dma_start = buf - (unsigned long)dmap->raw_buf_phys + (unsigned long)dmap->raw_buf;
dma_count = total_count;
if (!(adev->flags & DMA_ACTIVE))
{
unsigned long flags;
save_flags_cli(flags);
vidc_sound_dma_irq(0, NULL, NULL);
outb(DMA_CR_E | 0x10, IOMD_SD0CR);
restore_flags(flags);
}
}
static void vidc_audio_start_input(int dev, unsigned long buf, int count,
int intrflag)
{
}
static int vidc_audio_prepare_for_input(int dev, int bsize, int bcount)
{
return -EINVAL;
}
static void vidc_audio_dma_interrupt(void)
{
DMAbuf_outputintr(vidc_adev, 1);
}
/*
* Prepare for outputting samples to `dev'
*
* Each buffer that will be passed will be `bsize' bytes long,
* with a total of `bcount' buffers.
*
* Called when:
* 1. A trigger enables audio output (dmabuf.c:978)
* 2. We get a write buffer without dma_mode setup (dmabuf.c:1152)
* 3. We restart a transfer (dmabuf.c:1324)
*/
static int vidc_audio_prepare_for_output(int dev, int bsize, int bcount)
{
audio_devs[dev]->dmap_out->flags |= DMA_NODMA;
dma_interrupt = vidc_audio_dma_interrupt;
return 0;
}
/*
* Stop our current operation.
*/
static void vidc_audio_reset(int dev)
{
/* stop interrupts. Our real interrupt routine
* will close DMA down for us
*/
dma_interrupt = NULL;
}
static int vidc_audio_local_qlen(int dev)
{
return /*dma_count !=*/ 0;
}
static struct audio_driver vidc_audio_driver =
{
vidc_audio_open, /* open */
vidc_audio_close, /* close */
vidc_audio_output_block, /* output_block */
vidc_audio_start_input, /* start_input */
vidc_audio_ioctl, /* ioctl */
vidc_audio_prepare_for_input, /* prepare_for_input */
vidc_audio_prepare_for_output, /* prepare_for_output */
vidc_audio_reset, /* reset */
vidc_audio_local_qlen, /*+local_qlen */
NULL, /*+copy_from_user */
NULL, /*+halt_input */
NULL, /* halt_output */
NULL, /*+trigger */
NULL, /*+set_speed */
NULL, /*+set_bits */
NULL, /*+set_channels */
};
void vidc_audio_init(struct address_info *hw_config)
{
vidc_audio_volume = 100 | (100 << 8);
if ((vidc_adev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
"VIDCsound", &vidc_audio_driver,
sizeof(struct audio_driver),
DMA_AUTOMODE, AFMT_U8 | AFMT_S8 | AFMT_S16_LE,
NULL, hw_config->dma, hw_config->dma2)) >= 0)
{
audio_devs[vidc_adev]->min_fragment = 10; /* 1024 bytes => 64 buffers */
audio_devs[vidc_adev]->mixer_dev = num_mixers;
}
else printk(KERN_ERR "VIDCsound: Too many PCM devices available\n");
}
|