1a2328d02SGiuliano Pochini /************************************************************************
2a2328d02SGiuliano Pochini 
3a2328d02SGiuliano Pochini This file is part of Echo Digital Audio's generic driver library.
4a2328d02SGiuliano Pochini Copyright Echo Digital Audio Corporation (c) 1998 - 2005
5a2328d02SGiuliano Pochini All rights reserved
6a2328d02SGiuliano Pochini www.echoaudio.com
7a2328d02SGiuliano Pochini 
8a2328d02SGiuliano Pochini This library is free software; you can redistribute it and/or
9a2328d02SGiuliano Pochini modify it under the terms of the GNU Lesser General Public
10a2328d02SGiuliano Pochini License as published by the Free Software Foundation; either
11a2328d02SGiuliano Pochini version 2.1 of the License, or (at your option) any later version.
12a2328d02SGiuliano Pochini 
13a2328d02SGiuliano Pochini This library is distributed in the hope that it will be useful,
14a2328d02SGiuliano Pochini but WITHOUT ANY WARRANTY; without even the implied warranty of
15a2328d02SGiuliano Pochini MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16a2328d02SGiuliano Pochini Lesser General Public License for more details.
17a2328d02SGiuliano Pochini 
18a2328d02SGiuliano Pochini You should have received a copy of the GNU Lesser General Public
19a2328d02SGiuliano Pochini License along with this library; if not, write to the Free Software
20a2328d02SGiuliano Pochini Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21a2328d02SGiuliano Pochini 
22a2328d02SGiuliano Pochini *************************************************************************
23a2328d02SGiuliano Pochini 
24a2328d02SGiuliano Pochini  Translation from C++ and adaptation for use in ALSA-Driver
25a2328d02SGiuliano Pochini  were made by Giuliano Pochini <pochini@shiny.it>
26a2328d02SGiuliano Pochini 
27a2328d02SGiuliano Pochini *************************************************************************/
28a2328d02SGiuliano Pochini 
29a2328d02SGiuliano Pochini static int set_sample_rate(struct echoaudio *chip, u32 rate)
30a2328d02SGiuliano Pochini {
31a2328d02SGiuliano Pochini 	u32 clock, control_reg, old_control_reg;
32a2328d02SGiuliano Pochini 
33a2328d02SGiuliano Pochini 	if (wait_handshake(chip))
34a2328d02SGiuliano Pochini 		return -EIO;
35a2328d02SGiuliano Pochini 
36a2328d02SGiuliano Pochini 	old_control_reg = le32_to_cpu(chip->comm_page->control_register);
37a2328d02SGiuliano Pochini 	control_reg = old_control_reg & ~INDIGO_EXPRESS_CLOCK_MASK;
38a2328d02SGiuliano Pochini 
39a2328d02SGiuliano Pochini 	switch (rate) {
40a2328d02SGiuliano Pochini 	case 32000:
41a2328d02SGiuliano Pochini 		clock = INDIGO_EXPRESS_32000;
42a2328d02SGiuliano Pochini 		break;
43a2328d02SGiuliano Pochini 	case 44100:
44a2328d02SGiuliano Pochini 		clock = INDIGO_EXPRESS_44100;
45a2328d02SGiuliano Pochini 		break;
46a2328d02SGiuliano Pochini 	case 48000:
47a2328d02SGiuliano Pochini 		clock = INDIGO_EXPRESS_48000;
48a2328d02SGiuliano Pochini 		break;
49a2328d02SGiuliano Pochini 	case 64000:
50a2328d02SGiuliano Pochini 		clock = INDIGO_EXPRESS_32000|INDIGO_EXPRESS_DOUBLE_SPEED;
51a2328d02SGiuliano Pochini 		break;
52a2328d02SGiuliano Pochini 	case 88200:
53a2328d02SGiuliano Pochini 		clock = INDIGO_EXPRESS_44100|INDIGO_EXPRESS_DOUBLE_SPEED;
54a2328d02SGiuliano Pochini 		break;
55a2328d02SGiuliano Pochini 	case 96000:
56a2328d02SGiuliano Pochini 		clock = INDIGO_EXPRESS_48000|INDIGO_EXPRESS_DOUBLE_SPEED;
57a2328d02SGiuliano Pochini 		break;
58a2328d02SGiuliano Pochini 	default:
59a2328d02SGiuliano Pochini 		return -EINVAL;
60a2328d02SGiuliano Pochini 	}
61a2328d02SGiuliano Pochini 
62a2328d02SGiuliano Pochini 	control_reg |= clock;
63a2328d02SGiuliano Pochini 	if (control_reg != old_control_reg) {
64a2328d02SGiuliano Pochini 		chip->comm_page->control_register = cpu_to_le32(control_reg);
65a2328d02SGiuliano Pochini 		chip->sample_rate = rate;
66a2328d02SGiuliano Pochini 		clear_handshake(chip);
67a2328d02SGiuliano Pochini 		return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
68a2328d02SGiuliano Pochini 	}
69a2328d02SGiuliano Pochini 	return 0;
70a2328d02SGiuliano Pochini }
71a2328d02SGiuliano Pochini 
72a2328d02SGiuliano Pochini 
73a2328d02SGiuliano Pochini 
74a2328d02SGiuliano Pochini /* This function routes the sound from a virtual channel to a real output */
75a2328d02SGiuliano Pochini static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
76a2328d02SGiuliano Pochini 			   int gain)
77a2328d02SGiuliano Pochini {
78a2328d02SGiuliano Pochini 	int index;
79a2328d02SGiuliano Pochini 
80a2328d02SGiuliano Pochini 	if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
81a2328d02SGiuliano Pochini 		       output >= num_busses_out(chip)))
82a2328d02SGiuliano Pochini 		return -EINVAL;
83a2328d02SGiuliano Pochini 
84a2328d02SGiuliano Pochini 	if (wait_handshake(chip))
85a2328d02SGiuliano Pochini 		return -EIO;
86a2328d02SGiuliano Pochini 
87a2328d02SGiuliano Pochini 	chip->vmixer_gain[output][pipe] = gain;
88a2328d02SGiuliano Pochini 	index = output * num_pipes_out(chip) + pipe;
89a2328d02SGiuliano Pochini 	chip->comm_page->vmixer[index] = gain;
90a2328d02SGiuliano Pochini 
91a2328d02SGiuliano Pochini 	DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain));
92a2328d02SGiuliano Pochini 	return 0;
93a2328d02SGiuliano Pochini }
94a2328d02SGiuliano Pochini 
95a2328d02SGiuliano Pochini 
96a2328d02SGiuliano Pochini 
97a2328d02SGiuliano Pochini /* Tell the DSP to read and update virtual mixer levels in comm page. */
98a2328d02SGiuliano Pochini static int update_vmixer_level(struct echoaudio *chip)
99a2328d02SGiuliano Pochini {
100a2328d02SGiuliano Pochini 	if (wait_handshake(chip))
101a2328d02SGiuliano Pochini 		return -EIO;
102a2328d02SGiuliano Pochini 	clear_handshake(chip);
103a2328d02SGiuliano Pochini 	return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
104a2328d02SGiuliano Pochini }
105a2328d02SGiuliano Pochini 
106a2328d02SGiuliano Pochini 
107a2328d02SGiuliano Pochini 
108a2328d02SGiuliano Pochini static u32 detect_input_clocks(const struct echoaudio *chip)
109a2328d02SGiuliano Pochini {
110a2328d02SGiuliano Pochini 	return ECHO_CLOCK_BIT_INTERNAL;
111a2328d02SGiuliano Pochini }
112a2328d02SGiuliano Pochini 
113a2328d02SGiuliano Pochini 
114a2328d02SGiuliano Pochini 
115a2328d02SGiuliano Pochini /* The IndigoIO has no ASIC. Just do nothing */
116a2328d02SGiuliano Pochini static int load_asic(struct echoaudio *chip)
117a2328d02SGiuliano Pochini {
118a2328d02SGiuliano Pochini 	return 0;
119a2328d02SGiuliano Pochini }
120