18c2ecf20Sopenharmony_ci/****************************************************************************
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci   Copyright Echo Digital Audio Corporation (c) 1998 - 2004
48c2ecf20Sopenharmony_ci   All rights reserved
58c2ecf20Sopenharmony_ci   www.echoaudio.com
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci   This file is part of Echo Digital Audio's generic driver library.
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci   Echo Digital Audio's generic driver library is free software;
108c2ecf20Sopenharmony_ci   you can redistribute it and/or modify it under the terms of
118c2ecf20Sopenharmony_ci   the GNU General Public License as published by the Free Software
128c2ecf20Sopenharmony_ci   Foundation.
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci   This program is distributed in the hope that it will be useful,
158c2ecf20Sopenharmony_ci   but WITHOUT ANY WARRANTY; without even the implied warranty of
168c2ecf20Sopenharmony_ci   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
178c2ecf20Sopenharmony_ci   GNU General Public License for more details.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci   You should have received a copy of the GNU General Public License
208c2ecf20Sopenharmony_ci   along with this program; if not, write to the Free Software
218c2ecf20Sopenharmony_ci   Foundation, Inc., 59 Temple Place - Suite 330, Boston,
228c2ecf20Sopenharmony_ci   MA  02111-1307, USA.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci   *************************************************************************
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci Translation from C++ and adaptation for use in ALSA-Driver
278c2ecf20Sopenharmony_ci were made by Giuliano Pochini <pochini@shiny.it>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci****************************************************************************/
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistatic int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
338c2ecf20Sopenharmony_ci			   int gain);
348c2ecf20Sopenharmony_cistatic int update_vmixer_level(struct echoaudio *chip);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	int err;
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IO))
428c2ecf20Sopenharmony_ci		return -ENODEV;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	if ((err = init_dsp_comm_page(chip))) {
458c2ecf20Sopenharmony_ci		dev_err(chip->card->dev,
468c2ecf20Sopenharmony_ci			"init_hw - could not initialize DSP comm page\n");
478c2ecf20Sopenharmony_ci		return err;
488c2ecf20Sopenharmony_ci	}
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	chip->device_id = device_id;
518c2ecf20Sopenharmony_ci	chip->subdevice_id = subdevice_id;
528c2ecf20Sopenharmony_ci	chip->bad_board = true;
538c2ecf20Sopenharmony_ci	chip->dsp_code_to_load = FW_INDIGO_IO_DSP;
548c2ecf20Sopenharmony_ci	/* Since this card has no ASIC, mark it as loaded so everything
558c2ecf20Sopenharmony_ci	   works OK */
568c2ecf20Sopenharmony_ci	chip->asic_loaded = true;
578c2ecf20Sopenharmony_ci	chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	if ((err = load_firmware(chip)) < 0)
608c2ecf20Sopenharmony_ci		return err;
618c2ecf20Sopenharmony_ci	chip->bad_board = false;
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci	return err;
648c2ecf20Sopenharmony_ci}
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistatic int set_mixer_defaults(struct echoaudio *chip)
698c2ecf20Sopenharmony_ci{
708c2ecf20Sopenharmony_ci	return init_line_levels(chip);
718c2ecf20Sopenharmony_ci}
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic u32 detect_input_clocks(const struct echoaudio *chip)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	return ECHO_CLOCK_BIT_INTERNAL;
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/* The IndigoIO has no ASIC. Just do nothing */
838c2ecf20Sopenharmony_cistatic int load_asic(struct echoaudio *chip)
848c2ecf20Sopenharmony_ci{
858c2ecf20Sopenharmony_ci	return 0;
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic int set_sample_rate(struct echoaudio *chip, u32 rate)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	if (wait_handshake(chip))
938c2ecf20Sopenharmony_ci		return -EIO;
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	chip->sample_rate = rate;
968c2ecf20Sopenharmony_ci	chip->comm_page->sample_rate = cpu_to_le32(rate);
978c2ecf20Sopenharmony_ci	clear_handshake(chip);
988c2ecf20Sopenharmony_ci	return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
998c2ecf20Sopenharmony_ci}
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/* This function routes the sound from a virtual channel to a real output */
1048c2ecf20Sopenharmony_cistatic int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
1058c2ecf20Sopenharmony_ci			   int gain)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	int index;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
1108c2ecf20Sopenharmony_ci		       output >= num_busses_out(chip)))
1118c2ecf20Sopenharmony_ci		return -EINVAL;
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci	if (wait_handshake(chip))
1148c2ecf20Sopenharmony_ci		return -EIO;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	chip->vmixer_gain[output][pipe] = gain;
1178c2ecf20Sopenharmony_ci	index = output * num_pipes_out(chip) + pipe;
1188c2ecf20Sopenharmony_ci	chip->comm_page->vmixer[index] = gain;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	dev_dbg(chip->card->dev,
1218c2ecf20Sopenharmony_ci		"set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
1228c2ecf20Sopenharmony_ci	return 0;
1238c2ecf20Sopenharmony_ci}
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/* Tell the DSP to read and update virtual mixer levels in comm page. */
1288c2ecf20Sopenharmony_cistatic int update_vmixer_level(struct echoaudio *chip)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	if (wait_handshake(chip))
1318c2ecf20Sopenharmony_ci		return -EIO;
1328c2ecf20Sopenharmony_ci	clear_handshake(chip);
1338c2ecf20Sopenharmony_ci	return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
1348c2ecf20Sopenharmony_ci}
1358c2ecf20Sopenharmony_ci
136