1998-01-13 22:15:32 +03:00
|
|
|
/* $NetBSD: asc.c,v 1.26 1998/01/13 19:24:50 scottr Exp $ */
|
1994-10-26 11:45:48 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
/*
|
|
|
|
* 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.
|
1997-10-10 09:54:48 +04:00
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
1997-02-11 10:47:36 +03:00
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
1997-02-24 08:47:33 +03: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.
|
1997-02-11 10:47:36 +03:00
|
|
|
*/
|
1993-12-21 06:16:01 +03:00
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1997-02-11 10:47:36 +03:00
|
|
|
* ASC driver code and console bell support
|
1993-12-21 06:16:01 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1995-09-21 07:36:25 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-12-21 06:16:01 +03:00
|
|
|
#include <sys/errno.h>
|
1994-05-06 21:38:38 +04:00
|
|
|
#include <sys/time.h>
|
1993-12-21 06:16:01 +03:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/param.h>
|
1994-07-21 04:44:00 +04:00
|
|
|
#include <sys/device.h>
|
1997-02-11 10:47:36 +03:00
|
|
|
#include <sys/poll.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/pmap.h>
|
1996-11-09 20:26:26 +03:00
|
|
|
|
|
|
|
#include <machine/autoconf.h>
|
1994-07-21 04:44:00 +04:00
|
|
|
#include <machine/cpu.h>
|
1997-02-03 20:36:00 +03:00
|
|
|
#include <machine/bus.h>
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-08-12 02:53:26 +04:00
|
|
|
#include <mac68k/dev/ascvar.h>
|
|
|
|
#include <mac68k/dev/obiovar.h>
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-09-16 20:28:07 +04:00
|
|
|
#define MAC68K_ASC_BASE 0x50f14000
|
|
|
|
#define MAC68K_IIFX_ASC_BASE 0x50f10000
|
|
|
|
#define MAC68K_ASC_LEN 0x01000
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
static u_int8_t asc_wave_tab[0x800];
|
1997-02-03 20:36:00 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
static int asc_ring_bell __P((void *, int, int, int));
|
|
|
|
static void asc_stop_bell __P((void *));
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
static int ascmatch __P((struct device *, struct cfdata *, void *));
|
|
|
|
static void ascattach __P((struct device *, struct device *, void *));
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1996-03-17 04:26:49 +03:00
|
|
|
struct cfattach asc_ca = {
|
1997-02-11 10:47:36 +03:00
|
|
|
sizeof(struct asc_softc), ascmatch, ascattach
|
1996-03-17 04:26:49 +03:00
|
|
|
};
|
|
|
|
|
1998-01-12 21:59:04 +03:00
|
|
|
extern struct cfdriver asc_cd;
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1994-07-21 04:44:00 +04:00
|
|
|
static int
|
1996-12-16 19:17:02 +03:00
|
|
|
ascmatch(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1993-12-21 06:16:01 +03:00
|
|
|
{
|
1997-02-12 01:44:25 +03:00
|
|
|
struct obio_attach_args *oa = (struct obio_attach_args *)aux;
|
1997-02-03 20:36:00 +03:00
|
|
|
bus_addr_t addr;
|
1997-02-12 01:44:25 +03:00
|
|
|
bus_space_handle_t bsh;
|
1997-02-03 20:36:00 +03:00
|
|
|
int rval = 0;
|
|
|
|
|
1997-09-16 20:28:07 +04:00
|
|
|
if (oa->oa_addr != (-1))
|
|
|
|
addr = (bus_addr_t)oa->oa_addr;
|
|
|
|
else if (current_mac_model->machineid == MACH_MACIIFX)
|
|
|
|
addr = (bus_addr_t)MAC68K_IIFX_ASC_BASE;
|
|
|
|
else
|
|
|
|
addr = (bus_addr_t)MAC68K_ASC_BASE;
|
1997-02-03 20:36:00 +03:00
|
|
|
|
1997-02-12 01:44:25 +03:00
|
|
|
if (bus_space_map(oa->oa_tag, addr, MAC68K_ASC_LEN, 0, &bsh))
|
1997-02-03 20:36:00 +03:00
|
|
|
return (0);
|
|
|
|
|
1998-01-13 22:15:32 +03:00
|
|
|
if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0, 1))
|
1997-02-03 20:36:00 +03:00
|
|
|
rval = 1;
|
|
|
|
else
|
|
|
|
rval = 0;
|
|
|
|
|
1997-02-12 01:44:25 +03:00
|
|
|
bus_space_unmap(oa->oa_tag, bsh, MAC68K_ASC_LEN);
|
1997-02-03 20:36:00 +03:00
|
|
|
|
|
|
|
return rval;
|
1993-12-21 06:16:01 +03:00
|
|
|
}
|
|
|
|
|
1994-07-21 04:44:00 +04:00
|
|
|
static void
|
1997-02-03 20:36:00 +03:00
|
|
|
ascattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1994-07-21 04:44:00 +04:00
|
|
|
{
|
1997-02-12 01:44:25 +03:00
|
|
|
struct asc_softc *sc = (struct asc_softc *)self;
|
|
|
|
struct obio_attach_args *oa = (struct obio_attach_args *)aux;
|
1997-02-03 20:36:00 +03:00
|
|
|
bus_addr_t addr;
|
1997-02-11 10:47:36 +03:00
|
|
|
int i;
|
1997-02-03 20:36:00 +03:00
|
|
|
|
1997-02-12 01:44:25 +03:00
|
|
|
sc->sc_tag = oa->oa_tag;
|
1997-09-16 20:28:07 +04:00
|
|
|
if (oa->oa_addr != (-1))
|
|
|
|
addr = (bus_addr_t)oa->oa_addr;
|
|
|
|
else if (current_mac_model->machineid == MACH_MACIIFX)
|
|
|
|
addr = (bus_addr_t)MAC68K_IIFX_ASC_BASE;
|
|
|
|
else
|
|
|
|
addr = (bus_addr_t)MAC68K_ASC_BASE;
|
1997-02-11 10:47:36 +03:00
|
|
|
if (bus_space_map(sc->sc_tag, addr, MAC68K_ASC_LEN, 0,
|
|
|
|
&sc->sc_handle)) {
|
1997-02-13 22:55:48 +03:00
|
|
|
printf(": can't map memory space\n");
|
1997-02-03 20:36:00 +03:00
|
|
|
return;
|
|
|
|
}
|
1997-02-11 10:47:36 +03:00
|
|
|
sc->sc_open = 0;
|
|
|
|
sc->sc_ringing = 0;
|
|
|
|
|
|
|
|
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");
|
1997-02-12 01:44:25 +03:00
|
|
|
if (oa->oa_addr != (-1))
|
|
|
|
printf(" at %x", oa->oa_addr);
|
1997-02-11 10:47:36 +03:00
|
|
|
printf("\n");
|
1997-02-03 20:36:00 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
mac68k_set_bell_callback(asc_ring_bell, sc);
|
1994-07-21 04:44:00 +04:00
|
|
|
}
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
int
|
|
|
|
ascopen(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-12-21 06:16:01 +03:00
|
|
|
{
|
1997-02-11 10:47:36 +03:00
|
|
|
struct asc_softc *sc;
|
|
|
|
int unit;
|
1996-11-09 20:26:26 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
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;
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
return (0);
|
1993-12-21 06:16:01 +03:00
|
|
|
}
|
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
int
|
|
|
|
ascclose(dev, flag, mode, p)
|
|
|
|
dev_t dev;
|
|
|
|
int flag;
|
|
|
|
int mode;
|
|
|
|
struct proc *p;
|
1993-12-21 06:16:01 +03:00
|
|
|
{
|
1997-02-11 10:47:36 +03:00
|
|
|
struct asc_softc *sc;
|
1996-11-09 20:26:26 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
sc = asc_cd.cd_devs[ASCUNIT(dev)];
|
|
|
|
sc->sc_open = 0;
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
return (0);
|
1993-12-21 06:16:01 +03:00
|
|
|
}
|
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
int
|
|
|
|
ascread(dev, uio, ioflag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int ioflag;
|
|
|
|
{
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
int
|
|
|
|
ascwrite(dev, uio, ioflag)
|
|
|
|
dev_t dev;
|
|
|
|
struct uio *uio;
|
|
|
|
int ioflag;
|
1993-12-21 06:16:01 +03:00
|
|
|
{
|
1997-02-11 10:47:36 +03:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
1996-11-09 20:26:26 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
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);
|
1997-02-03 20:36:00 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
sc = asc_cd.cd_devs[unit];
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (error);
|
1993-12-21 06:16:01 +03:00
|
|
|
}
|
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
int
|
|
|
|
ascpoll(dev, events, p)
|
|
|
|
dev_t dev;
|
|
|
|
int events;
|
|
|
|
struct proc *p;
|
|
|
|
{
|
|
|
|
return (events & (POLLOUT | POLLWRNORM));
|
|
|
|
}
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
int
|
|
|
|
ascmmap(dev, off, prot)
|
|
|
|
dev_t dev;
|
|
|
|
int off;
|
|
|
|
int prot;
|
1993-12-21 06:16:01 +03:00
|
|
|
{
|
1997-02-11 10:47:36 +03:00
|
|
|
int unit = ASCUNIT(dev);
|
|
|
|
struct asc_softc *sc;
|
|
|
|
vm_offset_t pa;
|
|
|
|
|
|
|
|
sc = asc_cd.cd_devs[unit];
|
|
|
|
if (off < MAC68K_ASC_LEN) {
|
1997-02-12 01:44:25 +03:00
|
|
|
pa = pmap_extract(pmap_kernel(), (vm_offset_t)sc->sc_handle);
|
1997-06-11 00:29:10 +04:00
|
|
|
return m68k_btop(pa + off);
|
1997-02-11 10:47:36 +03:00
|
|
|
}
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asc_ring_bell(arg, freq, length, volume)
|
|
|
|
void *arg;
|
|
|
|
int freq, length, volume;
|
|
|
|
{
|
1997-02-12 01:44:25 +03:00
|
|
|
struct asc_softc *sc = (struct asc_softc *)arg;
|
1997-02-11 10:47:36 +03:00
|
|
|
unsigned long cfreq;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!sc)
|
1997-02-03 20:36:00 +03:00
|
|
|
return (ENODEV);
|
1996-11-09 20:26:26 +03:00
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
if (sc->sc_ringing == 0) {
|
|
|
|
|
|
|
|
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);
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1995-04-21 06:47:35 +04:00
|
|
|
/* Fix this. Need to find exact ASC sampling freq */
|
1997-02-11 10:47:36 +03:00
|
|
|
cfreq = 65536 * freq / 466;
|
1993-12-21 06:16:01 +03:00
|
|
|
|
1996-10-13 07:21:13 +04:00
|
|
|
/* printf("beep: from %d, %02x %02x %02x %02x\n",
|
1997-02-11 10:47:36 +03:00
|
|
|
* cur_beep.freq, (cfreq >> 24) & 0xff, (cfreq >> 16) & 0xff,
|
|
|
|
* (cfreq >> 8) & 0xff, (cfreq) & 0xff); */
|
1995-04-21 06:47:35 +04:00
|
|
|
for (i = 0; i < 8; i++) {
|
1997-02-11 10:47:36 +03:00
|
|
|
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);
|
1995-04-21 06:47:35 +04:00
|
|
|
} /* frequency; should put cur_beep.freq in here
|
|
|
|
* somewhere. */
|
|
|
|
|
1997-02-11 10:47:36 +03:00
|
|
|
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 */
|
1993-12-21 06:16:01 +03:00
|
|
|
}
|
1997-02-11 10:47:36 +03:00
|
|
|
sc->sc_ringing++;
|
1997-02-12 01:44:25 +03:00
|
|
|
timeout(asc_stop_bell, sc, length);
|
1996-05-05 10:15:56 +04:00
|
|
|
|
1997-02-03 20:36:00 +03:00
|
|
|
return (0);
|
1993-12-21 06:16:01 +03:00
|
|
|
}
|
1997-02-11 10:47:36 +03:00
|
|
|
|
|
|
|
static void
|
|
|
|
asc_stop_bell(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
1997-02-12 01:44:25 +03:00
|
|
|
struct asc_softc *sc = (struct asc_softc *)arg;
|
1997-02-11 10:47:36 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|