162306a36Sopenharmony_ci/****************************************************************************
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci   Copyright Echo Digital Audio Corporation (c) 1998 - 2004
462306a36Sopenharmony_ci   All rights reserved
562306a36Sopenharmony_ci   www.echoaudio.com
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci   This file is part of Echo Digital Audio's generic driver library.
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci   Echo Digital Audio's generic driver library is free software;
1062306a36Sopenharmony_ci   you can redistribute it and/or modify it under the terms of
1162306a36Sopenharmony_ci   the GNU General Public License as published by the Free Software
1262306a36Sopenharmony_ci   Foundation.
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ci   This program is distributed in the hope that it will be useful,
1562306a36Sopenharmony_ci   but WITHOUT ANY WARRANTY; without even the implied warranty of
1662306a36Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1762306a36Sopenharmony_ci   GNU General Public License for more details.
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci   You should have received a copy of the GNU General Public License
2062306a36Sopenharmony_ci   along with this program; if not, write to the Free Software
2162306a36Sopenharmony_ci   Foundation, Inc., 59 Temple Place - Suite 330, Boston,
2262306a36Sopenharmony_ci   MA  02111-1307, USA.
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci   *************************************************************************
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci Translation from C++ and adaptation for use in ALSA-Driver
2762306a36Sopenharmony_ci were made by Giuliano Pochini <pochini@shiny.it>
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci****************************************************************************/
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistatic int load_asic(struct echoaudio *chip);
3262306a36Sopenharmony_cistatic int dsp_set_digital_mode(struct echoaudio *chip, u8 mode);
3362306a36Sopenharmony_cistatic int set_digital_mode(struct echoaudio *chip, u8 mode);
3462306a36Sopenharmony_cistatic int check_asic_status(struct echoaudio *chip);
3562306a36Sopenharmony_cistatic int set_sample_rate(struct echoaudio *chip, u32 rate);
3662306a36Sopenharmony_cistatic int set_input_clock(struct echoaudio *chip, u16 clock);
3762306a36Sopenharmony_cistatic int set_professional_spdif(struct echoaudio *chip, char prof);
3862306a36Sopenharmony_cistatic int set_phantom_power(struct echoaudio *chip, char on);
3962306a36Sopenharmony_cistatic int write_control_reg(struct echoaudio *chip, u32 ctl, u32 frq,
4062306a36Sopenharmony_ci			     char force);
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#include <linux/interrupt.h>
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_cistatic int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
4562306a36Sopenharmony_ci{
4662306a36Sopenharmony_ci	int err;
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci	local_irq_enable();
4962306a36Sopenharmony_ci	if (snd_BUG_ON((subdevice_id & 0xfff0) != ECHO3G))
5062306a36Sopenharmony_ci		return -ENODEV;
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	err = init_dsp_comm_page(chip);
5362306a36Sopenharmony_ci	if (err) {
5462306a36Sopenharmony_ci		dev_err(chip->card->dev,
5562306a36Sopenharmony_ci			"init_hw - could not initialize DSP comm page\n");
5662306a36Sopenharmony_ci		return err;
5762306a36Sopenharmony_ci	}
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	chip->comm_page->e3g_frq_register =
6062306a36Sopenharmony_ci		cpu_to_le32((E3G_MAGIC_NUMBER / 48000) - 2);
6162306a36Sopenharmony_ci	chip->device_id = device_id;
6262306a36Sopenharmony_ci	chip->subdevice_id = subdevice_id;
6362306a36Sopenharmony_ci	chip->bad_board = true;
6462306a36Sopenharmony_ci	chip->has_midi = true;
6562306a36Sopenharmony_ci	chip->dsp_code_to_load = FW_ECHO3G_DSP;
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	/* Load the DSP code and the ASIC on the PCI card and get
6862306a36Sopenharmony_ci	what type of external box is attached */
6962306a36Sopenharmony_ci	err = load_firmware(chip);
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci	if (err < 0) {
7262306a36Sopenharmony_ci		return err;
7362306a36Sopenharmony_ci	} else if (err == E3G_GINA3G_BOX_TYPE) {
7462306a36Sopenharmony_ci		chip->input_clock_types =	ECHO_CLOCK_BIT_INTERNAL |
7562306a36Sopenharmony_ci						ECHO_CLOCK_BIT_SPDIF |
7662306a36Sopenharmony_ci						ECHO_CLOCK_BIT_ADAT;
7762306a36Sopenharmony_ci		chip->card_name = "Gina3G";
7862306a36Sopenharmony_ci		chip->px_digital_out = chip->bx_digital_out = 6;
7962306a36Sopenharmony_ci		chip->px_analog_in = chip->bx_analog_in = 14;
8062306a36Sopenharmony_ci		chip->px_digital_in = chip->bx_digital_in = 16;
8162306a36Sopenharmony_ci		chip->px_num = chip->bx_num = 24;
8262306a36Sopenharmony_ci		chip->has_phantom_power = true;
8362306a36Sopenharmony_ci		chip->hasnt_input_nominal_level = true;
8462306a36Sopenharmony_ci	} else if (err == E3G_LAYLA3G_BOX_TYPE) {
8562306a36Sopenharmony_ci		chip->input_clock_types =	ECHO_CLOCK_BIT_INTERNAL |
8662306a36Sopenharmony_ci						ECHO_CLOCK_BIT_SPDIF |
8762306a36Sopenharmony_ci						ECHO_CLOCK_BIT_ADAT |
8862306a36Sopenharmony_ci						ECHO_CLOCK_BIT_WORD;
8962306a36Sopenharmony_ci		chip->card_name = "Layla3G";
9062306a36Sopenharmony_ci		chip->px_digital_out = chip->bx_digital_out = 8;
9162306a36Sopenharmony_ci		chip->px_analog_in = chip->bx_analog_in = 16;
9262306a36Sopenharmony_ci		chip->px_digital_in = chip->bx_digital_in = 24;
9362306a36Sopenharmony_ci		chip->px_num = chip->bx_num = 32;
9462306a36Sopenharmony_ci	} else {
9562306a36Sopenharmony_ci		return -ENODEV;
9662306a36Sopenharmony_ci	}
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci	chip->digital_modes =	ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
9962306a36Sopenharmony_ci				ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
10062306a36Sopenharmony_ci				ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	return err;
10362306a36Sopenharmony_ci}
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_cistatic int set_mixer_defaults(struct echoaudio *chip)
10862306a36Sopenharmony_ci{
10962306a36Sopenharmony_ci	chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
11062306a36Sopenharmony_ci	chip->professional_spdif = false;
11162306a36Sopenharmony_ci	chip->non_audio_spdif = false;
11262306a36Sopenharmony_ci	chip->bad_board = false;
11362306a36Sopenharmony_ci	chip->phantom_power = false;
11462306a36Sopenharmony_ci	return init_line_levels(chip);
11562306a36Sopenharmony_ci}
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_cistatic int set_phantom_power(struct echoaudio *chip, char on)
12062306a36Sopenharmony_ci{
12162306a36Sopenharmony_ci	u32 control_reg = le32_to_cpu(chip->comm_page->control_register);
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci	if (on)
12462306a36Sopenharmony_ci		control_reg |= E3G_PHANTOM_POWER;
12562306a36Sopenharmony_ci	else
12662306a36Sopenharmony_ci		control_reg &= ~E3G_PHANTOM_POWER;
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	chip->phantom_power = on;
12962306a36Sopenharmony_ci	return write_control_reg(chip, control_reg,
13062306a36Sopenharmony_ci				 le32_to_cpu(chip->comm_page->e3g_frq_register),
13162306a36Sopenharmony_ci				 0);
13262306a36Sopenharmony_ci}
133