blob: a959eae95e0dca8ded186b307aefb550501a2add [file] [log] [blame]
Giuliano Pochinidd7b2542006-06-28 13:53:41 +02001/****************************************************************************
2
3 Copyright Echo Digital Audio Corporation (c) 1998 - 2004
4 All rights reserved
5 www.echoaudio.com
6
7 This file is part of Echo Digital Audio's generic driver library.
8
9 Echo Digital Audio's generic driver library is free software;
10 you can redistribute it and/or modify it under the terms of
11 the GNU General Public License as published by the Free Software
12 Foundation.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 MA 02111-1307, USA.
23
24 *************************************************************************
25
26 Translation from C++ and adaptation for use in ALSA-Driver
27 were made by Giuliano Pochini <pochini@shiny.it>
28
29****************************************************************************/
30
31
32static int set_professional_spdif(struct echoaudio *chip, char prof);
33static int update_flags(struct echoaudio *chip);
34
35
36static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
37{
38 int err;
39
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +053040 dev_dbg(chip->card->dev, "init_hw() - Gina20\n");
Takashi Iwaida3cec32008-08-08 17:12:14 +020041 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA20))
42 return -ENODEV;
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020043
44 if ((err = init_dsp_comm_page(chip))) {
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +053045 dev_err(chip->card->dev,
46 "init_hw - could not initialize DSP comm page\n");
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020047 return err;
48 }
49
50 chip->device_id = device_id;
51 chip->subdevice_id = subdevice_id;
52 chip->bad_board = TRUE;
Giuliano Pochini19b50062010-02-14 18:15:34 +010053 chip->dsp_code_to_load = FW_GINA20_DSP;
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020054 chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
55 chip->clock_state = GD_CLOCK_UNDEF;
56 /* Since this card has no ASIC, mark it as loaded so everything
57 works OK */
58 chip->asic_loaded = TRUE;
59 chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL |
60 ECHO_CLOCK_BIT_SPDIF;
61
62 if ((err = load_firmware(chip)) < 0)
63 return err;
64 chip->bad_board = FALSE;
65
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +053066 dev_dbg(chip->card->dev, "init_hw done\n");
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020067 return err;
68}
69
70
71
Giuliano Pochiniad3499f2010-02-14 18:15:59 +010072static int set_mixer_defaults(struct echoaudio *chip)
73{
74 chip->professional_spdif = FALSE;
75 return init_line_levels(chip);
76}
77
78
79
Giuliano Pochinidd7b2542006-06-28 13:53:41 +020080static u32 detect_input_clocks(const struct echoaudio *chip)
81{
82 u32 clocks_from_dsp, clock_bits;
83
84 /* Map the DSP clock detect bits to the generic driver clock
85 detect bits */
86 clocks_from_dsp = le32_to_cpu(chip->comm_page->status_clocks);
87
88 clock_bits = ECHO_CLOCK_BIT_INTERNAL;
89
90 if (clocks_from_dsp & GLDM_CLOCK_DETECT_BIT_SPDIF)
91 clock_bits |= ECHO_CLOCK_BIT_SPDIF;
92
93 return clock_bits;
94}
95
96
97
98/* The Gina20 has no ASIC. Just do nothing */
99static int load_asic(struct echoaudio *chip)
100{
101 return 0;
102}
103
104
105
106static int set_sample_rate(struct echoaudio *chip, u32 rate)
107{
108 u8 clock_state, spdif_status;
109
110 if (wait_handshake(chip))
111 return -EIO;
112
113 switch (rate) {
114 case 44100:
115 clock_state = GD_CLOCK_44;
116 spdif_status = GD_SPDIF_STATUS_44;
117 break;
118 case 48000:
119 clock_state = GD_CLOCK_48;
120 spdif_status = GD_SPDIF_STATUS_48;
121 break;
122 default:
123 clock_state = GD_CLOCK_NOCHANGE;
124 spdif_status = GD_SPDIF_STATUS_NOCHANGE;
125 break;
126 }
127
128 if (chip->clock_state == clock_state)
129 clock_state = GD_CLOCK_NOCHANGE;
130 if (spdif_status == chip->spdif_status)
131 spdif_status = GD_SPDIF_STATUS_NOCHANGE;
132
133 chip->comm_page->sample_rate = cpu_to_le32(rate);
134 chip->comm_page->gd_clock_state = clock_state;
135 chip->comm_page->gd_spdif_status = spdif_status;
136 chip->comm_page->gd_resampler_state = 3; /* magic number - should always be 3 */
137
138 /* Save the new audio state if it changed */
139 if (clock_state != GD_CLOCK_NOCHANGE)
140 chip->clock_state = clock_state;
141 if (spdif_status != GD_SPDIF_STATUS_NOCHANGE)
142 chip->spdif_status = spdif_status;
143 chip->sample_rate = rate;
144
145 clear_handshake(chip);
146 return send_vector(chip, DSP_VC_SET_GD_AUDIO_STATE);
147}
148
149
150
151static int set_input_clock(struct echoaudio *chip, u16 clock)
152{
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +0530153 dev_dbg(chip->card->dev, "set_input_clock:\n");
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200154
155 switch (clock) {
156 case ECHO_CLOCK_INTERNAL:
157 /* Reset the audio state to unknown (just in case) */
158 chip->clock_state = GD_CLOCK_UNDEF;
159 chip->spdif_status = GD_SPDIF_STATUS_UNDEF;
160 set_sample_rate(chip, chip->sample_rate);
161 chip->input_clock = clock;
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +0530162 dev_dbg(chip->card->dev, "Set Gina clock to INTERNAL\n");
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200163 break;
164 case ECHO_CLOCK_SPDIF:
165 chip->comm_page->gd_clock_state = GD_CLOCK_SPDIFIN;
166 chip->comm_page->gd_spdif_status = GD_SPDIF_STATUS_NOCHANGE;
167 clear_handshake(chip);
168 send_vector(chip, DSP_VC_SET_GD_AUDIO_STATE);
169 chip->clock_state = GD_CLOCK_SPDIFIN;
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +0530170 dev_dbg(chip->card->dev, "Set Gina20 clock to SPDIF\n");
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200171 chip->input_clock = clock;
172 break;
173 default:
174 return -EINVAL;
175 }
176
177 return 0;
178}
179
180
181
182/* Set input bus gain (one unit is 0.5dB !) */
183static int set_input_gain(struct echoaudio *chip, u16 input, int gain)
184{
Takashi Iwaida3cec32008-08-08 17:12:14 +0200185 if (snd_BUG_ON(input >= num_busses_in(chip)))
186 return -EINVAL;
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200187
188 if (wait_handshake(chip))
189 return -EIO;
190
191 chip->input_gain[input] = gain;
192 gain += GL20_INPUT_GAIN_MAGIC_NUMBER;
193 chip->comm_page->line_in_level[input] = gain;
194 return 0;
195}
196
197
198
199/* Tell the DSP to reread the flags from the comm page */
200static int update_flags(struct echoaudio *chip)
201{
202 if (wait_handshake(chip))
203 return -EIO;
204 clear_handshake(chip);
205 return send_vector(chip, DSP_VC_UPDATE_FLAGS);
206}
207
208
209
210static int set_professional_spdif(struct echoaudio *chip, char prof)
211{
Sudip Mukherjeeb5b4a412014-11-03 16:04:13 +0530212 dev_dbg(chip->card->dev, "set_professional_spdif %d\n", prof);
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200213 if (prof)
214 chip->comm_page->flags |=
Harvey Harrisone930e992009-02-11 14:49:30 -0800215 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200216 else
217 chip->comm_page->flags &=
Harvey Harrisone930e992009-02-11 14:49:30 -0800218 ~cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
Giuliano Pochinidd7b2542006-06-28 13:53:41 +0200219 chip->professional_spdif = prof;
220 return update_flags(chip);
221}