62c631ed7f
Without this, ioctl commands for setting formats and speeds were essentially ignored for simplex devices until the application actually performed a read or write. * Make sure that both channels are set in the SB mixer code and provide a mixer table specifically for the ess18xx which supports the extended accuracy available on this part. * Fix a stupid bug in ess_format() which ignored the passed-in format and changed the hardware based on the value which was set last time. This meant that the hardware setting was often not set correctly at all. * Add a custom identify driver for the ESS1888 which automagically detects and adds the device in a pseudo-PnP way. This driver also emits the magic sequence which enables the sound hardware after a hard reset, allowing it to work correctly for the sound hardware of a PWS 433au (and probably all other PWS class alpha machines). With these changes, I was able to play back simple sounds on my 433au. I have not tested recording or any other formats other than 8bit ulaw and 16bit stereo.
172 lines
4.3 KiB
C
172 lines
4.3 KiB
C
/*-
|
|
* Copyright (c) 1999 Doug Rabson
|
|
* 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.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
*
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
#include <dev/pcm/sound.h>
|
|
#include <dev/pcm/isa/sb.h>
|
|
|
|
#if NPCM > 0
|
|
|
|
static int
|
|
es1888_dspready(u_int32_t port)
|
|
{
|
|
return ((inb(port + SBDSP_STATUS) & 0x80) == 0);
|
|
}
|
|
|
|
static int
|
|
es1888_dspwr(u_int32_t port, u_char val)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < 1000; i++) {
|
|
if (es1888_dspready(port)) {
|
|
outb(port + SBDSP_CMD, val);
|
|
return 1;
|
|
}
|
|
if (i > 10) DELAY((i > 100)? 1000 : 10);
|
|
}
|
|
printf("es1888_dspwr(0x%02x) timed out.\n", val);
|
|
return 0;
|
|
}
|
|
|
|
static u_int
|
|
es1888_get_byte(u_int32_t port)
|
|
{
|
|
int i;
|
|
|
|
for (i = 1000; i > 0; i--) {
|
|
if (inb(port + DSP_DATA_AVAIL) & 0x80)
|
|
return inb(port + DSP_READ);
|
|
else
|
|
DELAY(20);
|
|
}
|
|
return 0xffff;
|
|
}
|
|
|
|
static int
|
|
es1888_reset(u_int32_t port)
|
|
{
|
|
outb(port + SBDSP_RST, 3);
|
|
DELAY(100);
|
|
outb(port + SBDSP_RST, 0);
|
|
if (es1888_get_byte(port) != 0xAA) {
|
|
DEB(printf("sb_reset_dsp 0x%lx failed\n",
|
|
rman_get_start(d->io_base)));
|
|
return ENXIO; /* Sorry */
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
es1888_configuration_mode(void)
|
|
{
|
|
/*
|
|
* Emit the Read-Sequence-Key to enter configuration
|
|
* mode. Note this only works after a reset (or after bit 2 of
|
|
* mixer register 0x40 is set).
|
|
*
|
|
* 3 reads from 0x229 in a row guarantees reset of key
|
|
* sequence to beginning.
|
|
*/
|
|
inb(0x229);
|
|
inb(0x229);
|
|
inb(0x229);
|
|
|
|
inb(0x22b); /* state 1 */
|
|
inb(0x229); /* state 2 */
|
|
inb(0x22b); /* state 3 */
|
|
inb(0x229); /* state 4 */
|
|
inb(0x229); /* state 5 */
|
|
inb(0x22b); /* state 6 */
|
|
inb(0x229); /* state 7 */
|
|
}
|
|
|
|
static void
|
|
es1888_set_port(u_int32_t port)
|
|
{
|
|
es1888_configuration_mode();
|
|
inb(port);
|
|
}
|
|
|
|
static void
|
|
es1888_identify(driver_t *driver, device_t parent)
|
|
{
|
|
u_int32_t lo, hi;
|
|
device_t dev;
|
|
|
|
es1888_set_port(0x220);
|
|
es1888_reset(0x220);
|
|
|
|
/*
|
|
* Check identification bytes for es1888.
|
|
*/
|
|
es1888_dspwr(0x220, 0xe7);
|
|
hi = es1888_get_byte(0x220);
|
|
lo = es1888_get_byte(0x220);
|
|
printf("es1888_identify: 0x%02x%02x\n", hi, lo);
|
|
if (hi != 0x68 || (lo & 0xf0) != 0x80)
|
|
return;
|
|
|
|
/*
|
|
* Program irq and drq.
|
|
*/
|
|
es1888_dspwr(0x220, 0xc6); /* enter extended mode */
|
|
es1888_dspwr(0x220, 0xb1); /* write register b1 */
|
|
es1888_dspwr(0x220, 0x14); /* enable irq 5 */
|
|
es1888_dspwr(0x220, 0xb2); /* write register b1 */
|
|
es1888_dspwr(0x220, 0x18); /* enable drq 1 */
|
|
|
|
/*
|
|
* Create the device and program its resources.
|
|
*/
|
|
dev = BUS_ADD_CHILD(parent, ISA_ORDER_PNP, NULL, -1);
|
|
bus_set_resource(dev, SYS_RES_IOPORT, 0, 0x220, 0x10);
|
|
bus_set_resource(dev, SYS_RES_IRQ, 0, 5, 1);
|
|
bus_set_resource(dev, SYS_RES_DRQ, 0, 1, 1);
|
|
isa_set_vendorid(dev, PNP_EISAID("ESS1888"));
|
|
isa_set_logicalid(dev, PNP_EISAID("ESS1888"));
|
|
}
|
|
|
|
static device_method_t es1888_methods[] = {
|
|
/* Device interface */
|
|
DEVMETHOD(device_identify, es1888_identify),
|
|
|
|
{ 0, 0 }
|
|
};
|
|
|
|
static driver_t es1888_driver = {
|
|
"pcm",
|
|
es1888_methods,
|
|
1, /* no softc */
|
|
};
|
|
|
|
static devclass_t pcm_devclass;
|
|
|
|
DRIVER_MODULE(es1888, isa, es1888_driver, pcm_devclass, 0, 0);
|
|
|
|
#endif /* NPCM > 0 */
|