18c2ecf20Sopenharmony_ci/************************************************************************
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ciThis file is part of Echo Digital Audio's generic driver library.
48c2ecf20Sopenharmony_ciCopyright Echo Digital Audio Corporation (c) 1998 - 2005
58c2ecf20Sopenharmony_ciAll rights reserved
68c2ecf20Sopenharmony_ciwww.echoaudio.com
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciThis library is free software; you can redistribute it and/or
98c2ecf20Sopenharmony_cimodify it under the terms of the GNU Lesser General Public
108c2ecf20Sopenharmony_ciLicense as published by the Free Software Foundation; either
118c2ecf20Sopenharmony_civersion 2.1 of the License, or (at your option) any later version.
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciThis library is distributed in the hope that it will be useful,
148c2ecf20Sopenharmony_cibut WITHOUT ANY WARRANTY; without even the implied warranty of
158c2ecf20Sopenharmony_ciMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
168c2ecf20Sopenharmony_ciLesser General Public License for more details.
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ciYou should have received a copy of the GNU Lesser General Public
198c2ecf20Sopenharmony_ciLicense along with this library; if not, write to the Free Software
208c2ecf20Sopenharmony_ciFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci*************************************************************************
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci Translation from C++ and adaptation for use in ALSA-Driver
258c2ecf20Sopenharmony_ci were made by Giuliano Pochini <pochini@shiny.it>
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci*************************************************************************/
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic int set_sample_rate(struct echoaudio *chip, u32 rate)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	u32 clock, control_reg, old_control_reg;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	if (wait_handshake(chip))
348c2ecf20Sopenharmony_ci		return -EIO;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	old_control_reg = le32_to_cpu(chip->comm_page->control_register);
378c2ecf20Sopenharmony_ci	control_reg = old_control_reg & ~INDIGO_EXPRESS_CLOCK_MASK;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	switch (rate) {
408c2ecf20Sopenharmony_ci	case 32000:
418c2ecf20Sopenharmony_ci		clock = INDIGO_EXPRESS_32000;
428c2ecf20Sopenharmony_ci		break;
438c2ecf20Sopenharmony_ci	case 44100:
448c2ecf20Sopenharmony_ci		clock = INDIGO_EXPRESS_44100;
458c2ecf20Sopenharmony_ci		break;
468c2ecf20Sopenharmony_ci	case 48000:
478c2ecf20Sopenharmony_ci		clock = INDIGO_EXPRESS_48000;
488c2ecf20Sopenharmony_ci		break;
498c2ecf20Sopenharmony_ci	case 64000:
508c2ecf20Sopenharmony_ci		clock = INDIGO_EXPRESS_32000|INDIGO_EXPRESS_DOUBLE_SPEED;
518c2ecf20Sopenharmony_ci		break;
528c2ecf20Sopenharmony_ci	case 88200:
538c2ecf20Sopenharmony_ci		clock = INDIGO_EXPRESS_44100|INDIGO_EXPRESS_DOUBLE_SPEED;
548c2ecf20Sopenharmony_ci		break;
558c2ecf20Sopenharmony_ci	case 96000:
568c2ecf20Sopenharmony_ci		clock = INDIGO_EXPRESS_48000|INDIGO_EXPRESS_DOUBLE_SPEED;
578c2ecf20Sopenharmony_ci		break;
588c2ecf20Sopenharmony_ci	default:
598c2ecf20Sopenharmony_ci		return -EINVAL;
608c2ecf20Sopenharmony_ci	}
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	control_reg |= clock;
638c2ecf20Sopenharmony_ci	if (control_reg != old_control_reg) {
648c2ecf20Sopenharmony_ci		dev_dbg(chip->card->dev,
658c2ecf20Sopenharmony_ci			"set_sample_rate: %d clock %d\n", rate, clock);
668c2ecf20Sopenharmony_ci		chip->comm_page->control_register = cpu_to_le32(control_reg);
678c2ecf20Sopenharmony_ci		chip->sample_rate = rate;
688c2ecf20Sopenharmony_ci		clear_handshake(chip);
698c2ecf20Sopenharmony_ci		return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
708c2ecf20Sopenharmony_ci	}
718c2ecf20Sopenharmony_ci	return 0;
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci/* This function routes the sound from a virtual channel to a real output */
778c2ecf20Sopenharmony_cistatic int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
788c2ecf20Sopenharmony_ci			   int gain)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	int index;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
838c2ecf20Sopenharmony_ci		       output >= num_busses_out(chip)))
848c2ecf20Sopenharmony_ci		return -EINVAL;
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	if (wait_handshake(chip))
878c2ecf20Sopenharmony_ci		return -EIO;
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci	chip->vmixer_gain[output][pipe] = gain;
908c2ecf20Sopenharmony_ci	index = output * num_pipes_out(chip) + pipe;
918c2ecf20Sopenharmony_ci	chip->comm_page->vmixer[index] = gain;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	dev_dbg(chip->card->dev,
948c2ecf20Sopenharmony_ci		"set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
958c2ecf20Sopenharmony_ci	return 0;
968c2ecf20Sopenharmony_ci}
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* Tell the DSP to read and update virtual mixer levels in comm page. */
1018c2ecf20Sopenharmony_cistatic int update_vmixer_level(struct echoaudio *chip)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	if (wait_handshake(chip))
1048c2ecf20Sopenharmony_ci		return -EIO;
1058c2ecf20Sopenharmony_ci	clear_handshake(chip);
1068c2ecf20Sopenharmony_ci	return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic u32 detect_input_clocks(const struct echoaudio *chip)
1128c2ecf20Sopenharmony_ci{
1138c2ecf20Sopenharmony_ci	return ECHO_CLOCK_BIT_INTERNAL;
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci/* The IndigoIO has no ASIC. Just do nothing */
1198c2ecf20Sopenharmony_cistatic int load_asic(struct echoaudio *chip)
1208c2ecf20Sopenharmony_ci{
1218c2ecf20Sopenharmony_ci	return 0;
1228c2ecf20Sopenharmony_ci}
123