Complete revamp of Apple Sound Chip support. The ASC can now be accessed

as a real device whose registers and buffers are available through mmap(2),
which makes further development of the driver considerably less painful.
This commit is contained in:
scottr 1997-02-11 07:47:36 +00:00
parent 2a2a70d39c
commit 77e960bf17
5 changed files with 452 additions and 286 deletions

View File

@ -1,5 +1,35 @@
/* $NetBSD: asc.c,v 1.16 1997/02/03 17:36:00 scottr Exp $ */
/* $NetBSD: asc.c,v 1.17 1997/02/11 07:47:36 scottr Exp $ */
/*
* Copyright (C) 1997 Scott Reynolds
* 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
* notice, this list of conditions and the following disclaimer.
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Scott Reynolds.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 REGENTS OR CONTRIBUTORS 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.
*/
/*-
* Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo,
* Michael L. Finch, Bradley A. Grantham, and
@ -34,7 +64,7 @@
*/
/*
* ASC driver code and asc_ringbell() support
* ASC driver code and console bell support
*/
#include <sys/types.h>
@ -44,6 +74,10 @@
#include <sys/systm.h>
#include <sys/param.h>
#include <sys/device.h>
#include <sys/poll.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
@ -55,21 +89,16 @@
#define MAC68K_ASC_BASE ((caddr_t) 0x50f14000)
#define MAC68K_ASC_LEN 0x01000
/* bell support data */
static int asc_configured = 0;
static bus_space_tag_t asc_tag = MAC68K_BUS_SPACE_MEM;
static bus_space_handle_t asc_handle;
static u_int8_t asc_wave_tab[0x800];
static int bell_freq = 1880;
static int bell_length = 10;
static int bell_volume = 100;
static int bell_ringing = 0;
static int asc_ring_bell __P((void *, int, int, int));
static void asc_stop_bell __P((void *));
static int ascmatch __P((struct device *, struct cfdata *, void *));
static void ascattach __P((struct device *, struct device *, void *));
static int ascmatch __P((struct device *, struct cfdata *, void *));
static void ascattach __P((struct device *, struct device *, void *));
struct cfattach asc_ca = {
sizeof(struct device), ascmatch, ascattach
sizeof(struct asc_softc), ascmatch, ascattach
};
struct cfdriver asc_cd = {
@ -82,18 +111,12 @@ ascmatch(parent, cf, aux)
struct cfdata *cf;
void *aux;
{
static int asc_matched = 0;
struct obio_attach_args *oa = aux;
bus_space_tag_t bst = MAC68K_BUS_SPACE_MEM;
bus_space_handle_t bsh;
bus_addr_t addr;
int rval = 0;
/* Allow only one instance. */
if (asc_matched)
return (0);
asc_matched = 1;
addr = (bus_addr_t) (oa->oa_addr ? oa->oa_addr : MAC68K_ASC_BASE);
if (bus_space_map(bst, addr, MAC68K_ASC_LEN, 0, &bsh))
@ -114,141 +137,210 @@ ascattach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct asc_softc *sc = (struct asc_softc *) self;
struct obio_attach_args *oa = aux;
bus_addr_t addr;
int i;
sc->sc_tag = MAC68K_BUS_SPACE_MEM;
addr = (bus_addr_t) (oa->oa_addr ? oa->oa_addr : MAC68K_ASC_BASE);
if (bus_space_map(asc_tag, addr, MAC68K_ASC_LEN, 0,
&asc_handle)) {
printf("%s: can't map memory space\n", self->dv_xname);
if (bus_space_map(sc->sc_tag, addr, MAC68K_ASC_LEN, 0,
&sc->sc_handle)) {
printf("%s: can't map memory space\n", sc->sc_dev.dv_xname);
return;
}
sc->sc_open = 0;
sc->sc_ringing = 0;
printf(" Apple sound chip\n");
asc_configured = 1;
for (i = 0; i < 256; i++) { /* up part of wave, four voices? */
asc_wave_tab[i] = i / 4;
asc_wave_tab[i + 512] = i / 4;
asc_wave_tab[i + 1024] = i / 4;
asc_wave_tab[i + 1536] = i / 4;
}
for (i = 0; i < 256; i++) { /* down part of wave, four voices? */
asc_wave_tab[i + 256] = 0x3f - (i / 4);
asc_wave_tab[i + 768] = 0x3f - (i / 4);
asc_wave_tab[i + 1280] = 0x3f - (i / 4);
asc_wave_tab[i + 1792] = 0x3f - (i / 4);
}
printf(": Apple Sound Chip");
if (oa->oa_addr)
printf(" at %p", oa->oa_addr);
printf("\n");
mac68k_set_bell_callback(asc_ring_bell, sc);
}
int
asc_setbellparams(freq, length, volume)
int freq;
int length;
int volume;
int
ascopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
if (!asc_configured)
return (ENODEV);
struct asc_softc *sc;
int unit;
/*
* I only perform these checks for sanity. I suppose
* someone might want a bell that rings all day, but then
* they can make kernel mods themselves.
*/
if (freq < 10 || freq > 40000)
return (EINVAL);
if (length < 0 || length > 3600)
return (EINVAL);
if (volume < 0 || volume > 100)
return (EINVAL);
bell_freq = freq;
bell_length = length;
bell_volume = volume;
unit = ASCUNIT(dev);
sc = asc_cd.cd_devs[unit];
if (unit >= asc_cd.cd_ndevs)
return (ENXIO);
if (sc->sc_open)
return (EBUSY);
sc->sc_open = 1;
return (0);
}
int
asc_getbellparams(freq, length, volume)
int *freq;
int *length;
int *volume;
int
ascclose(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
if (!asc_configured)
return (ENODEV);
struct asc_softc *sc;
*freq = bell_freq;
*length = bell_length;
*volume = bell_volume;
sc = asc_cd.cd_devs[ASCUNIT(dev)];
sc->sc_open = 0;
return (0);
}
void
asc_bellstop(param)
int param;
int
ascread(dev, uio, ioflag)
dev_t dev;
struct uio *uio;
int ioflag;
{
if (!asc_configured)
return;
if (bell_ringing > 1000 || bell_ringing < 0)
panic("bell got out of sync?");
if (--bell_ringing == 0) /* disable ASC */
bus_space_write_1(asc_tag, asc_handle, 0x801, 0);
return (ENXIO);
}
int
asc_ringbell()
int
ascwrite(dev, uio, ioflag)
dev_t dev;
struct uio *uio;
int ioflag;
{
int i;
unsigned long freq;
return (ENXIO);
}
if (!asc_configured)
int
ascioctl(dev, cmd, data, flag, p)
dev_t dev;
int cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct asc_softc *sc;
int error;
int unit = ASCUNIT(dev);
sc = asc_cd.cd_devs[unit];
error = 0;
switch (cmd) {
default:
error = EINVAL;
break;
}
return (error);
}
int
ascpoll(dev, events, p)
dev_t dev;
int events;
struct proc *p;
{
return (events & (POLLOUT | POLLWRNORM));
}
int
ascmmap(dev, off, prot)
dev_t dev;
int off;
int prot;
{
int unit = ASCUNIT(dev);
struct asc_softc *sc;
vm_offset_t pa;
sc = asc_cd.cd_devs[unit];
if (off < MAC68K_ASC_LEN) {
pa = pmap_extract(pmap_kernel(), (vm_offset_t) sc->sc_handle);
return mac68k_btop(pa + off);
}
return (-1);
}
static int
asc_ring_bell(arg, freq, length, volume)
void *arg;
int freq, length, volume;
{
struct asc_softc *sc = (struct asc_softc *) arg;
unsigned long cfreq;
int i;
if (!sc)
return (ENODEV);
if (bell_ringing == 0) {
if (sc->sc_ringing == 0) {
for (i = 0; i < 0x800; i++)
bus_space_write_1(asc_tag, asc_handle, i, 0);
for (i = 0; i < 256; i++) {
bus_space_write_1(asc_tag, asc_handle, i, i / 4);
bus_space_write_1(asc_tag, asc_handle, i + 512, i / 4);
bus_space_write_1(asc_tag, asc_handle, i + 1024, i / 4);
bus_space_write_1(asc_tag, asc_handle, i + 1536, i / 4);
} /* up part of wave, four voices ? */
for (i = 0; i < 256; i++) {
bus_space_write_1(asc_tag, asc_handle, i + 256,
0x3f - (i / 4));
bus_space_write_1(asc_tag, asc_handle, i + 768,
0x3f - (i / 4));
bus_space_write_1(asc_tag, asc_handle, i + 1280,
0x3f - (i / 4));
bus_space_write_1(asc_tag, asc_handle, i + 1792,
0x3f - (i / 4));
} /* down part of wave, four voices ? */
bus_space_write_multi_1(sc->sc_tag, sc->sc_handle,
0, 0, 0x800);
bus_space_write_region_1(sc->sc_tag, sc->sc_handle,
0, asc_wave_tab, 0x800);
/* Fix this. Need to find exact ASC sampling freq */
freq = 65536 * bell_freq / 466;
cfreq = 65536 * freq / 466;
/* printf("beep: from %d, %02x %02x %02x %02x\n",
* cur_beep.freq, (freq >> 24) & 0xff, (freq >> 16) & 0xff,
* (freq >> 8) & 0xff, (freq) & 0xff); */
* cur_beep.freq, (cfreq >> 24) & 0xff, (cfreq >> 16) & 0xff,
* (cfreq >> 8) & 0xff, (cfreq) & 0xff); */
for (i = 0; i < 8; i++) {
bus_space_write_1(asc_tag, asc_handle, 0x814 + 8 * i,
(freq >> 24) & 0xff);
bus_space_write_1(asc_tag, asc_handle, 0x815 + 8 * i,
(freq >> 16) & 0xff);
bus_space_write_1(asc_tag, asc_handle, 0x816 + 8 * i,
(freq >> 8) & 0xff);
bus_space_write_1(asc_tag, asc_handle, 0x817 + 8 * i,
(freq) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x814 + 8 * i, (cfreq >> 24) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x815 + 8 * i, (cfreq >> 16) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x816 + 8 * i, (cfreq >> 8) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x817 + 8 * i, (cfreq) & 0xff);
} /* frequency; should put cur_beep.freq in here
* somewhere. */
bus_space_write_1(asc_tag, asc_handle, 0x807, 3); /* 44 ? */
bus_space_write_1(asc_tag, asc_handle, 0x806,
255 * bell_volume / 100);
bus_space_write_1(asc_tag, asc_handle, 0x805, 0);
bus_space_write_1(asc_tag, asc_handle, 0x80f, 0);
bus_space_write_1(asc_tag, asc_handle, 0x802, 2); /* sampled */
bus_space_write_1(asc_tag, asc_handle, 0x801, 2); /* enable sampled */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x807, 3); /* 44 ? */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x806,
255 * volume / 100);
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x805, 0);
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x80f, 0);
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x802, 2); /* sampled */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x801, 2); /* enable sampled */
}
bell_ringing++;
timeout((void *) asc_bellstop, 0, bell_length);
sc->sc_ringing++;
timeout((void *) asc_stop_bell, sc, length);
return (0);
}
static void
asc_stop_bell(arg)
void *arg;
{
struct asc_softc *sc = (struct asc_softc *) arg;
if (!sc)
return;
if (sc->sc_ringing > 1000 || sc->sc_ringing < 0)
panic("bell got out of sync?");
if (--sc->sc_ringing == 0) /* disable ASC */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x801, 0);
}

