7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Redistribution and use in source and binary forms, with or without
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * modification, are permitted provided that the following conditions
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * 1. Redistributions of source code must retain the above copyright
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * notice, this list of conditions and the following disclaimer.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * notice, this list of conditions and the following disclaimer in the
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * documentation and/or other materials provided with the distribution.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * SUCH DAMAGE.
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Use is subject to license terms.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Copyright (C) 4Front Technologies 1996-2008.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * NB: The Solo-1 is a bit schizophrenic compared to most devices.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * It has two separate DMA engines for PCM data. The first can do
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * either capture or playback, and supports various Sound Blaster
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * compatibility features. The second is dedicated to playback. The
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * two engines have very little in common when it comes to programming
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * We configure engine 1 for record, and engine 2 for playback. Both
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * are configured for 48 kHz stereo 16-bit signed PCM.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * ESS Solo-1 only implements the low 24-bits on Audio1, and requires
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * 64KB alignment. For Audio2, it implements the full 32-bit address
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * space, but requires a 1MB address boundary. Audio1 is used for
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * recording, and Audio2 is used for playback.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amorestatic struct ddi_dma_attr dma_attr_audio1 = {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore 0 /* dma_attr_flags */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amorestatic struct ddi_dma_attr dma_attr_audio2 = {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore 0 /* dma_attr_flags */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * For the sake of simplicity, this driver fixes a few parameters with
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define SOLO_FRAGSZ (SOLO_FRAGFR * (SOLO_NCHAN * SOLO_SAMPSZ))
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define SOLO_BUFFR (SOLO_NFRAGS * SOLO_FRAGFR)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define SOLO_BUFSZ (SOLO_NFRAGS * SOLO_FRAGSZ)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore AUDIO_PORT_AUX2IN, /* this is really mono-in */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoretypedef enum {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Audio engines
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Mapped registers
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Common code for the pcm function
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * solo_cmd write a single byte to the CMD port.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * solo_cmd1 write a CMD + 1 byte arg
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * ess_get_byte returns a single byte from the DSP data port
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * solo_write is actually solo_cmd1
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * solo_read access ext. regs via solo_cmd(0xc0, reg) followed by solo_get_byte
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore ddi_get8(port.acch, (void *)(port.base + (regno)))
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore ddi_get16(port.acch, (void *)(port.base + (regno)))
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore ddi_get32(port.acch, (void *)(port.base + (regno)))
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore ddi_put8(port.acch, (void *)(port.base + (regno)), data)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore ddi_put16(port.acch, (void *)(port.base + (regno)), data)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore ddi_put32(port.acch, (void *)(port.base + (regno)), data)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return ((PORT_RD8(dev->sb, 0xc) & 0x80) == 0 ? true : false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore for (i = 0; i < 1000; i++) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (true);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "solo_dspwr(0x%02x) timed out", val);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_cmd1(solo_dev_t *dev, uint8_t cmd, uint8_t val)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_setmixer(solo_dev_t *dev, uint8_t port, uint8_t value)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore PORT_WR8(dev->sb, 0x4, port); /* Select register */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore PORT_WR8(dev->sb, 0x4, port); /* Select register */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore for (int i = 1000; i > 0; i--) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "timeout waiting to read DSP port");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (0xff);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_write(solo_dev_t *dev, uint8_t reg, uint8_t val)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (solo_cmd(dev, 0xc0) && solo_cmd(dev, reg)) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (0xff);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "solo_reset_dsp failed");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false); /* Sorry */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (true);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* ack the interrupt */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x7a, solo_getmixer(dev, 0x7a) & ~0x80);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* ack the interrupt */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_mixer_scale(solo_dev_t *dev, solo_ctrl_num_t num)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * We disable hardware volume control (i.e. async updates to volume).
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * We could in theory support this, but making it work right can be
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * tricky, and we doubt it is widely used.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x64, solo_getmixer(dev, 0x64) | 0xc);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* master volume has 6 bits per channel, bit 6 indicates mute */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore v = (dev->ctrls[CTL_FRONT].val >> 8) & 0xff;
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore v = v | (v << 4);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * The Solo-1 has dual stereo mixers (one for input and one for output),
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * with separate volume controls for each.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x68, rec & (1 << INPUT_MIC) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x1a, mon & (1 << INPUT_MIC) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x6e, rec & (1 << INPUT_LINE) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x3e, mon & (1 << INPUT_LINE) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x6a, rec & (1 << INPUT_CD) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x38, mon & (1 << INPUT_CD) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x6c, rec & (1 << INPUT_AUX) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x3a, mon & (1 << INPUT_AUX) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore v = v | (v << 4);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x6f, rec & (1 << INPUT_MONO) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x6d, mon & (1 << INPUT_MONO) ? v : 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x7d, solo_getmixer(dev, 0x7d) | 0x8);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x7d, solo_getmixer(dev, 0x7d) & ~(0x8));
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore v = v | (v << 4);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* record-what-you-hear mode */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* use record mixer */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define PLAYCTL (AUDIO_CTRL_FLAG_RW | AUDIO_CTRL_FLAG_PLAY)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define RECCTL (AUDIO_CTRL_FLAG_RW | AUDIO_CTRL_FLAG_REC)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define MONCTL (AUDIO_CTRL_FLAG_RW | AUDIO_CTRL_FLAG_MONITOR)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define PCMVOL (PLAYCTL | AUDIO_CTRL_FLAG_PCMVOL)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define MAINVOL (PLAYCTL | AUDIO_CTRL_FLAG_MAINVOL)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore#define RECVOL (RECCTL | AUDIO_CTRL_FLAG_RECVOL)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_alloc_ctrl(solo_dev_t *dev, uint32_t num, uint64_t val)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore desc.acd_flags = RECCTL | AUDIO_CTRL_FLAG_MULTI;
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore for (int i = 0; solo_insrcs[i]; i++) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore desc.acd_flags = MONCTL | AUDIO_CTRL_FLAG_MULTI;
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore for (int i = 0; solo_insrcs[i]; i++) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore pc->ctrl = audio_dev_add_control(dev->adev, &desc,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_alloc_ctrl(dev, CTL_RECSRC, (1U << INPUT_MIC));
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (true);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore/* utility functions for ESS */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * During recording, this register is known to give back
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * garbage if it's not quiescent while being read. This hack
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * attempts to work around it. We also suspend the DMA
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * while we do this, to minimize record distortion.
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore PORT_WR8(dev->vc, 0xf, 0); /* restart DMA */
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * Note, this is a pretty bad situation, because we'll
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * not have an accurate idea of our position. But its
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * better than making a bad alteration. If we had FMA
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * for audio devices, this would be a good point to
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amore * raise a fault.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* sample rate - 48 kHz */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* filter cutoff */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_write(dev, 0xa2, solo_calcfilter(SOLO_RATE));
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* mono/stereo - bit 0 set, bit 1 clear */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_write(dev, 0xa8, (solo_read(dev, 0xa8) & ~0x03) | 1);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore (void) solo_cmd(dev, 0xd3); /* turn off DAC1 output */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* setup fifo for signed 16-bit stereo */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore v = v | (v << 4);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore PORT_WR8(dev->vc, 0xd, 0xff); /* clear DMA */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore PORT_WR8(dev->vc, 0xf, 0x01); /* stop DMA */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* transfer length low, high */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* autoinit, dma dir, go for it */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* NB: We might be in quiesce, without a lock held */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_write(dev, 0xb8, solo_read(dev, 0xb8) & ~0x01);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore offset = SOLO_BUFSZ - PORT_RD16(dev->io, 0x4);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* program transfer type */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* sample rate - 48 kHz */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x72, solo_calcfilter(SOLO_RATE));
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* transfer length low & high */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x76, (len & 0xff00) >> 8);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* enable irq, set signed 16-bit stereo format */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* this crazy initialization appears to help with fifo weirdness */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* start the engine running */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore PORT_WR8(dev->io, 0x6, 0x0a); /* autoinit, enable */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore v = v | (v << 4);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* NB: We might be in quiesce, without a lock held */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0x78, solo_getmixer(dev, 0x78) & ~0x03);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Audio entry points.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_chinfo(void *arg, int chan, unsigned *offset, unsigned *incr)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore (void) ddi_dma_sync(e->dmah, 0, 0, e->syncdir);
68c47f65208790c466e5e484f2293d3baed71c6aGarrett D'Amoresolo_open(void *arg, int f, unsigned *nframes, caddr_t *buf)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amorestatic audio_engine_ops_t solo_engine_ops = {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore (void) ddi_intr_remove_handler(dev->ihandle);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* release play resources */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore (void) ddi_dma_unbind_handle(dev->play.dmah);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_remove_engine(dev->adev, dev->play.engine);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* release record resources */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore (void) ddi_dma_unbind_handle(dev->rec.dmah);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_remove_engine(dev->adev, dev->rec.engine);
7f8098eddd24ef5d0d43749a8f4c2c245bdcc077Garrett D'Amore for (int i = 0; i < CTL_NUM; i++) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if ((ddi_intr_alloc(dev->dip, &dev->ihandle, DDI_INTR_TYPE_FIXED,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore 0, 1, &actual, DDI_INTR_ALLOC_NORMAL) != DDI_SUCCESS) ||
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "can't alloc intr handle");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_intr_get_pri(dev->ihandle, &ipri) != DDI_SUCCESS) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "can't determine intr priority");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_intr_add_handler(dev->ihandle, solo_intr, dev,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "can't add intr handler");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore mutex_init(&dev->mutex, NULL, MUTEX_DRIVER, DDI_INTR_PRI(ipri));
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (true);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* map registers */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_regs_map_setup(dip, 1, &dev->io.base, 0, 0, &acc_attr,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "can't map IO registers");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_regs_map_setup(dip, 2, &dev->sb.base, 0, 0, &acc_attr,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "can't map SB registers");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_regs_map_setup(dip, 3, &dev->vc.base, 0, 0, &acc_attr,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "can't map VC registers");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (true);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Legacy audio register -- disable legacy audio. We also
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * arrange for 16-bit I/O address decoding.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* this version disables the MPU, FM synthesis (Adlib), and Game Port */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore pci_config_put16(dev->pcih, ESS_PCI_LEGACYCONTROL, 0x8041);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Note that Solo-1 uses I/O space for all BARs, and hardwires
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * the upper 32-bits to zero.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore data = pci_config_get32(dev->pcih, PCI_CONF_BASE2);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore pci_config_put16(dev->pcih, ESS_PCI_DDMACONTROL, data & 0xffff);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Make sure that legacy IRQ and DRQ are disbled. We disable most
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * other legacy features too.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore pci_config_put16(dev->pcih, ESS_PCI_CONFIG, 0);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* enable extended mode */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore PORT_WR8(dev->io, 0x7, 0x30); /* enable audio irqs */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* demand mode, 4 bytes/xfer */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * This sets Audio 2 (playback) to use its own independent
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * rate control, and gives us 48 kHz compatible divisors. It
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * also bypasses the switched capacitor filter.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* irq control */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_write(dev, 0xb1, (solo_read(dev, 0xb1) & 0x0f) | 0x50);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* drq control */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_write(dev, 0xb2, (solo_read(dev, 0xb2) & 0x0f) | 0x50);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore solo_setmixer(dev, 0, 0); /* reset mixer settings */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (true);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_alloc_engine(solo_dev_t *dev, int engno)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore dflags = DDI_DMA_WRITE | DDI_DMA_CONSISTENT;
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "bad engine number!");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_dma_alloc_handle(dev->dip, dattr, DDI_DMA_SLEEP, NULL,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "%s dma handle alloc failed", desc);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_dma_mem_alloc(e->dmah, SOLO_BUFSZ, &buf_attr,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore DDI_DMA_CONSISTENT, DDI_DMA_SLEEP, NULL, &e->kaddr,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "%s dma memory alloc failed", desc);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore /* ensure that the buffer is zeroed out properly */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (ddi_dma_addr_bind_handle(e->dmah, NULL, e->kaddr, SOLO_BUFSZ,
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore dflags, DDI_DMA_SLEEP, NULL, &c, &ccnt) != DDI_DMA_MAPPED) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "%s dma binding failed", desc);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore * Allocate and configure audio engine.
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore e->engine = audio_engine_alloc(&solo_engine_ops, caps);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "record audio_engine_alloc failed");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (false);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore return (true);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "unable to resume audio!");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(dev->adev, "reboot or reload driver to reset");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_set_description(dev->adev, "ESS Solo-1 PCI AudioDrive");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (pci_config_setup(dip, &dev->pcih) != DDI_SUCCESS) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore audio_dev_warn(NULL, "pci_config_setup failed");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore data = pci_config_get16(dev->pcih, PCI_CONF_COMM);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore pci_config_put16(dev->pcih, PCI_CONF_COMM, data);
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (audio_dev_register(dev->adev) != DDI_SUCCESS) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore "unable to register with audio framework");
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if (audio_dev_unregister(dev->adev) != DDI_SUCCESS) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_ddi_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if ((dev = ddi_get_driver_private(dip)) == NULL) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amoresolo_ddi_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore if ((dev = ddi_get_driver_private(dip)) == NULL) {
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore PORT_WR8(dev->io, 0x7, 0); /* disable all irqs */
7a4f122cf63a91c2888629e433b5f5ee7536a802Garrett D'Amore 0, /* refcnt */