/*
* Copyright 1997
* Digital Equipment Corporation. All rights reserved.
*
* This software is furnished under license and may be used and
* copied only in accordance with the following terms and conditions.
* Subject to these conditions, you may download, copy, install,
* use, modify and distribute this software in source and/or binary
* form. No title or ownership is transferred hereby.
*
* 1) Any source code used, modified or distributed must reproduce
* and retain this copyright notice and list of conditions as
* they appear in the source file.
*
* 2) No right is granted to use any trade name, trademark, or logo of
* Digital Equipment Corporation. Neither the "Digital Equipment
* Corporation" name nor any trademark or logo of Digital Equipment
* Corporation may be used to endorse or promote products derived
* from this software without the prior written permission of
* Digital Equipment Corporation.
*
* 3) This software is provided "AS-IS" and any express or implied
* warranties, including but not limited to, any implied warranties
* of merchantability, fitness for a particular purpose, or
* non-infringement are disclaimed. In no event shall DIGITAL be
* liable for any damages whatsoever, and in particular, DIGITAL
* shall not be liable for special, indirect, consequential, or
* incidental damages or damages for lost profits, loss of
* revenue or loss of use, whether such damages arise in contract,
* negligence, tort, under statute, in equity, at law or otherwise,
* even if advised of the possibility of such damage.
*/
/*
**++
**
** ess.c
**
** FACILITY:
**
** DIGITAL Network Appliance Reference Design (DNARD)
**
** MODULE DESCRIPTION:
**
** This module contains the device driver for the ESS
** Technologies 1888/1887/888 sound chip. The code in sbdsp.c was
** used as a reference point when implementing this driver.
**
** AUTHORS:
**
** Blair Fidler Software Engineering Australia
** Gold Coast, Australia.
**
** CREATION DATE:
**
** March 10, 1997.
**
** MODIFICATION HISTORY:
**
** Heavily modified by Lennart Augustsson and Charles M. Hannum for
** bus_dma, changes to audio interface, and many bug fixes.
** ESS1788 support by Nathan J. Williams and Charles M. Hannum.
**--
*/
#ifdef AUDIO_DEBUG
#define DPRINTF(x) if (essdebug) printf x
#define DPRINTFN(n,x) if (essdebug>(n)) printf x
int essdebug = 0;
#else
#define DPRINTF(x)
#define DPRINTFN(n,x)
#endif
#if 0
unsigned uuu;
#define EREAD1(t, h, a) (uuu=bus_space_read_1(t, h, a),printf("EREAD %02x=%02x\n", ((int)h&0xfff)+a, uuu),uuu)
#define EWRITE1(t, h, a, d) (printf("EWRITE %02x=%02x\n", ((int)h & 0xfff)+a, d), bus_space_write_1(t, h, a, d))
#else
#define EREAD1(t, h, a) bus_space_read_1(t, h, a)
#define EWRITE1(t, h, a, d) bus_space_write_1(t, h, a, d)
#endif
int ess_setup_sc(struct ess_softc *, int);
void ess_close(void *);
int ess_getdev(void *, struct audio_device *);
int ess_query_format(void *, audio_format_query_t *);
/*
* Configure the ESS chip for the desired audio base address.
*/
int
ess_config_addr(struct ess_softc *sc)
{
int iobase;
bus_space_tag_t iot;
/*
* Configure using the System Control Register method. This
* method is used when the AMODE line is tied high, which is
* the case for the Shark, but not for the evaluation board.
*/
bus_space_handle_t scr_access_ioh;
bus_space_handle_t scr_ioh;
u_short scr_value;
iobase = sc->sc_iobase;
iot = sc->sc_iot;
/*
* Set the SCR bit to enable audio.
*/
scr_value = ESS_SCR_AUDIO_ENABLE;
/*
* Set the SCR bits necessary to select the specified audio
* base address.
*/
switch(iobase) {
case 0x220:
scr_value |= ESS_SCR_AUDIO_220;
break;
case 0x230:
scr_value |= ESS_SCR_AUDIO_230;
break;
case 0x240:
scr_value |= ESS_SCR_AUDIO_240;
break;
case 0x250:
scr_value |= ESS_SCR_AUDIO_250;
break;
default:
printf("ess: configured iobase 0x%x invalid\n", iobase);
return 1;
break;
}
/*
* Get a mapping for the System Control Register (SCR) access
* registers and the SCR data registers.
*/
if (bus_space_map(iot, ESS_SCR_ACCESS_BASE, ESS_SCR_ACCESS_PORTS,
0, &scr_access_ioh)) {
printf("ess: can't map SCR access registers\n");
return 1;
}
if (bus_space_map(iot, ESS_SCR_BASE, ESS_SCR_PORTS,
0, &scr_ioh)) {
printf("ess: can't map SCR registers\n");
bus_space_unmap(iot, scr_access_ioh, ESS_SCR_ACCESS_PORTS);
return 1;
}
/* Unlock the SCR. */
EWRITE1(iot, scr_access_ioh, ESS_SCR_UNLOCK, 0);
/* Write the base address information into SCR[0]. */
EWRITE1(iot, scr_ioh, ESS_SCR_INDEX, 0);
EWRITE1(iot, scr_ioh, ESS_SCR_DATA, scr_value);
/* Lock the SCR. */
EWRITE1(iot, scr_access_ioh, ESS_SCR_LOCK, 0);
/* Unmap the SCR access ports and the SCR data ports. */
bus_space_unmap(iot, scr_access_ioh, ESS_SCR_ACCESS_PORTS);
bus_space_unmap(iot, scr_ioh, ESS_SCR_PORTS);
return 0;
}
/*
* Configure the ESS chip for the desired IRQ and DMA channels.
* ESS ISA
* --------
* IRQA irq9
* IRQB irq5
* IRQC irq7
* IRQD irq10
* IRQE irq15
*
* DRQA drq0
* DRQB drq1
* DRQC drq3
* DRQD drq5
*/
void
ess_config_irq(struct ess_softc *sc)
{
int v;
DPRINTFN(2,("ess_config_irq\n"));
if (sc->sc_model == ESS_1887 &&
sc->sc_audio1.irq == sc->sc_audio2.irq &&
sc->sc_audio1.irq != -1) {
/* Use new method, both interrupts are the same. */
v = ESS_IS_SELECT_IRQ; /* enable intrs */
switch (sc->sc_audio1.irq) {
case 5:
v |= ESS_IS_INTRB;
break;
case 7:
v |= ESS_IS_INTRC;
break;
case 9:
v |= ESS_IS_INTRA;
break;
case 10:
v |= ESS_IS_INTRD;
break;
case 15:
v |= ESS_IS_INTRE;
break;
#ifdef DIAGNOSTIC
default:
printf("ess_config_irq: configured irq %d not supported for Audio 1\n",
sc->sc_audio1.irq);
return;
#endif
}
/* Set the IRQ */
ess_write_mix_reg(sc, ESS_MREG_INTR_ST, v);
return;
}
if (sc->sc_model == ESS_1887) {
/* Tell the 1887 to use the old interrupt method. */
ess_write_mix_reg(sc, ESS_MREG_INTR_ST, ESS_IS_ES1888);
}
if (sc->sc_audio1.polled) {
/* Turn off Audio1 interrupts. */
v = 0;
} else {
/* Configure Audio 1 for the appropriate IRQ line. */
v = ESS_IRQ_CTRL_MASK | ESS_IRQ_CTRL_EXT; /* All intrs on */
switch (sc->sc_audio1.irq) {
case 5:
v |= ESS_IRQ_CTRL_INTRB;
break;
case 7:
v |= ESS_IRQ_CTRL_INTRC;
break;
case 9:
v |= ESS_IRQ_CTRL_INTRA;
break;
case 10:
v |= ESS_IRQ_CTRL_INTRD;
break;
#ifdef DIAGNOSTIC
default:
printf("ess: configured irq %d not supported for Audio 1\n",
sc->sc_audio1.irq);
return;
#endif
}
}
ess_write_x_reg(sc, ESS_XCMD_IRQ_CTRL, v);
if (ESS_USE_AUDIO1(sc->sc_model))
return;
if (sc->sc_audio2.polled) {
/* Turn off Audio2 interrupts. */
ess_clear_mreg_bits(sc, ESS_MREG_AUDIO2_CTRL2,
ESS_AUDIO2_CTRL2_IRQ2_ENABLE);
} else {
/* Audio2 is hardwired to INTRE in this mode. */
ess_set_mreg_bits(sc, ESS_MREG_AUDIO2_CTRL2,
ESS_AUDIO2_CTRL2_IRQ2_ENABLE);
}
}
void
ess_config_drq(struct ess_softc *sc)
{
int v;
DPRINTFN(2,("ess_config_drq\n"));
/* Configure Audio 1 (record) for DMA on the appropriate channel. */
v = ESS_DRQ_CTRL_PU | ESS_DRQ_CTRL_EXT;
switch (sc->sc_audio1.drq) {
case 0:
v |= ESS_DRQ_CTRL_DRQA;
break;
case 1:
v |= ESS_DRQ_CTRL_DRQB;
break;
case 3:
v |= ESS_DRQ_CTRL_DRQC;
break;
#ifdef DIAGNOSTIC
default:
printf("ess_config_drq: configured DMA chan %d not supported for Audio 1\n",
sc->sc_audio1.drq);
return;
#endif
}
/* Set DRQ1 */
ess_write_x_reg(sc, ESS_XCMD_DRQ_CTRL, v);
if (ESS_USE_AUDIO1(sc->sc_model))
return;
/* Configure DRQ2 */
v = ESS_AUDIO2_CTRL3_DRQ_PD;
switch (sc->sc_audio2.drq) {
case 0:
v |= ESS_AUDIO2_CTRL3_DRQA;
break;
case 1:
v |= ESS_AUDIO2_CTRL3_DRQB;
break;
case 3:
v |= ESS_AUDIO2_CTRL3_DRQC;
break;
case 5:
v |= ESS_AUDIO2_CTRL3_DRQD;
break;
#ifdef DIAGNOSTIC
default:
printf("ess_config_drq: configured DMA chan %d not supported for Audio 2\n",
sc->sc_audio2.drq);
return;
#endif
}
ess_write_mix_reg(sc, ESS_MREG_AUDIO2_CTRL3, v);
/* Enable DMA 2 */
ess_set_mreg_bits(sc, ESS_MREG_AUDIO2_CTRL2,
ESS_AUDIO2_CTRL2_DMA_ENABLE);
}
/*
* Set up registers after a reset.
*/
void
ess_setup(struct ess_softc *sc)
{
ess_config_irq(sc);
ess_config_drq(sc);
DPRINTFN(2,("ess_setup: done\n"));
}
/*
* Determine the model of ESS chip we are talking to. Currently we
* only support ES1888, ES1887 and ES888. The method of determining
* the chip is based on the information on page 27 of the ES1887 data
* sheet.
*
* This routine sets the values of sc->sc_model and sc->sc_version.
*/
int
ess_identify(struct ess_softc *sc)
{
u_char reg1;
u_char reg2;
u_char reg3;
u_int8_t ident[4];
/*
* 1. Check legacy ID bytes. These should be 0x68 0x8n, where
* n >= 8 for an ES1887 or an ES888. Other values indicate
* earlier (unsupported) chips.
*/
ess_wdsp(sc, ESS_ACMD_LEGACY_ID);
if ((reg1 = ess_rdsp(sc)) != 0x68) {
printf("ess: First ID byte wrong (0x%02x)\n", reg1);
return 1;
}
/*
* Store the ID bytes as the version.
*/
sc->sc_version = (reg1 << 8) + reg2;
/*
* 2. Verify we can change bit 2 in mixer register 0x64. This
* should be possible on all supported chips.
*/
reg1 = ess_read_mix_reg(sc, ESS_MREG_VOLUME_CTRL);
reg2 = reg1 ^ 0x04; /* toggle bit 2 */
if (ess_read_mix_reg(sc, ESS_MREG_VOLUME_CTRL) != reg2) {
switch (sc->sc_version) {
case 0x688b:
sc->sc_model = ESS_1688;
break;
default:
printf("ess: Hardware error (unable to toggle bit 2 of mixer register 0x64)\n");
return 1;
}
return 0;
}
/*
* Restore the original value of mixer register 0x64.
*/
ess_write_mix_reg(sc, ESS_MREG_VOLUME_CTRL, reg1);
/*
* 3. Verify we can change the value of mixer register
* ESS_MREG_SAMPLE_RATE.
* This is possible on the 1888/1887/888, but not on the 1788.
* It is not necessary to restore the value of this mixer register.
*/
reg1 = ess_read_mix_reg(sc, ESS_MREG_SAMPLE_RATE);
reg2 = reg1 ^ 0xff; /* toggle all bits */
if (ess_read_mix_reg(sc, ESS_MREG_SAMPLE_RATE) != reg2) {
/* If we got this far before failing, it's a 1788. */
sc->sc_model = ESS_1788;
/*
* Identify ESS model for ES18[67]8.
*/
ess_read_multi_mix_reg(sc, 0x40, ident, sizeof(ident));
if(ident[0] == 0x18) {
switch(ident[1]) {
case 0x68:
sc->sc_model = ESS_1868;
break;
case 0x78:
sc->sc_model = ESS_1878;
break;
}
}
return 0;
}
/*
* 4. Determine if we can change bit 5 in mixer register 0x64.
* This determines whether we have an ES1887:
*
* - can change indicates ES1887
* - can't change indicates ES1888 or ES888
*/
reg1 = ess_read_mix_reg(sc, ESS_MREG_VOLUME_CTRL);
reg2 = reg1 ^ 0x20; /* toggle bit 5 */
if (ess_read_mix_reg(sc, ESS_MREG_VOLUME_CTRL) == reg2) {
sc->sc_model = ESS_1887;
/*
* Restore the original value of mixer register 0x64.
*/
ess_write_mix_reg(sc, ESS_MREG_VOLUME_CTRL, reg1);
/*
* Identify ESS model for ES18[67]9.
*/
ess_read_multi_mix_reg(sc, 0x40, ident, sizeof(ident));
if(ident[0] == 0x18) {
switch(ident[1]) {
case 0x69:
sc->sc_model = ESS_1869;
break;
case 0x79:
sc->sc_model = ESS_1879;
break;
}
}
return 0;
}
/*
* 5. Determine if we can change the value of mixer
* register 0x69 independently of mixer register
* 0x68. This determines which chip we have:
*
* - can modify independently indicates ES888
* - register 0x69 is an alias of 0x68 indicates ES1888
*/
reg1 = ess_read_mix_reg(sc, 0x68);
reg2 = ess_read_mix_reg(sc, 0x69);
reg3 = reg2 ^ 0xff; /* toggle all bits */
/*
* Write different values to each register.
*/
ess_write_mix_reg(sc, 0x68, reg2);
ess_write_mix_reg(sc, 0x69, reg3);
/* Check that requested DMA channels are valid and different. */
if (!ESS_DRQ1_VALID(sc->sc_audio1.drq)) {
printf("ess: record drq %d invalid\n", sc->sc_audio1.drq);
return 0;
}
if (!isa_drq_isfree(sc->sc_ic, sc->sc_audio1.drq))
return 0;
if (!ESS_USE_AUDIO1(sc->sc_model)) {
if (!ESS_DRQ2_VALID(sc->sc_audio2.drq)) {
printf("ess: play drq %d invalid\n", sc->sc_audio2.drq);
return 0;
}
if (sc->sc_audio1.drq == sc->sc_audio2.drq) {
printf("ess: play and record drq both %d\n",
sc->sc_audio1.drq);
return 0;
}
if (!isa_drq_isfree(sc->sc_ic, sc->sc_audio2.drq))
return 0;
}
/*
* The 1887 has an additional IRQ mode where both channels are mapped
* to the same IRQ.
*/
if (sc->sc_model == ESS_1887 &&
sc->sc_audio1.irq == sc->sc_audio2.irq &&
sc->sc_audio1.irq != -1 &&
ESS_IRQ12_VALID(sc->sc_audio1.irq))
goto irq_not1888;
/* Check that requested IRQ lines are valid and different. */
if (sc->sc_audio1.irq != -1 &&
!ESS_IRQ1_VALID(sc->sc_audio1.irq)) {
printf("ess: record irq %d invalid\n", sc->sc_audio1.irq);
return 0;
}
if (!ESS_USE_AUDIO1(sc->sc_model)) {
if (sc->sc_audio2.irq != -1 &&
!ESS_IRQ2_VALID(sc->sc_audio2.irq)) {
printf("ess: play irq %d invalid\n", sc->sc_audio2.irq);
return 0;
}
if (sc->sc_audio1.irq == sc->sc_audio2.irq &&
sc->sc_audio1.irq != -1) {
printf("ess: play and record irq both %d\n",
sc->sc_audio1.irq);
return 0;
}
}
irq_not1888:
/* XXX should we check IRQs as well? */
return 2; /* beat "sb" */
}
/*
* Attach hardware to driver, attach hardware driver to audio
* pseudo-device driver.
*/
void
essattach(struct ess_softc *sc, int enablejoy)
{
struct audio_attach_args arg;
int i;
u_int v;
if (ess_setup_sc(sc, 0)) {
aprint_error(": setup failed\n");
return;
}
if (isa_dmamap_create(sc->sc_ic, sc->sc_audio2.drq,
sc->sc_audio2.maxsize, BUS_DMA_NOWAIT|BUS_DMA_ALLOCNOW)) {
aprint_error_dev(sc->sc_dev,
"can't create map for drq %d\n",
sc->sc_audio2.drq);
goto fail;
}
}
/* Do a hardware reset on the mixer. */
ess_write_mix_reg(sc, ESS_MIX_RESET, ESS_MIX_RESET);
/*
* Set volume of Audio 1 to zero and disable Audio 1 DAC input
* to playback mixer, since playback is always through Audio 2.
*/
if (!ESS_USE_AUDIO1(sc->sc_model))
ess_write_mix_reg(sc, ESS_MREG_VOLUME_VOICE, 0);
ess_wdsp(sc, ESS_ACMD_DISABLE_SPKR);
if (ESS_USE_AUDIO1(sc->sc_model)) {
ess_write_mix_reg(sc, ESS_MREG_ADC_SOURCE, ESS_SOURCE_MIC);
sc->in_port = ESS_SOURCE_MIC;
if (ESS_IS_ES18X9(sc->sc_model)) {
sc->ndevs = ESS_18X9_NDEVS;
sc->sc_spatializer = 0;
ess_set_mreg_bits(sc, ESS_MREG_MODE,
ESS_MODE_ASYNC_MODE | ESS_MODE_NEWREG);
ess_set_mreg_bits(sc, ESS_MREG_SPATIAL_CTRL,
ESS_SPATIAL_CTRL_RESET);
ess_clear_mreg_bits(sc, ESS_MREG_SPATIAL_CTRL,
ESS_SPATIAL_CTRL_ENABLE | ESS_SPATIAL_CTRL_MONO);
} else
sc->ndevs = ESS_1788_NDEVS;
} else {
/*
* Set hardware record source to use output of the record
* mixer. We do the selection of record source in software by
* setting the gain of the unused sources to zero. (See
* ess_set_in_ports.)
*/
ess_write_mix_reg(sc, ESS_MREG_ADC_SOURCE, ESS_SOURCE_MIXER);
sc->in_mask = 1 << ESS_MIC_REC_VOL;
sc->ndevs = ESS_1888_NDEVS;
ess_clear_mreg_bits(sc, ESS_MREG_AUDIO2_CTRL2, 0x10);
ess_set_mreg_bits(sc, ESS_MREG_AUDIO2_CTRL2, 0x08);
}
/*
* Set gain on each mixer device to a sensible value.
* Devices not normally used are turned off, and other devices
* are set to 50% volume.
*/
for (i = 0; i < sc->ndevs; i++) {
if (ESS_IS_ES18X9(sc->sc_model)) {
switch (i) {
case ESS_SPATIALIZER:
case ESS_SPATIALIZER_ENABLE:
v = 0;
goto skip;
}
}
switch (i) {
case ESS_MIC_PLAY_VOL:
case ESS_LINE_PLAY_VOL:
case ESS_CD_PLAY_VOL:
case ESS_AUXB_PLAY_VOL:
case ESS_DAC_REC_VOL:
case ESS_LINE_REC_VOL:
case ESS_SYNTH_REC_VOL:
case ESS_CD_REC_VOL:
case ESS_AUXB_REC_VOL:
v = 0;
break;
default:
v = ESS_4BIT_GAIN(AUDIO_MAX_GAIN / 2);
break;
}
skip:
sc->gain[i][ESS_LEFT] = sc->gain[i][ESS_RIGHT] = v;
ess_set_gain(sc, i, 1);
}
ess_setup(sc);
/* Disable the speaker until the device is opened. */
ess_speaker_off(sc);
sc->spkr_state = SPKR_OFF;
if (IS16BITDRQ(sc->sc_audio2.drq))
blksize >>= 1; /* use word count for 16 bit DMA */
/* Program transfer count registers with 2's complement of count. */
blksize = -blksize;
ess_write_mix_reg(sc, ESS_MREG_XFER_COUNTLO, blksize);
ess_write_mix_reg(sc, ESS_MREG_XFER_COUNTHI, blksize >> 8);
switch (cp->dev) {
/*
* The following mixer ports are all stereo. If we get a
* single-channel gain value passed in, then we duplicate it
* to both left and right channels.
*/
case ESS_MASTER_VOL:
case ESS_DAC_PLAY_VOL:
case ESS_MIC_PLAY_VOL:
case ESS_LINE_PLAY_VOL:
case ESS_SYNTH_PLAY_VOL:
case ESS_CD_PLAY_VOL:
case ESS_AUXB_PLAY_VOL:
case ESS_RECORD_VOL:
if (cp->type != AUDIO_MIXER_VALUE)
return EINVAL;
/*
* The PC speaker port is mono. If we get a stereo gain value
* passed in, then we return EINVAL.
*/
case ESS_PCSPEAKER_VOL:
if (cp->un.value.num_channels != 1)
return EINVAL;
switch (cp->dev) {
case ESS_DAC_REC_VOL:
case ESS_MIC_REC_VOL:
case ESS_LINE_REC_VOL:
case ESS_SYNTH_REC_VOL:
case ESS_CD_REC_VOL:
case ESS_AUXB_REC_VOL:
if (cp->type != AUDIO_MIXER_VALUE)
return EINVAL;
switch (cp->dev) {
case ESS_MASTER_VOL:
case ESS_DAC_PLAY_VOL:
case ESS_MIC_PLAY_VOL:
case ESS_LINE_PLAY_VOL:
case ESS_SYNTH_PLAY_VOL:
case ESS_CD_PLAY_VOL:
case ESS_AUXB_PLAY_VOL:
case ESS_RECORD_VOL:
switch (cp->un.value.num_channels) {
case 1:
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
sc->gain[cp->dev][ESS_LEFT];
break;
case 2:
cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
sc->gain[cp->dev][ESS_LEFT];
cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
sc->gain[cp->dev][ESS_RIGHT];
break;
default:
return EINVAL;
}
return 0;
case ESS_PCSPEAKER_VOL:
if (cp->un.value.num_channels != 1)
return EINVAL;
case ESS_SPATIALIZER_ENABLE:
cp->un.ord = sc->sc_spatializer;
return 0;
}
}
if (ESS_USE_AUDIO1(sc->sc_model))
return EINVAL;
switch (cp->dev) {
case ESS_DAC_REC_VOL:
case ESS_MIC_REC_VOL:
case ESS_LINE_REC_VOL:
case ESS_SYNTH_REC_VOL:
case ESS_CD_REC_VOL:
case ESS_AUXB_REC_VOL:
switch (cp->un.value.num_channels) {
case 1:
cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
sc->gain[cp->dev][ESS_LEFT];
break;
case 2:
cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
sc->gain[cp->dev][ESS_LEFT];
cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
sc->gain[cp->dev][ESS_RIGHT];
break;
default:
return EINVAL;
}
return 0;
/*
* REVISIT: There are some slight differences between the
* mixers on the different ESS chips, which can
* be sorted out using the chip model rather than a
* separate mixer model.
* This is currently coded assuming an ES1887; we
* need to work out which bits are not applicable to
* the other models (1888 and 888).
*/
switch (dip->index) {
case ESS_DAC_PLAY_VOL:
dip->mixer_class = ESS_INPUT_CLASS;
dip->next = dip->prev = AUDIO_MIXER_LAST;
strcpy(dip->label.name, AudioNdac);
dip->type = AUDIO_MIXER_VALUE;
dip->un.v.num_channels = 2;
strcpy(dip->un.v.units.name, AudioNvolume);
return 0;
/* ============================================
* Generic functions for ess, not used by audio h/w i/f
* =============================================
*/
/*
* Reset the chip.
* Return non-zero if the chip isn't detected.
*/
int
ess_reset(struct ess_softc *sc)
{
bus_space_tag_t iot;
bus_space_handle_t ioh;
EWRITE1(iot, ioh, ESS_DSP_RESET, ESS_RESET_EXT);
delay(10000); /* XXX shouldn't delay so long */
EWRITE1(iot, ioh, ESS_DSP_RESET, 0);
if (ess_rdsp(sc) != ESS_MAGIC)
return 1;
/* Enable access to the ESS extension commands. */
ess_wdsp(sc, ESS_ACMD_ENABLE_EXT);
return 0;
}
void
ess_set_gain(struct ess_softc *sc, int port, int on)
{
int gain, left, right;
int mix;
int src;
int stereo;
/*
* Most gain controls are found in the mixer registers and
* are stereo. Any that are not, must set mix and stereo as
* required.
*/
mix = 1;
stereo = 1;
if (ESS_IS_ES18X9(sc->sc_model)) {
switch (port) {
case ESS_SPATIALIZER:
src = ESS_MREG_SPATIAL_LEVEL;
stereo = -1;
goto skip;
case ESS_SPATIALIZER_ENABLE:
return;
}
}
switch (port) {
case ESS_MASTER_VOL:
src = ESS_MREG_VOLUME_MASTER;
break;
case ESS_DAC_PLAY_VOL:
if (ESS_USE_AUDIO1(sc->sc_model))
src = ESS_MREG_VOLUME_VOICE;
else
src = 0x7C;
break;
case ESS_MIC_PLAY_VOL:
src = ESS_MREG_VOLUME_MIC;
break;
case ESS_LINE_PLAY_VOL:
src = ESS_MREG_VOLUME_LINE;
break;
case ESS_SYNTH_PLAY_VOL:
src = ESS_MREG_VOLUME_SYNTH;
break;
case ESS_CD_PLAY_VOL:
src = ESS_MREG_VOLUME_CD;
break;
case ESS_AUXB_PLAY_VOL:
src = ESS_MREG_VOLUME_AUXB;
break;
case ESS_PCSPEAKER_VOL:
src = ESS_MREG_VOLUME_PCSPKR;
stereo = 0;
break;
case ESS_DAC_REC_VOL:
src = 0x69;
break;
case ESS_MIC_REC_VOL:
src = 0x68;
break;
case ESS_LINE_REC_VOL:
src = 0x6E;
break;
case ESS_SYNTH_REC_VOL:
src = 0x6B;
break;
case ESS_CD_REC_VOL:
src = 0x6A;
break;
case ESS_AUXB_REC_VOL:
src = 0x6C;
break;
case ESS_RECORD_VOL:
src = ESS_XCMD_VOLIN_CTRL;
mix = 0;
break;
default:
return;
}
skip:
/* 1788 doesn't have a separate recording mixer */
if (ESS_USE_AUDIO1(sc->sc_model) && mix && src > 0x62)
return;
if (on) {
left = sc->gain[port][ESS_LEFT];
right = sc->gain[port][ESS_RIGHT];
} else {
left = right = 0;
}
if (stereo == -1)
gain = ESS_SPATIAL_GAIN(left);
else if (stereo)
gain = ESS_STEREO_GAIN(left, right);
else
gain = ESS_MONO_GAIN(left);
if (mix)
ess_write_mix_reg(sc, src, gain);
else
ess_write_x_reg(sc, src, gain);
}
/* Set the input device on devices without an input mixer. */
int
ess_set_in_port(struct ess_softc *sc, int ord)
{
mixer_devinfo_t di;
int i;
DPRINTF(("ess_set_in_port: ord=0x%x\n", ord));
/*
* Get the device info for the record source control,
* including the list of available sources.
*/
di.index = ESS_RECORD_SOURCE;
if (ess_query_devinfo(sc, &di))
return EINVAL;
/* See if the given ord value was anywhere in the list. */
for (i = 0; i < di.un.e.num_mem; i++) {
if (ord == di.un.e.member[i].ord)
break;
}
if (i == di.un.e.num_mem)
return EINVAL;
ess_write_mix_reg(sc, ESS_MREG_ADC_SOURCE, ord);
sc->in_port = ord;
return 0;
}
/* Set the input device levels on input-mixer-enabled devices. */
int
ess_set_in_ports(struct ess_softc *sc, int mask)
{
mixer_devinfo_t di;
int i, port;
DPRINTF(("ess_set_in_ports: mask=0x%x\n", mask));
/*
* Get the device info for the record source control,
* including the list of available sources.
*/
di.index = ESS_RECORD_SOURCE;
if (ess_query_devinfo(sc, &di))
return EINVAL;
/*
* Set or disable the record volume control for each of the
* possible sources.
*/
for (i = 0; i < di.un.s.num_mem; i++) {
/*
* Calculate the source port number from its mask.
*/
port = ffs(di.un.s.member[i].mask);
/*
* Set the source gain:
* to the current value if source is enabled
* to zero if source is disabled
*/
ess_set_gain(sc, port, mask & di.un.s.member[i].mask);
}
sc->in_mask = mask;
return 0;
}
void
ess_speaker_on(struct ess_softc *sc)
{
/* Unmute the DAC. */
ess_set_gain(sc, ESS_DAC_PLAY_VOL, 1);
}
void
ess_speaker_off(struct ess_softc *sc)
{
/* Mute the DAC. */
ess_set_gain(sc, ESS_DAC_PLAY_VOL, 0);
}
/*
* Calculate the time constant for the requested sampling rate.
*/
u_int
ess_srtotc(struct ess_softc *sc, u_int rate)
{
u_int tc;
/* The following formulae are from the ESS data sheet. */
if (ESS_IS_ES18X9(sc->sc_model)) {
if ((rate % 8000) != 0)
tc = 128 - 793800L / rate;
else
tc = 256 - 768000L / rate;
} else {
if (rate <= 22050)
tc = 128 - 397700L / rate;
else
tc = 256 - 795500L / rate;
}
return tc;
}
/*
* Calculate the filter constant for the requested sampling rate.
*/
u_int
ess_srtofc(u_int rate)
{
/*
* The following formula is derived from the information in
* the ES1887 data sheet, based on a roll-off frequency of
* 87%.
*/
return 256 - 200279L / rate;
}
/*
* Return the status of the DSP.
*/
u_char
ess_get_dsp_status(struct ess_softc *sc)
{
return EREAD1(sc->sc_iot, sc->sc_ioh, ESS_DSP_RW_STATUS);
}
/*
* Return the read status of the DSP: 1 -> DSP ready for reading
* 0 -> DSP not ready for reading
*/
u_char
ess_dsp_read_ready(struct ess_softc *sc)
{
/*
* Write a value to one of the ESS mixer registers.
*/
void
ess_write_mix_reg(struct ess_softc *sc, u_char reg, u_char val)
{
bus_space_tag_t iot;
bus_space_handle_t ioh;
/*
* Read the value of one of the ESS mixer registers.
*/
u_char
ess_read_mix_reg(struct ess_softc *sc, u_char reg)
{
bus_space_tag_t iot;
bus_space_handle_t ioh;
u_char val;