Path: blob/master/sound/pci/echoaudio/echoaudio_gml.c
10818 views
/****************************************************************************12Copyright Echo Digital Audio Corporation (c) 1998 - 20043All rights reserved4www.echoaudio.com56This file is part of Echo Digital Audio's generic driver library.78Echo Digital Audio's generic driver library is free software;9you can redistribute it and/or modify it under the terms of10the GNU General Public License as published by the Free Software11Foundation.1213This program is distributed in the hope that it will be useful,14but WITHOUT ANY WARRANTY; without even the implied warranty of15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16GNU General Public License for more details.1718You should have received a copy of the GNU General Public License19along with this program; if not, write to the Free Software20Foundation, Inc., 59 Temple Place - Suite 330, Boston,21MA 02111-1307, USA.2223*************************************************************************2425Translation from C++ and adaptation for use in ALSA-Driver26were made by Giuliano Pochini <[email protected]>2728****************************************************************************/293031/* These functions are common for Gina24, Layla24 and Mona cards */323334/* ASIC status check - some cards have one or two ASICs that need to be35loaded. Once that load is complete, this function is called to see if36the load was successful.37If this load fails, it does not necessarily mean that the hardware is38defective - the external box may be disconnected or turned off. */39static int check_asic_status(struct echoaudio *chip)40{41u32 asic_status;4243send_vector(chip, DSP_VC_TEST_ASIC);4445/* The DSP will return a value to indicate whether or not the46ASIC is currently loaded */47if (read_dsp(chip, &asic_status) < 0) {48DE_INIT(("check_asic_status: failed on read_dsp\n"));49chip->asic_loaded = FALSE;50return -EIO;51}5253chip->asic_loaded = (asic_status == ASIC_ALREADY_LOADED);54return chip->asic_loaded ? 0 : -EIO;55}56575859/* Most configuration of Gina24, Layla24, or Mona is accomplished by writing60the control register. write_control_reg sends the new control register61value to the DSP. */62static int write_control_reg(struct echoaudio *chip, u32 value, char force)63{64/* Handle the digital input auto-mute */65if (chip->digital_in_automute)66value |= GML_DIGITAL_IN_AUTO_MUTE;67else68value &= ~GML_DIGITAL_IN_AUTO_MUTE;6970DE_ACT(("write_control_reg: 0x%x\n", value));7172/* Write the control register */73value = cpu_to_le32(value);74if (value != chip->comm_page->control_register || force) {75if (wait_handshake(chip))76return -EIO;77chip->comm_page->control_register = value;78clear_handshake(chip);79return send_vector(chip, DSP_VC_WRITE_CONTROL_REG);80}81return 0;82}83848586/* Gina24, Layla24, and Mona support digital input auto-mute. If the digital87input auto-mute is enabled, the DSP will only enable the digital inputs if88the card is syncing to a valid clock on the ADAT or S/PDIF inputs.89If the auto-mute is disabled, the digital inputs are enabled regardless of90what the input clock is set or what is connected. */91static int set_input_auto_mute(struct echoaudio *chip, int automute)92{93DE_ACT(("set_input_auto_mute %d\n", automute));9495chip->digital_in_automute = automute;9697/* Re-set the input clock to the current value - indirectly causes98the auto-mute flag to be sent to the DSP */99return set_input_clock(chip, chip->input_clock);100}101102103104/* S/PDIF coax / S/PDIF optical / ADAT - switch */105static int set_digital_mode(struct echoaudio *chip, u8 mode)106{107u8 previous_mode;108int err, i, o;109110if (chip->bad_board)111return -EIO;112113/* All audio channels must be closed before changing the digital mode */114if (snd_BUG_ON(chip->pipe_alloc_mask))115return -EAGAIN;116117if (snd_BUG_ON(!(chip->digital_modes & (1 << mode))))118return -EINVAL;119120previous_mode = chip->digital_mode;121err = dsp_set_digital_mode(chip, mode);122123/* If we successfully changed the digital mode from or to ADAT,124then make sure all output, input and monitor levels are125updated by the DSP comm object. */126if (err >= 0 && previous_mode != mode &&127(previous_mode == DIGITAL_MODE_ADAT || mode == DIGITAL_MODE_ADAT)) {128spin_lock_irq(&chip->lock);129for (o = 0; o < num_busses_out(chip); o++)130for (i = 0; i < num_busses_in(chip); i++)131set_monitor_gain(chip, o, i,132chip->monitor_gain[o][i]);133134#ifdef ECHOCARD_HAS_INPUT_GAIN135for (i = 0; i < num_busses_in(chip); i++)136set_input_gain(chip, i, chip->input_gain[i]);137update_input_line_level(chip);138#endif139140for (o = 0; o < num_busses_out(chip); o++)141set_output_gain(chip, o, chip->output_gain[o]);142update_output_line_level(chip);143spin_unlock_irq(&chip->lock);144}145146return err;147}148149150151/* Set the S/PDIF output format */152static int set_professional_spdif(struct echoaudio *chip, char prof)153{154u32 control_reg;155int err;156157/* Clear the current S/PDIF flags */158control_reg = le32_to_cpu(chip->comm_page->control_register);159control_reg &= GML_SPDIF_FORMAT_CLEAR_MASK;160161/* Set the new S/PDIF flags depending on the mode */162control_reg |= GML_SPDIF_TWO_CHANNEL | GML_SPDIF_24_BIT |163GML_SPDIF_COPY_PERMIT;164if (prof) {165/* Professional mode */166control_reg |= GML_SPDIF_PRO_MODE;167168switch (chip->sample_rate) {169case 32000:170control_reg |= GML_SPDIF_SAMPLE_RATE0 |171GML_SPDIF_SAMPLE_RATE1;172break;173case 44100:174control_reg |= GML_SPDIF_SAMPLE_RATE0;175break;176case 48000:177control_reg |= GML_SPDIF_SAMPLE_RATE1;178break;179}180} else {181/* Consumer mode */182switch (chip->sample_rate) {183case 32000:184control_reg |= GML_SPDIF_SAMPLE_RATE0 |185GML_SPDIF_SAMPLE_RATE1;186break;187case 48000:188control_reg |= GML_SPDIF_SAMPLE_RATE1;189break;190}191}192193if ((err = write_control_reg(chip, control_reg, FALSE)))194return err;195chip->professional_spdif = prof;196DE_ACT(("set_professional_spdif to %s\n",197prof ? "Professional" : "Consumer"));198return 0;199}200201202