1994-04-21 14:16:55 +00:00
|
|
|
|
/*-
|
1998-09-15 18:16:39 +00:00
|
|
|
|
* Copyright (c) 1994-1998 S<EFBFBD>ren Schmidt
|
1994-04-21 14:16:55 +00:00
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1998-09-15 18:16:39 +00:00
|
|
|
|
* notice, this list of conditions and the following disclaimer,
|
|
|
|
|
* without modification, immediately at the beginning of the file.
|
1994-04-21 14:16:55 +00:00
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
1998-09-15 18:16:39 +00:00
|
|
|
|
* derived from this software without specific prior written permission.
|
1994-04-21 14:16:55 +00:00
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
|
* $FreeBSD$
|
1994-04-21 14:16:55 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
|
#include <sys/param.h>
|
1994-08-22 11:11:05 +00:00
|
|
|
|
#include <sys/systm.h>
|
1995-11-16 09:56:02 +00:00
|
|
|
|
#include <sys/conf.h>
|
1994-09-29 08:24:45 +00:00
|
|
|
|
#include <sys/proc.h>
|
2000-01-25 21:58:43 +00:00
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
#include <sys/bus.h>
|
1997-09-03 19:08:05 +00:00
|
|
|
|
#include <sys/filio.h>
|
1997-09-14 03:19:42 +00:00
|
|
|
|
#include <sys/poll.h>
|
1997-11-18 16:01:15 +00:00
|
|
|
|
#include <sys/vnode.h>
|
1994-11-06 00:46:21 +00:00
|
|
|
|
|
|
|
|
|
#include <machine/clock.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
|
#include <machine/pcaudioio.h>
|
1994-11-06 00:46:21 +00:00
|
|
|
|
|
2000-01-25 21:58:43 +00:00
|
|
|
|
#include <isa/isareg.h>
|
|
|
|
|
#include <isa/isavar.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
|
#include <i386/isa/timerreg.h>
|
1994-11-06 00:46:21 +00:00
|
|
|
|
|
1994-04-21 14:16:55 +00:00
|
|
|
|
#define BUF_SIZE 8192
|
|
|
|
|
#define SAMPLE_RATE 8000
|
|
|
|
|
#define INTERRUPT_RATE 16000
|
|
|
|
|
|
|
|
|
|
static struct pca_status {
|
|
|
|
|
char open; /* device open */
|
|
|
|
|
char queries; /* did others try opening */
|
1997-09-03 19:08:05 +00:00
|
|
|
|
unsigned char *buf[3]; /* triple buffering */
|
1994-04-21 14:16:55 +00:00
|
|
|
|
unsigned char *buffer; /* current buffer ptr */
|
1997-09-03 19:08:05 +00:00
|
|
|
|
unsigned in_use[3]; /* buffers fill */
|
1994-04-21 14:16:55 +00:00
|
|
|
|
unsigned index; /* index in current buffer */
|
|
|
|
|
unsigned counter; /* sample counter */
|
|
|
|
|
unsigned scale; /* sample counter scale */
|
|
|
|
|
unsigned sample_rate; /* sample rate */
|
|
|
|
|
unsigned processed; /* samples processed */
|
|
|
|
|
unsigned volume; /* volume for pc-speaker */
|
|
|
|
|
char encoding; /* Ulaw, Alaw or linear */
|
1999-05-06 18:58:05 +00:00
|
|
|
|
u_char current; /* current buffer */
|
1994-04-21 14:16:55 +00:00
|
|
|
|
unsigned char oldval; /* old timer port value */
|
|
|
|
|
char timer_on; /* is playback running */
|
1997-09-14 03:19:42 +00:00
|
|
|
|
struct selinfo wsel; /* select/poll status */
|
1994-04-21 14:16:55 +00:00
|
|
|
|
} pca_status;
|
|
|
|
|
|
|
|
|
|
static char buffer1[BUF_SIZE];
|
|
|
|
|
static char buffer2[BUF_SIZE];
|
1997-09-03 19:08:05 +00:00
|
|
|
|
static char buffer3[BUF_SIZE];
|
1994-04-21 14:16:55 +00:00
|
|
|
|
static char volume_table[256];
|
|
|
|
|
|
1999-09-27 01:52:37 +00:00
|
|
|
|
static unsigned char ulaw_dsp[] = {
|
|
|
|
|
3, 7, 11, 15, 19, 23, 27, 31,
|
|
|
|
|
35, 39, 43, 47, 51, 55, 59, 63,
|
|
|
|
|
66, 68, 70, 72, 74, 76, 78, 80,
|
|
|
|
|
82, 84, 86, 88, 90, 92, 94, 96,
|
|
|
|
|
98, 99, 100, 101, 102, 103, 104, 105,
|
|
|
|
|
106, 107, 108, 109, 110, 111, 112, 113,
|
|
|
|
|
113, 114, 114, 115, 115, 116, 116, 117,
|
|
|
|
|
117, 118, 118, 119, 119, 120, 120, 121,
|
|
|
|
|
121, 121, 122, 122, 122, 122, 123, 123,
|
|
|
|
|
123, 123, 124, 124, 124, 124, 125, 125,
|
|
|
|
|
125, 125, 125, 125, 126, 126, 126, 126,
|
|
|
|
|
126, 126, 126, 126, 127, 127, 127, 127,
|
|
|
|
|
127, 127, 127, 127, 127, 127, 127, 127,
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128,
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128,
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128,
|
|
|
|
|
253, 249, 245, 241, 237, 233, 229, 225,
|
|
|
|
|
221, 217, 213, 209, 205, 201, 197, 193,
|
|
|
|
|
190, 188, 186, 184, 182, 180, 178, 176,
|
|
|
|
|
174, 172, 170, 168, 166, 164, 162, 160,
|
|
|
|
|
158, 157, 156, 155, 154, 153, 152, 151,
|
|
|
|
|
150, 149, 148, 147, 146, 145, 144, 143,
|
|
|
|
|
143, 142, 142, 141, 141, 140, 140, 139,
|
|
|
|
|
139, 138, 138, 137, 137, 136, 136, 135,
|
|
|
|
|
135, 135, 134, 134, 134, 134, 133, 133,
|
|
|
|
|
133, 133, 132, 132, 132, 132, 131, 131,
|
|
|
|
|
131, 131, 131, 131, 130, 130, 130, 130,
|
|
|
|
|
130, 130, 130, 130, 129, 129, 129, 129,
|
|
|
|
|
129, 129, 129, 129, 129, 129, 129, 129,
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128,
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128,
|
|
|
|
|
128, 128, 128, 128, 128, 128, 128, 128,
|
|
|
|
|
};
|
1998-12-27 20:09:31 +00:00
|
|
|
|
|
|
|
|
|
static unsigned char alaw_linear[] = {
|
|
|
|
|
45, 214, 122, 133, 0, 255, 107, 149,
|
|
|
|
|
86, 171, 126, 129, 0, 255, 117, 138,
|
|
|
|
|
13, 246, 120, 135, 0, 255, 99, 157,
|
|
|
|
|
70, 187, 124, 131, 0, 255, 113, 142,
|
|
|
|
|
61, 198, 123, 132, 0, 255, 111, 145,
|
|
|
|
|
94, 163, 127, 128, 0, 255, 119, 136,
|
|
|
|
|
29, 230, 121, 134, 0, 255, 103, 153,
|
|
|
|
|
78, 179, 125, 130, 0, 255, 115, 140,
|
|
|
|
|
37, 222, 122, 133, 0, 255, 105, 151,
|
|
|
|
|
82, 175, 126, 129, 0, 255, 116, 139,
|
|
|
|
|
5, 254, 120, 135, 0, 255, 97, 159,
|
|
|
|
|
66, 191, 124, 131, 0, 255, 112, 143,
|
|
|
|
|
53, 206, 123, 132, 0, 255, 109, 147,
|
|
|
|
|
90, 167, 127, 128, 0, 255, 118, 137,
|
|
|
|
|
21, 238, 121, 134, 0, 255, 101, 155,
|
|
|
|
|
74, 183, 125, 130, 0, 255, 114, 141,
|
|
|
|
|
49, 210, 123, 133, 0, 255, 108, 148,
|
|
|
|
|
88, 169, 127, 129, 0, 255, 118, 138,
|
|
|
|
|
17, 242, 121, 135, 0, 255, 100, 156,
|
|
|
|
|
72, 185, 125, 131, 0, 255, 114, 142,
|
|
|
|
|
64, 194, 124, 132, 0, 255, 112, 144,
|
|
|
|
|
96, 161, 128, 128, 1, 255, 120, 136,
|
|
|
|
|
33, 226, 122, 134, 0, 255, 104, 152,
|
|
|
|
|
80, 177, 126, 130, 0, 255, 116, 140,
|
|
|
|
|
41, 218, 122, 133, 0, 255, 106, 150,
|
|
|
|
|
84, 173, 126, 129, 0, 255, 117, 139,
|
|
|
|
|
9, 250, 120, 135, 0, 255, 98, 158,
|
|
|
|
|
68, 189, 124, 131, 0, 255, 113, 143,
|
|
|
|
|
57, 202, 123, 132, 0, 255, 110, 146,
|
|
|
|
|
92, 165, 127, 128, 0, 255, 119, 137,
|
|
|
|
|
25, 234, 121, 134, 0, 255, 102, 154,
|
|
|
|
|
76, 181, 125, 130, 0, 255, 115, 141,
|
|
|
|
|
};
|
|
|
|
|
|
1994-04-21 14:16:55 +00:00
|
|
|
|
static int pca_sleep = 0;
|
|
|
|
|
static int pca_initialized = 0;
|
|
|
|
|
|
1996-10-25 16:09:31 +00:00
|
|
|
|
static void pcaintr(struct clockframe *frame);
|
1994-04-21 14:16:55 +00:00
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
|
static d_open_t pcaopen;
|
|
|
|
|
static d_close_t pcaclose;
|
|
|
|
|
static d_write_t pcawrite;
|
|
|
|
|
static d_ioctl_t pcaioctl;
|
1997-09-14 03:19:42 +00:00
|
|
|
|
static d_poll_t pcapoll;
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 24
|
1999-05-30 16:53:49 +00:00
|
|
|
|
static struct cdevsw pca_cdevsw = {
|
|
|
|
|
/* open */ pcaopen,
|
|
|
|
|
/* close */ pcaclose,
|
|
|
|
|
/* read */ noread,
|
|
|
|
|
/* write */ pcawrite,
|
|
|
|
|
/* ioctl */ pcaioctl,
|
|
|
|
|
/* poll */ pcapoll,
|
|
|
|
|
/* mmap */ nommap,
|
|
|
|
|
/* strategy */ nostrategy,
|
|
|
|
|
/* name */ "pca",
|
|
|
|
|
/* maj */ CDEV_MAJOR,
|
|
|
|
|
/* dump */ nodump,
|
|
|
|
|
/* psize */ nopsize,
|
|
|
|
|
/* flags */ 0,
|
|
|
|
|
/* bmaj */ -1
|
|
|
|
|
};
|
1995-12-08 11:19:42 +00:00
|
|
|
|
|
1995-12-15 00:54:32 +00:00
|
|
|
|
static void pca_continue __P((void));
|
|
|
|
|
static void pca_init __P((void));
|
|
|
|
|
static void pca_pause __P((void));
|
1994-04-21 14:16:55 +00:00
|
|
|
|
|
1999-11-15 23:27:40 +00:00
|
|
|
|
static void
|
|
|
|
|
conv(const unsigned char *table, unsigned char *buff, unsigned n)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
1999-11-15 23:27:40 +00:00
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
|
buff[i] = table[buff[i]];
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
|
static void
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_volume(int volume)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
|
|
for (i=0; i<256; i++) {
|
1997-09-03 19:08:05 +00:00
|
|
|
|
j = ((i-128)*volume)/25;
|
|
|
|
|
/* XXX
|
1994-05-02 09:40:12 +00:00
|
|
|
|
j = ((i-128)*volume)/100;
|
1997-09-03 19:08:05 +00:00
|
|
|
|
*/
|
1994-04-21 14:16:55 +00:00
|
|
|
|
if (j<-128)
|
|
|
|
|
j = -128;
|
|
|
|
|
if (j>127)
|
|
|
|
|
j = 127;
|
|
|
|
|
volume_table[i] = (((255-(j + 128))/4)+1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1996-10-25 16:09:31 +00:00
|
|
|
|
pca_init(void)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
|
|
|
|
pca_status.open = 0;
|
|
|
|
|
pca_status.queries = 0;
|
|
|
|
|
pca_status.timer_on = 0;
|
|
|
|
|
pca_status.buf[0] = (unsigned char *)&buffer1[0];
|
|
|
|
|
pca_status.buf[1] = (unsigned char *)&buffer2[0];
|
1997-09-03 19:08:05 +00:00
|
|
|
|
pca_status.buf[2] = (unsigned char *)&buffer3[0];
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.buffer = pca_status.buf[0];
|
1998-12-13 23:32:44 +00:00
|
|
|
|
pca_status.in_use[0] = pca_status.in_use[1] = pca_status.in_use[2] = 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.current = 0;
|
|
|
|
|
pca_status.sample_rate = SAMPLE_RATE;
|
|
|
|
|
pca_status.scale = (pca_status.sample_rate << 8) / INTERRUPT_RATE;
|
|
|
|
|
pca_status.encoding = AUDIO_ENCODING_ULAW;
|
|
|
|
|
pca_status.volume = 100;
|
|
|
|
|
|
|
|
|
|
pca_volume(pca_status.volume);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
|
static int
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_start(void)
|
|
|
|
|
{
|
1996-06-09 14:23:13 +00:00
|
|
|
|
int x = splhigh();
|
|
|
|
|
int rv = 0;
|
|
|
|
|
|
1994-04-21 14:16:55 +00:00
|
|
|
|
/* use the first buffer */
|
|
|
|
|
pca_status.current = 0;
|
|
|
|
|
pca_status.index = 0;
|
|
|
|
|
pca_status.counter = 0;
|
|
|
|
|
pca_status.buffer = pca_status.buf[pca_status.current];
|
1994-05-02 09:40:12 +00:00
|
|
|
|
pca_status.oldval = inb(IO_PPI) | 0x03;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
/* acquire the timers */
|
1996-06-09 14:23:13 +00:00
|
|
|
|
if (acquire_timer2(TIMER_LSB|TIMER_ONESHOT))
|
|
|
|
|
rv = -1;
|
|
|
|
|
else if (acquire_timer0(INTERRUPT_RATE, pcaintr)) {
|
1994-04-21 14:16:55 +00:00
|
|
|
|
release_timer2();
|
1996-06-09 14:23:13 +00:00
|
|
|
|
rv = -1;
|
|
|
|
|
} else
|
|
|
|
|
pca_status.timer_on = 1;
|
|
|
|
|
|
|
|
|
|
splx(x);
|
|
|
|
|
return rv;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
|
static void
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_stop(void)
|
|
|
|
|
{
|
1996-06-09 14:23:13 +00:00
|
|
|
|
int x = splhigh();
|
|
|
|
|
|
1994-04-21 14:16:55 +00:00
|
|
|
|
/* release the timers */
|
|
|
|
|
release_timer0();
|
|
|
|
|
release_timer2();
|
|
|
|
|
/* reset the buffer */
|
1997-09-03 19:08:05 +00:00
|
|
|
|
pca_status.in_use[0] = pca_status.in_use[1] = pca_status.in_use[2] = 0;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
pca_status.index = 0;
|
|
|
|
|
pca_status.counter = 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.current = 0;
|
|
|
|
|
pca_status.buffer = pca_status.buf[pca_status.current];
|
|
|
|
|
pca_status.timer_on = 0;
|
1996-06-09 14:23:13 +00:00
|
|
|
|
splx(x);
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
|
static void
|
1996-10-25 16:09:31 +00:00
|
|
|
|
pca_pause(void)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
1996-06-09 14:23:13 +00:00
|
|
|
|
int x = splhigh();
|
|
|
|
|
|
1994-04-21 14:16:55 +00:00
|
|
|
|
release_timer0();
|
1995-05-30 08:16:23 +00:00
|
|
|
|
release_timer2();
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.timer_on = 0;
|
1996-06-09 14:23:13 +00:00
|
|
|
|
splx(x);
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-05-30 08:16:23 +00:00
|
|
|
|
static void
|
1996-10-25 16:09:31 +00:00
|
|
|
|
pca_continue(void)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
1996-06-09 14:23:13 +00:00
|
|
|
|
int x = splhigh();
|
|
|
|
|
|
1994-05-02 09:40:12 +00:00
|
|
|
|
pca_status.oldval = inb(IO_PPI) | 0x03;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
acquire_timer2(TIMER_LSB|TIMER_ONESHOT);
|
|
|
|
|
acquire_timer0(INTERRUPT_RATE, pcaintr);
|
|
|
|
|
pca_status.timer_on = 1;
|
1996-06-09 14:23:13 +00:00
|
|
|
|
splx(x);
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1994-11-06 00:46:21 +00:00
|
|
|
|
static int
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_wait(void)
|
|
|
|
|
{
|
1996-06-09 14:23:13 +00:00
|
|
|
|
int error, x;
|
|
|
|
|
|
|
|
|
|
if (!pca_status.timer_on)
|
|
|
|
|
return 0;
|
1994-11-06 00:46:21 +00:00
|
|
|
|
|
1997-11-18 16:01:15 +00:00
|
|
|
|
while (pca_status.in_use[0] || pca_status.in_use[1] ||
|
|
|
|
|
pca_status.in_use[2]) {
|
1996-06-09 14:23:13 +00:00
|
|
|
|
x = spltty();
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_sleep = 1;
|
1994-11-06 00:46:21 +00:00
|
|
|
|
error = tsleep(&pca_sleep, PZERO|PCATCH, "pca_drain", 0);
|
|
|
|
|
pca_sleep = 0;
|
1996-06-09 14:23:13 +00:00
|
|
|
|
splx(x);
|
1994-11-06 00:46:21 +00:00
|
|
|
|
if (error != 0 && error != ERESTART) {
|
|
|
|
|
pca_stop();
|
|
|
|
|
return error;
|
|
|
|
|
}
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
1994-11-06 00:46:21 +00:00
|
|
|
|
return 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-25 21:58:43 +00:00
|
|
|
|
static struct isa_pnp_id pca_ids[] = {
|
|
|
|
|
{0x0008d041, "AT-style speaker sound"}, /* PNP0800 */
|
|
|
|
|
{0}
|
|
|
|
|
};
|
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
|
static int
|
2000-01-25 21:58:43 +00:00
|
|
|
|
pcaprobe(device_t dev)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
2000-01-25 21:58:43 +00:00
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
/* Check isapnp ids */
|
|
|
|
|
error = ISA_PNP_PROBE(device_get_parent(dev), dev, pca_ids);
|
|
|
|
|
if (error == ENXIO)
|
|
|
|
|
return ENXIO;
|
|
|
|
|
return 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-12-10 13:40:44 +00:00
|
|
|
|
static int
|
2000-01-25 21:58:43 +00:00
|
|
|
|
pcaattach(device_t dev)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
|
|
|
|
pca_init();
|
1999-08-23 20:59:21 +00:00
|
|
|
|
make_dev(&pca_cdevsw, 0, 0, 0, 0600, "pcaudio");
|
|
|
|
|
make_dev(&pca_cdevsw, 128, 0, 0, 0600, "pcaudioctl");
|
2000-01-25 21:58:43 +00:00
|
|
|
|
return 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-25 21:58:43 +00:00
|
|
|
|
static device_method_t pca_methods[] = {
|
|
|
|
|
DEVMETHOD(device_probe, pcaprobe),
|
|
|
|
|
DEVMETHOD(device_attach, pcaattach),
|
|
|
|
|
{ 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static driver_t pca_driver = {
|
|
|
|
|
"pca",
|
|
|
|
|
pca_methods,
|
|
|
|
|
1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static devclass_t pca_devclass;
|
|
|
|
|
|
|
|
|
|
DRIVER_MODULE(pca, isa, pca_driver, pca_devclass, 0, 0);
|
|
|
|
|
|
1994-04-21 14:16:55 +00:00
|
|
|
|
|
1996-10-25 16:09:31 +00:00
|
|
|
|
static int
|
1995-09-08 11:09:15 +00:00
|
|
|
|
pcaopen(dev_t dev, int flags, int fmt, struct proc *p)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
|
|
|
|
/* audioctl device can always be opened */
|
|
|
|
|
if (minor(dev) == 128)
|
|
|
|
|
return 0;
|
|
|
|
|
if (minor(dev) > 0)
|
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
|
|
if (!pca_initialized) {
|
|
|
|
|
pca_init();
|
|
|
|
|
pca_initialized = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* audio device can only be open by one process */
|
|
|
|
|
if (pca_status.open) {
|
|
|
|
|
pca_status.queries = 1;
|
|
|
|
|
return EBUSY;
|
|
|
|
|
}
|
|
|
|
|
pca_status.buffer = pca_status.buf[0];
|
1997-09-03 19:08:05 +00:00
|
|
|
|
pca_status.in_use[0] = pca_status.in_use[1] = pca_status.in_use[2] = 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.timer_on = 0;
|
|
|
|
|
pca_status.open = 1;
|
|
|
|
|
pca_status.processed = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-10-25 16:09:31 +00:00
|
|
|
|
static int
|
1995-09-08 11:09:15 +00:00
|
|
|
|
pcaclose(dev_t dev, int flags, int fmt, struct proc *p)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
|
|
|
|
/* audioctl device can always be closed */
|
|
|
|
|
if (minor(dev) == 128)
|
|
|
|
|
return 0;
|
|
|
|
|
if (minor(dev) > 0)
|
|
|
|
|
return ENXIO;
|
|
|
|
|
/* audio device close drains all output and restores timers */
|
|
|
|
|
pca_wait();
|
1995-05-30 08:16:23 +00:00
|
|
|
|
pca_stop();
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.open = 0;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-10-25 16:09:31 +00:00
|
|
|
|
static int
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pcawrite(dev_t dev, struct uio *uio, int flag)
|
|
|
|
|
{
|
1996-06-09 14:23:13 +00:00
|
|
|
|
int count, error, which, x;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
|
|
|
|
|
/* only audio device can be written */
|
|
|
|
|
if (minor(dev) > 0)
|
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
|
|
while ((count = min(BUF_SIZE, uio->uio_resid)) > 0) {
|
1997-11-18 16:01:15 +00:00
|
|
|
|
if (pca_status.in_use[0] && pca_status.in_use[1] &&
|
|
|
|
|
pca_status.in_use[2]) {
|
|
|
|
|
if (flag & IO_NDELAY)
|
1997-09-03 19:08:05 +00:00
|
|
|
|
return EWOULDBLOCK;
|
1996-06-09 14:23:13 +00:00
|
|
|
|
x = spltty();
|
1994-09-29 08:24:45 +00:00
|
|
|
|
pca_sleep = 1;
|
1994-11-06 00:46:21 +00:00
|
|
|
|
error = tsleep(&pca_sleep, PZERO|PCATCH, "pca_wait", 0);
|
|
|
|
|
pca_sleep = 0;
|
1996-06-09 14:23:13 +00:00
|
|
|
|
splx(x);
|
1994-11-06 00:46:21 +00:00
|
|
|
|
if (error != 0 && error != ERESTART) {
|
|
|
|
|
pca_stop();
|
|
|
|
|
return error;
|
|
|
|
|
}
|
1994-09-29 08:24:45 +00:00
|
|
|
|
}
|
1997-11-18 16:01:15 +00:00
|
|
|
|
if (!pca_status.in_use[0])
|
1997-09-03 19:08:05 +00:00
|
|
|
|
which = 0;
|
1997-11-18 16:01:15 +00:00
|
|
|
|
else if (!pca_status.in_use[1])
|
1997-09-03 19:08:05 +00:00
|
|
|
|
which = 1;
|
1997-11-18 16:01:15 +00:00
|
|
|
|
else
|
|
|
|
|
which = 2;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
if (count && !pca_status.in_use[which]) {
|
|
|
|
|
uiomove(pca_status.buf[which], count, uio);
|
|
|
|
|
pca_status.processed += count;
|
|
|
|
|
switch (pca_status.encoding) {
|
|
|
|
|
case AUDIO_ENCODING_ULAW:
|
1994-05-02 09:40:12 +00:00
|
|
|
|
conv(ulaw_dsp, pca_status.buf[which], count);
|
1994-04-21 14:16:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case AUDIO_ENCODING_ALAW:
|
1997-09-06 17:38:29 +00:00
|
|
|
|
conv(alaw_linear, pca_status.buf[which], count);
|
1994-04-21 14:16:55 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case AUDIO_ENCODING_RAW:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
pca_status.in_use[which] = count;
|
|
|
|
|
if (!pca_status.timer_on)
|
1995-05-30 08:16:23 +00:00
|
|
|
|
if (pca_start())
|
1994-04-21 14:16:55 +00:00
|
|
|
|
return EBUSY;
|
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
}
|
1994-04-21 14:16:55 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-10-25 16:09:31 +00:00
|
|
|
|
static int
|
1998-06-07 17:13:14 +00:00
|
|
|
|
pcaioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
1994-09-29 08:24:45 +00:00
|
|
|
|
audio_info_t *auptr;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
|
|
|
|
|
switch(cmd) {
|
|
|
|
|
|
|
|
|
|
case AUDIO_GETINFO:
|
|
|
|
|
auptr = (audio_info_t *)data;
|
|
|
|
|
auptr->play.sample_rate = pca_status.sample_rate;
|
|
|
|
|
auptr->play.channels = 1;
|
|
|
|
|
auptr->play.precision = 8;
|
|
|
|
|
auptr->play.encoding = pca_status.encoding;
|
|
|
|
|
|
|
|
|
|
auptr->play.gain = pca_status.volume;
|
|
|
|
|
auptr->play.port = 0;
|
|
|
|
|
|
|
|
|
|
auptr->play.samples = pca_status.processed;
|
|
|
|
|
auptr->play.eof = 0;
|
|
|
|
|
auptr->play.pause = !pca_status.timer_on;
|
|
|
|
|
auptr->play.error = 0;
|
|
|
|
|
auptr->play.waiting = pca_status.queries;
|
|
|
|
|
|
|
|
|
|
auptr->play.open = pca_status.open;
|
|
|
|
|
auptr->play.active = pca_status.timer_on;
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
case AUDIO_SETINFO:
|
|
|
|
|
auptr = (audio_info_t *)data;
|
|
|
|
|
if (auptr->play.sample_rate != (unsigned int)~0) {
|
|
|
|
|
pca_status.sample_rate = auptr->play.sample_rate;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
pca_status.scale =
|
1994-04-21 14:16:55 +00:00
|
|
|
|
(pca_status.sample_rate << 8) / INTERRUPT_RATE;
|
|
|
|
|
}
|
|
|
|
|
if (auptr->play.encoding != (unsigned int)~0) {
|
|
|
|
|
pca_status.encoding = auptr->play.encoding;
|
|
|
|
|
}
|
|
|
|
|
if (auptr->play.gain != (unsigned int)~0) {
|
|
|
|
|
pca_status.volume = auptr->play.gain;
|
|
|
|
|
pca_volume(pca_status.volume);
|
|
|
|
|
}
|
|
|
|
|
if (auptr->play.pause != (unsigned char)~0) {
|
|
|
|
|
if (auptr->play.pause)
|
|
|
|
|
pca_pause();
|
|
|
|
|
else
|
|
|
|
|
pca_continue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
case AUDIO_DRAIN:
|
1996-07-17 20:18:56 +00:00
|
|
|
|
case AUDIO_COMPAT_DRAIN:
|
1994-11-06 00:46:21 +00:00
|
|
|
|
return pca_wait();
|
1994-04-21 14:16:55 +00:00
|
|
|
|
|
|
|
|
|
case AUDIO_FLUSH:
|
1996-07-17 20:18:56 +00:00
|
|
|
|
case AUDIO_COMPAT_FLUSH:
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_stop();
|
|
|
|
|
return 0;
|
1997-09-03 19:08:05 +00:00
|
|
|
|
case FIONBIO:
|
|
|
|
|
return 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
return ENXIO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-10-25 16:09:31 +00:00
|
|
|
|
static void
|
1994-11-06 00:46:21 +00:00
|
|
|
|
pcaintr(struct clockframe *frame)
|
1994-04-21 14:16:55 +00:00
|
|
|
|
{
|
|
|
|
|
if (pca_status.index < pca_status.in_use[pca_status.current]) {
|
1994-05-02 09:40:12 +00:00
|
|
|
|
disable_intr();
|
|
|
|
|
__asm__("outb %0,$0x61\n"
|
|
|
|
|
"andb $0xFE,%0\n"
|
|
|
|
|
"outb %0,$0x61"
|
1994-04-21 14:16:55 +00:00
|
|
|
|
: : "a" ((char)pca_status.oldval) );
|
1994-05-02 09:40:12 +00:00
|
|
|
|
__asm__("xlatb\n"
|
|
|
|
|
"outb %0,$0x42"
|
1994-04-21 14:16:55 +00:00
|
|
|
|
: : "a" ((char)pca_status.buffer[pca_status.index]),
|
1998-07-14 06:17:28 +00:00
|
|
|
|
"b" (volume_table) );
|
1994-05-02 09:40:12 +00:00
|
|
|
|
enable_intr();
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.counter += pca_status.scale;
|
|
|
|
|
pca_status.index = (pca_status.counter >> 8);
|
|
|
|
|
}
|
1994-09-29 08:24:45 +00:00
|
|
|
|
if (pca_status.index >= pca_status.in_use[pca_status.current]) {
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.index = pca_status.counter = 0;
|
|
|
|
|
pca_status.in_use[pca_status.current] = 0;
|
1997-09-03 19:08:05 +00:00
|
|
|
|
pca_status.current++;
|
1997-11-18 16:01:15 +00:00
|
|
|
|
if (pca_status.current > 2)
|
|
|
|
|
pca_status.current = 0;
|
1994-04-21 14:16:55 +00:00
|
|
|
|
pca_status.buffer = pca_status.buf[pca_status.current];
|
1996-06-09 14:23:13 +00:00
|
|
|
|
if (pca_sleep)
|
1994-11-06 00:46:21 +00:00
|
|
|
|
wakeup(&pca_sleep);
|
1994-09-29 21:11:29 +00:00
|
|
|
|
if (pca_status.wsel.si_pid) {
|
|
|
|
|
selwakeup((struct selinfo *)&pca_status.wsel.si_pid);
|
|
|
|
|
pca_status.wsel.si_pid = 0;
|
|
|
|
|
pca_status.wsel.si_flags = 0;
|
1994-09-29 08:24:45 +00:00
|
|
|
|
}
|
1994-04-21 14:16:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1994-09-29 08:24:45 +00:00
|
|
|
|
|
1996-10-25 16:09:31 +00:00
|
|
|
|
static int
|
1997-09-14 03:19:42 +00:00
|
|
|
|
pcapoll(dev_t dev, int events, struct proc *p)
|
1994-09-29 08:24:45 +00:00
|
|
|
|
{
|
1997-09-14 03:19:42 +00:00
|
|
|
|
int s;
|
1994-09-29 08:24:45 +00:00
|
|
|
|
struct proc *p1;
|
1997-09-14 03:19:42 +00:00
|
|
|
|
int revents = 0;
|
|
|
|
|
|
|
|
|
|
s = spltty();
|
|
|
|
|
|
1999-05-06 18:13:11 +00:00
|
|
|
|
if (events & (POLLOUT | POLLWRNORM)) {
|
1997-09-14 03:19:42 +00:00
|
|
|
|
if (!pca_status.in_use[0] || !pca_status.in_use[1] ||
|
|
|
|
|
!pca_status.in_use[2])
|
|
|
|
|
revents |= events & (POLLOUT | POLLWRNORM);
|
|
|
|
|
else {
|
|
|
|
|
if (pca_status.wsel.si_pid &&
|
|
|
|
|
(p1=pfind(pca_status.wsel.si_pid))
|
|
|
|
|
&& p1->p_wchan == (caddr_t)&selwait)
|
|
|
|
|
pca_status.wsel.si_flags = SI_COLL;
|
|
|
|
|
else
|
|
|
|
|
pca_status.wsel.si_pid = p->p_pid;
|
|
|
|
|
}
|
1999-05-06 18:13:11 +00:00
|
|
|
|
}
|
1997-09-14 03:19:42 +00:00
|
|
|
|
splx(s);
|
|
|
|
|
return (revents);
|
1994-09-29 08:24:45 +00:00
|
|
|
|
}
|