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 
set_sample_rate(struct echoaudio * chip,u32 rate)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) {
64b5b4a41bSSudip Mukherjee 		dev_dbg(chip->card->dev,
65b5b4a41bSSudip Mukherjee 			"set_sample_rate: %d clock %d\n", rate, clock);
66a2328d02SGiuliano Pochini 		chip->comm_page->control_register = cpu_to_le32(control_reg);
67a2328d02SGiuliano Pochini 		chip->sample_rate = rate;
68a2328d02SGiuliano Pochini 		clear_handshake(chip);
69a2328d02SGiuliano Pochini 		return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
70a2328d02SGiuliano Pochini 	}
71a2328d02SGiuliano Pochini 	return 0;
72a2328d02SGiuliano Pochini }
73a2328d02SGiuliano Pochini 
74a2328d02SGiuliano Pochini 
75a2328d02SGiuliano Pochini 
76a2328d02SGiuliano Pochini /* This function routes the sound from a virtual channel to a real output */
set_vmixer_gain(struct echoaudio * chip,u16 output,u16 pipe,int gain)77a2328d02SGiuliano Pochini static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
78a2328d02SGiuliano Pochini 			   int gain)
79a2328d02SGiuliano Pochini {
80a2328d02SGiuliano Pochini 	int index;
81a2328d02SGiuliano Pochini 
82a2328d02SGiuliano Pochini 	if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
83a2328d02SGiuliano Pochini 		       output >= num_busses_out(chip)))
84a2328d02SGiuliano Pochini 		return -EINVAL;
85a2328d02SGiuliano Pochini 
86a2328d02SGiuliano Pochini 	if (wait_handshake(chip))
87a2328d02SGiuliano Pochini 		return -EIO;
88a2328d02SGiuliano Pochini 
89a2328d02SGiuliano Pochini 	chip->vmixer_gain[output][pipe] = gain;
90a2328d02SGiuliano Pochini 	index = output * num_pipes_out(chip) + pipe;
91a2328d02SGiuliano Pochini 	chip->comm_page->vmixer[index] = gain;
92a2328d02SGiuliano Pochini 
93b5b4a41bSSudip Mukherjee 	dev_dbg(chip->card->dev,
94b5b4a41bSSudip Mukherjee 		"set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain);
95a2328d02SGiuliano Pochini 	return 0;
96a2328d02SGiuliano Pochini }
97a2328d02SGiuliano Pochini 
98a2328d02SGiuliano Pochini 
99a2328d02SGiuliano Pochini 
100a2328d02SGiuliano Pochini /* Tell the DSP to read and update virtual mixer levels in comm page. */
update_vmixer_level(struct echoaudio * chip)101a2328d02SGiuliano Pochini static int update_vmixer_level(struct echoaudio *chip)
102a2328d02SGiuliano Pochini {
103a2328d02SGiuliano Pochini 	if (wait_handshake(chip))
104a2328d02SGiuliano Pochini 		return -EIO;
105a2328d02SGiuliano Pochini 	clear_handshake(chip);
106a2328d02SGiuliano Pochini 	return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
107a2328d02SGiuliano Pochini }
108a2328d02SGiuliano Pochini 
109a2328d02SGiuliano Pochini 
110a2328d02SGiuliano Pochini 
detect_input_clocks(const struct echoaudio * chip)111a2328d02SGiuliano Pochini static u32 detect_input_clocks(const struct echoaudio *chip)
112a2328d02SGiuliano Pochini {
113a2328d02SGiuliano Pochini 	return ECHO_CLOCK_BIT_INTERNAL;
114a2328d02SGiuliano Pochini }
115a2328d02SGiuliano Pochini 
116a2328d02SGiuliano Pochini 
117a2328d02SGiuliano Pochini 
118a2328d02SGiuliano Pochini /* The IndigoIO has no ASIC. Just do nothing */
load_asic(struct echoaudio * chip)119a2328d02SGiuliano Pochini static int load_asic(struct echoaudio *chip)
120a2328d02SGiuliano Pochini {
121a2328d02SGiuliano Pochini 	return 0;
122a2328d02SGiuliano Pochini }
123