View File

@ -1,44 +0,0 @@
/* $NetBSD: asc.h,v 1.3 1995/04/21 02:47:46 briggs Exp $ */
/*-
* Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo,
* Michael L. Finch, Bradley A. Grantham, and
* Lawrence A. Kesteloot
* 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
* notice, this list of conditions and the following disclaimer.
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Alice Group.
* 4. The names of the Alice Group or any of its members may not be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``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 ALICE GROUP 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.
*/
/*
* ASC driver code and asc_ringbell() support header
*/
int asc_ringbell();
int asc_getbellparams __P((int *freq, int *length, int *volume));
int asc_setbellparams __P((int freq, int length, int volume));

View File

@ -1,4 +1,4 @@
/* $NetBSD: ascvar.h,v 1.1 1996/05/05 06:16:28 briggs Exp $ */
/* $NetBSD: ascvar.h,v 1.2 1997/02/11 07:47:37 scottr Exp $ */
/*
* Copyright (c) 1995 Allen Briggs. All rights reserved.
@ -29,7 +29,20 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int asc_setbellparams __P((int freq, int length, int volume));
int asc_getbellparams __P((int *freq, int *length, int *volume));
void asc_bellstop __P((int param));
int asc_ringbell __P((void));
#define ASCUNIT(d) ((d) & 0x7)
struct asc_softc {
struct device sc_dev;
bus_space_tag_t sc_tag;
bus_space_handle_t sc_handle;
int sc_open;
int sc_ringing;
};
int ascopen __P((dev_t dev, int flag, int mode, struct proc *p));
int ascclose __P((dev_t dev, int flag, int mode, struct proc *p));
int ascread __P((dev_t, struct uio *, int));
int ascwrite __P((dev_t, struct uio *, int));
int ascioctl __P((dev_t, int, caddr_t, int, struct proc *p));
int ascpoll __P((dev_t dev, int events, struct proc *p));
int ascmmap __P((dev_t dev, int off, int prot));

View File

@ -1,5 +1,35 @@
/* $NetBSD: asc.c,v 1.16 1997/02/03 17:36:00 scottr Exp $ */
/* $NetBSD: asc.c,v 1.17 1997/02/11 07:47:36 scottr Exp $ */
/*
* Copyright (C) 1997 Scott Reynolds
* 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
* notice, this list of conditions and the following disclaimer.
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Scott Reynolds.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 REGENTS OR CONTRIBUTORS 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.
*/
/*-
* Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo,
* Michael L. Finch, Bradley A. Grantham, and
@ -34,7 +64,7 @@
*/
/*
* ASC driver code and asc_ringbell() support
* ASC driver code and console bell support
*/
#include <sys/types.h>
@ -44,6 +74,10 @@
#include <sys/systm.h>
#include <sys/param.h>
#include <sys/device.h>
#include <sys/poll.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
@ -55,21 +89,16 @@
#define MAC68K_ASC_BASE ((caddr_t) 0x50f14000)
#define MAC68K_ASC_LEN 0x01000
/* bell support data */
static int asc_configured = 0;
static bus_space_tag_t asc_tag = MAC68K_BUS_SPACE_MEM;
static bus_space_handle_t asc_handle;
static u_int8_t asc_wave_tab[0x800];
static int bell_freq = 1880;
static int bell_length = 10;
static int bell_volume = 100;
static int bell_ringing = 0;
static int asc_ring_bell __P((void *, int, int, int));
static void asc_stop_bell __P((void *));
static int ascmatch __P((struct device *, struct cfdata *, void *));
static void ascattach __P((struct device *, struct device *, void *));
static int ascmatch __P((struct device *, struct cfdata *, void *));
static void ascattach __P((struct device *, struct device *, void *));
struct cfattach asc_ca = {
sizeof(struct device), ascmatch, ascattach
sizeof(struct asc_softc), ascmatch, ascattach
};
struct cfdriver asc_cd = {
@ -82,18 +111,12 @@ ascmatch(parent, cf, aux)
struct cfdata *cf;
void *aux;
{
static int asc_matched = 0;
struct obio_attach_args *oa = aux;
bus_space_tag_t bst = MAC68K_BUS_SPACE_MEM;
bus_space_handle_t bsh;
bus_addr_t addr;
int rval = 0;
/* Allow only one instance. */
if (asc_matched)
return (0);
asc_matched = 1;
addr = (bus_addr_t) (oa->oa_addr ? oa->oa_addr : MAC68K_ASC_BASE);
if (bus_space_map(bst, addr, MAC68K_ASC_LEN, 0, &bsh))
@ -114,141 +137,210 @@ ascattach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct asc_softc *sc = (struct asc_softc *) self;
struct obio_attach_args *oa = aux;
bus_addr_t addr;
int i;
sc->sc_tag = MAC68K_BUS_SPACE_MEM;
addr = (bus_addr_t) (oa->oa_addr ? oa->oa_addr : MAC68K_ASC_BASE);
if (bus_space_map(asc_tag, addr, MAC68K_ASC_LEN, 0,
&asc_handle)) {
printf("%s: can't map memory space\n", self->dv_xname);
if (bus_space_map(sc->sc_tag, addr, MAC68K_ASC_LEN, 0,
&sc->sc_handle)) {
printf("%s: can't map memory space\n", sc->sc_dev.dv_xname);
return;
}
sc->sc_open = 0;
sc->sc_ringing = 0;
printf(" Apple sound chip\n");
asc_configured = 1;
for (i = 0; i < 256; i++) { /* up part of wave, four voices? */
asc_wave_tab[i] = i / 4;
asc_wave_tab[i + 512] = i / 4;
asc_wave_tab[i + 1024] = i / 4;
asc_wave_tab[i + 1536] = i / 4;
}
for (i = 0; i < 256; i++) { /* down part of wave, four voices? */
asc_wave_tab[i + 256] = 0x3f - (i / 4);
asc_wave_tab[i + 768] = 0x3f - (i / 4);
asc_wave_tab[i + 1280] = 0x3f - (i / 4);
asc_wave_tab[i + 1792] = 0x3f - (i / 4);
}
printf(": Apple Sound Chip");
if (oa->oa_addr)
printf(" at %p", oa->oa_addr);
printf("\n");
mac68k_set_bell_callback(asc_ring_bell, sc);
}
int
asc_setbellparams(freq, length, volume)
int freq;
int length;
int volume;
int
ascopen(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
if (!asc_configured)
return (ENODEV);
struct asc_softc *sc;
int unit;
/*
* I only perform these checks for sanity. I suppose
* someone might want a bell that rings all day, but then
* they can make kernel mods themselves.
*/
if (freq < 10 || freq > 40000)
return (EINVAL);
if (length < 0 || length > 3600)
return (EINVAL);
if (volume < 0 || volume > 100)
return (EINVAL);
bell_freq = freq;
bell_length = length;
bell_volume = volume;
unit = ASCUNIT(dev);
sc = asc_cd.cd_devs[unit];
if (unit >= asc_cd.cd_ndevs)
return (ENXIO);
if (sc->sc_open)
return (EBUSY);
sc->sc_open = 1;
return (0);
}
int
asc_getbellparams(freq, length, volume)
int *freq;
int *length;
int *volume;
int
ascclose(dev, flag, mode, p)
dev_t dev;
int flag;
int mode;
struct proc *p;
{
if (!asc_configured)
return (ENODEV);
struct asc_softc *sc;
*freq = bell_freq;
*length = bell_length;
*volume = bell_volume;
sc = asc_cd.cd_devs[ASCUNIT(dev)];
sc->sc_open = 0;
return (0);
}
void
asc_bellstop(param)
int param;
int
ascread(dev, uio, ioflag)
dev_t dev;
struct uio *uio;
int ioflag;
{
if (!asc_configured)
return;
if (bell_ringing > 1000 || bell_ringing < 0)
panic("bell got out of sync?");
if (--bell_ringing == 0) /* disable ASC */
bus_space_write_1(asc_tag, asc_handle, 0x801, 0);
return (ENXIO);
}
int
asc_ringbell()
int
ascwrite(dev, uio, ioflag)
dev_t dev;
struct uio *uio;
int ioflag;
{
int i;
unsigned long freq;
return (ENXIO);
}
if (!asc_configured)
int
ascioctl(dev, cmd, data, flag, p)
dev_t dev;
int cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct asc_softc *sc;
int error;
int unit = ASCUNIT(dev);
sc = asc_cd.cd_devs[unit];
error = 0;
switch (cmd) {
default:
error = EINVAL;
break;
}
return (error);
}
int
ascpoll(dev, events, p)
dev_t dev;
int events;
struct proc *p;
{
return (events & (POLLOUT | POLLWRNORM));
}
int
ascmmap(dev, off, prot)
dev_t dev;
int off;
int prot;
{
int unit = ASCUNIT(dev);
struct asc_softc *sc;
vm_offset_t pa;
sc = asc_cd.cd_devs[unit];
if (off < MAC68K_ASC_LEN) {
pa = pmap_extract(pmap_kernel(), (vm_offset_t) sc->sc_handle);
return mac68k_btop(pa + off);
}
return (-1);
}
static int
asc_ring_bell(arg, freq, length, volume)
void *arg;
int freq, length, volume;
{
struct asc_softc *sc = (struct asc_softc *) arg;
unsigned long cfreq;
int i;
if (!sc)
return (ENODEV);
if (bell_ringing == 0) {
if (sc->sc_ringing == 0) {
for (i = 0; i < 0x800; i++)
bus_space_write_1(asc_tag, asc_handle, i, 0);
for (i = 0; i < 256; i++) {
bus_space_write_1(asc_tag, asc_handle, i, i / 4);
bus_space_write_1(asc_tag, asc_handle, i + 512, i / 4);
bus_space_write_1(asc_tag, asc_handle, i + 1024, i / 4);
bus_space_write_1(asc_tag, asc_handle, i + 1536, i / 4);
} /* up part of wave, four voices ? */
for (i = 0; i < 256; i++) {
bus_space_write_1(asc_tag, asc_handle, i + 256,
0x3f - (i / 4));
bus_space_write_1(asc_tag, asc_handle, i + 768,
0x3f - (i / 4));
bus_space_write_1(asc_tag, asc_handle, i + 1280,
0x3f - (i / 4));
bus_space_write_1(asc_tag, asc_handle, i + 1792,
0x3f - (i / 4));
} /* down part of wave, four voices ? */
bus_space_write_multi_1(sc->sc_tag, sc->sc_handle,
0, 0, 0x800);
bus_space_write_region_1(sc->sc_tag, sc->sc_handle,
0, asc_wave_tab, 0x800);
/* Fix this. Need to find exact ASC sampling freq */
freq = 65536 * bell_freq / 466;
cfreq = 65536 * freq / 466;
/* printf("beep: from %d, %02x %02x %02x %02x\n",
* cur_beep.freq, (freq >> 24) & 0xff, (freq >> 16) & 0xff,
* (freq >> 8) & 0xff, (freq) & 0xff); */
* cur_beep.freq, (cfreq >> 24) & 0xff, (cfreq >> 16) & 0xff,
* (cfreq >> 8) & 0xff, (cfreq) & 0xff); */
for (i = 0; i < 8; i++) {
bus_space_write_1(asc_tag, asc_handle, 0x814 + 8 * i,
(freq >> 24) & 0xff);
bus_space_write_1(asc_tag, asc_handle, 0x815 + 8 * i,
(freq >> 16) & 0xff);
bus_space_write_1(asc_tag, asc_handle, 0x816 + 8 * i,
(freq >> 8) & 0xff);
bus_space_write_1(asc_tag, asc_handle, 0x817 + 8 * i,
(freq) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x814 + 8 * i, (cfreq >> 24) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x815 + 8 * i, (cfreq >> 16) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x816 + 8 * i, (cfreq >> 8) & 0xff);
bus_space_write_1(sc->sc_tag, sc->sc_handle,
0x817 + 8 * i, (cfreq) & 0xff);
} /* frequency; should put cur_beep.freq in here
* somewhere. */
bus_space_write_1(asc_tag, asc_handle, 0x807, 3); /* 44 ? */
bus_space_write_1(asc_tag, asc_handle, 0x806,
255 * bell_volume / 100);
bus_space_write_1(asc_tag, asc_handle, 0x805, 0);
bus_space_write_1(asc_tag, asc_handle, 0x80f, 0);
bus_space_write_1(asc_tag, asc_handle, 0x802, 2); /* sampled */
bus_space_write_1(asc_tag, asc_handle, 0x801, 2); /* enable sampled */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x807, 3); /* 44 ? */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x806,
255 * volume / 100);
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x805, 0);
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x80f, 0);
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x802, 2); /* sampled */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x801, 2); /* enable sampled */
}
bell_ringing++;
timeout((void *) asc_bellstop, 0, bell_length);
sc->sc_ringing++;
timeout((void *) asc_stop_bell, sc, length);
return (0);
}
static void
asc_stop_bell(arg)
void *arg;
{
struct asc_softc *sc = (struct asc_softc *) arg;
if (!sc)
return;
if (sc->sc_ringing > 1000 || sc->sc_ringing < 0)
panic("bell got out of sync?");
if (--sc->sc_ringing == 0) /* disable ASC */
bus_space_write_1(sc->sc_tag, sc->sc_handle, 0x801, 0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ascvar.h,v 1.1 1996/05/05 06:16:28 briggs Exp $ */
/* $NetBSD: ascvar.h,v 1.2 1997/02/11 07:47:37 scottr Exp $ */
/*
* Copyright (c) 1995 Allen Briggs. All rights reserved.
@ -29,7 +29,20 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int asc_setbellparams __P((int freq, int length, int volume));
int asc_getbellparams __P((int *freq, int *length, int *volume));
void asc_bellstop __P((int param));
int asc_ringbell __P((void));
#define ASCUNIT(d) ((d) & 0x7)
struct asc_softc {
struct device sc_dev;
bus_space_tag_t sc_tag;
bus_space_handle_t sc_handle;
int sc_open;
int sc_ringing;
};
int ascopen __P((dev_t dev, int flag, int mode, struct proc *p));
int ascclose __P((dev_t dev, int flag, int mode, struct proc *p));
int ascread __P((dev_t, struct uio *, int));
int ascwrite __P((dev_t, struct uio *, int));
int ascioctl __P((dev_t, int, caddr_t, int, struct proc *p));
int ascpoll __P((dev_t dev, int events, struct proc *p));
int ascmmap __P((dev_t dev, int off, int prot));