Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/agpgart
[linux-2.6-block.git] / sound / oss / pas2_pcm.c
CommitLineData
1da177e4
LT
1/*
2 * pas2_pcm.c Audio routines for PAS16
3 *
4 *
5 * Copyright (C) by Hannu Savolainen 1993-1997
6 *
7 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
8 * Version 2 (June 1991). See the "COPYING" file distributed with this software
9 * for more info.
10 *
11 *
12 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
13 * Alan Cox : Swatted a double allocation of device bug. Made a few
14 * more things module options.
15 * Bartlomiej Zolnierkiewicz : Added __init to pas_pcm_init()
16 */
17
18#include <linux/init.h>
19#include <linux/spinlock.h>
20#include <asm/timex.h>
21#include "sound_config.h"
22
23#include "pas2.h"
24
25#ifndef DEB
26#define DEB(WHAT)
27#endif
28
29#define PAS_PCM_INTRBITS (0x08)
30/*
31 * Sample buffer timer interrupt enable
32 */
33
34#define PCM_NON 0
35#define PCM_DAC 1
36#define PCM_ADC 2
37
38static unsigned long pcm_speed; /* sampling rate */
39static unsigned char pcm_channels = 1; /* channels (1 or 2) */
40static unsigned char pcm_bits = 8; /* bits/sample (8 or 16) */
41static unsigned char pcm_filter; /* filter FLAG */
42static unsigned char pcm_mode = PCM_NON;
43static unsigned long pcm_count;
44static unsigned short pcm_bitsok = 8; /* mask of OK bits */
45static int pcm_busy;
46int pas_audiodev = -1;
47static int open_mode;
48
49extern spinlock_t pas_lock;
50
51static int pcm_set_speed(int arg)
52{
53 int foo, tmp;
54 unsigned long flags;
55
56 if (arg == 0)
57 return pcm_speed;
58
59 if (arg > 44100)
60 arg = 44100;
61 if (arg < 5000)
62 arg = 5000;
63
64 if (pcm_channels & 2)
65 {
66 foo = ((CLOCK_TICK_RATE / 2) + (arg / 2)) / arg;
67 arg = ((CLOCK_TICK_RATE / 2) + (foo / 2)) / foo;
68 }
69 else
70 {
71 foo = (CLOCK_TICK_RATE + (arg / 2)) / arg;
72 arg = (CLOCK_TICK_RATE + (foo / 2)) / foo;
73 }
74
75 pcm_speed = arg;
76
77 tmp = pas_read(0x0B8A);
78
79 /*
80 * Set anti-aliasing filters according to sample rate. You really *NEED*
81 * to enable this feature for all normal recording unless you want to
82 * experiment with aliasing effects.
83 * These filters apply to the selected "recording" source.
84 * I (pfw) don't know the encoding of these 5 bits. The values shown
85 * come from the SDK found on ftp.uwp.edu:/pub/msdos/proaudio/.
86 *
87 * I cleared bit 5 of these values, since that bit controls the master
88