1 /****************************************************************************
3 Copyright Echo Digital Audio Corporation (c) 1998 - 2004
7 This file is part of Echo Digital Audio's generic driver library.
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
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.
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,
24 *************************************************************************
26 Translation from C++ and adaptation for use in ALSA-Driver
27 were made by Giuliano Pochini <pochini@shiny.it>
29 ****************************************************************************/
32 static int write_control_reg(struct echoaudio *chip, u32 value, char force);
33 static int set_input_clock(struct echoaudio *chip, u16 clock);
34 static int set_professional_spdif(struct echoaudio *chip, char prof);
35 static int set_digital_mode(struct echoaudio *chip, u8 mode);
36 static int load_asic_generic(struct echoaudio *chip, u32 cmd,
37 const struct firmware *asic);
38 static int check_asic_status(struct echoaudio *chip);
41 static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
45 DE_INIT(("init_hw() - Gina24\n"));
46 if (snd_BUG_ON((subdevice_id & 0xfff0) != GINA24))
49 if ((err = init_dsp_comm_page(chip))) {
50 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
54 chip->device_id = device_id;
55 chip->subdevice_id = subdevice_id;
56 chip->bad_board = TRUE;
57 chip->input_clock_types =
58 ECHO_CLOCK_BIT_INTERNAL | ECHO_CLOCK_BIT_SPDIF |
59 ECHO_CLOCK_BIT_ESYNC | ECHO_CLOCK_BIT_ESYNC96 |
61 chip->professional_spdif = FALSE;
62 chip->digital_in_automute = TRUE;
63 chip->digital_mode = DIGITAL_MODE_SPDIF_RCA;
65 /* Gina24 comes in both '301 and '361 flavors */
66 if (chip->device_id == DEVICE_ID_56361) {
67 chip->dsp_code_to_load = &card_fw[FW_GINA24_361_DSP];
69 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
70 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
71 ECHOCAPS_HAS_DIGITAL_MODE_ADAT;
73 chip->dsp_code_to_load = &card_fw[FW_GINA24_301_DSP];
75 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_RCA |
76 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_OPTICAL |
77 ECHOCAPS_HAS_DIGITAL_MODE_ADAT |
78 ECHOCAPS_HAS_DIGITAL_MODE_SPDIF_CDROM;
81 if ((err = load_firmware(chip)) < 0)
83 chip->bad_board = FALSE;
85 if ((err = init_line_levels(chip)) < 0)
87 err = set_digital_mode(chip, DIGITAL_MODE_SPDIF_RCA);
90 err = set_professional_spdif(chip, TRUE);
92 DE_INIT(("init_hw done\n"));
98 static u32 detect_input_clocks(const struct echoaudio *chip)
100 u32 clocks_from_dsp, clock_bits;
102 /* Map the DSP clock detect bits to the generic driver clock
104 clocks_from_dsp = le32_to_cpu(chip->comm_page->status_clocks);
106 clock_bits = ECHO_CLOCK_BIT_INTERNAL;
108 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_SPDIF)
109 clock_bits |= ECHO_CLOCK_BIT_SPDIF;
111 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_ADAT)
112 clock_bits |= ECHO_CLOCK_BIT_ADAT;
114 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_ESYNC)
115 clock_bits |= ECHO_CLOCK_BIT_ESYNC | ECHO_CLOCK_BIT_ESYNC96;
122 /* Gina24 has an ASIC on the PCI card which must be loaded for anything
123 interesting to happen. */
124 static int load_asic(struct echoaudio *chip)
128 const struct firmware *fw;
130 if (chip->asic_loaded)
133 /* Give the DSP a few milliseconds to settle down */
136 /* Pick the correct ASIC for '301 or '361 Gina24 */
137 if (chip->device_id == DEVICE_ID_56361)
138 fw = &card_fw[FW_GINA24_361_ASIC];
140 fw = &card_fw[FW_GINA24_301_ASIC];
142 if ((err = load_asic_generic(chip, DSP_FNC_LOAD_GINA24_ASIC, fw)) < 0)
145 chip->asic_code = fw;
147 /* Now give the new ASIC a little time to set up */
149 /* See if it worked */
150 err = check_asic_status(chip);
152 /* Set up the control register if the load succeeded -
153 48 kHz, internal clock, S/PDIF RCA mode */
155 control_reg = GML_CONVERTER_ENABLE | GML_48KHZ;
156 err = write_control_reg(chip, control_reg, TRUE);
158 DE_INIT(("load_asic() done\n"));
164 static int set_sample_rate(struct echoaudio *chip, u32 rate)
166 u32 control_reg, clock;
168 if (snd_BUG_ON(rate >= 50000 &&
169 chip->digital_mode == DIGITAL_MODE_ADAT))
172 /* Only set the clock for internal mode. */
173 if (chip->input_clock != ECHO_CLOCK_INTERNAL) {
174 DE_ACT(("set_sample_rate: Cannot set sample rate - "
175 "clock not set to CLK_CLOCKININTERNAL\n"));
176 /* Save the rate anyhow */
177 chip->comm_page->sample_rate = cpu_to_le32(rate);
178 chip->sample_rate = rate;
184 control_reg = le32_to_cpu(chip->comm_page->control_register);
185 control_reg &= GML_CLOCK_CLEAR_MASK & GML_SPDIF_RATE_CLEAR_MASK;
195 clock = GML_48KHZ | GML_SPDIF_SAMPLE_RATE1;
199 /* Professional mode ? */
200 if (control_reg & GML_SPDIF_PRO_MODE)
201 clock |= GML_SPDIF_SAMPLE_RATE0;
204 clock = GML_32KHZ | GML_SPDIF_SAMPLE_RATE0 |
205 GML_SPDIF_SAMPLE_RATE1;
220 DE_ACT(("set_sample_rate: %d invalid!\n", rate));
224 control_reg |= clock;
226 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */
227 chip->sample_rate = rate;
228 DE_ACT(("set_sample_rate: %d clock %d\n", rate, clock));
230 return write_control_reg(chip, control_reg, FALSE);
235 static int set_input_clock(struct echoaudio *chip, u16 clock)
237 u32 control_reg, clocks_from_dsp;
239 DE_ACT(("set_input_clock:\n"));
241 /* Mask off the clock select bits */
242 control_reg = le32_to_cpu(chip->comm_page->control_register) &
243 GML_CLOCK_CLEAR_MASK;
244 clocks_from_dsp = le32_to_cpu(chip->comm_page->status_clocks);
247 case ECHO_CLOCK_INTERNAL:
248 DE_ACT(("Set Gina24 clock to INTERNAL\n"));
249 chip->input_clock = ECHO_CLOCK_INTERNAL;
250 return set_sample_rate(chip, chip->sample_rate);
251 case ECHO_CLOCK_SPDIF:
252 if (chip->digital_mode == DIGITAL_MODE_ADAT)
254 DE_ACT(("Set Gina24 clock to SPDIF\n"));
255 control_reg |= GML_SPDIF_CLOCK;
256 if (clocks_from_dsp & GML_CLOCK_DETECT_BIT_SPDIF96)
257 control_reg |= GML_DOUBLE_SPEED_MODE;
259 control_reg &= ~GML_DOUBLE_SPEED_MODE;
261 case ECHO_CLOCK_ADAT:
262 if (chip->digital_mode != DIGITAL_MODE_ADAT)
264 DE_ACT(("Set Gina24 clock to ADAT\n"));
265 control_reg |= GML_ADAT_CLOCK;
266 control_reg &= ~GML_DOUBLE_SPEED_MODE;
268 case ECHO_CLOCK_ESYNC:
269 DE_ACT(("Set Gina24 clock to ESYNC\n"));
270 control_reg |= GML_ESYNC_CLOCK;
271 control_reg &= ~GML_DOUBLE_SPEED_MODE;
273 case ECHO_CLOCK_ESYNC96:
274 DE_ACT(("Set Gina24 clock to ESYNC96\n"));
275 control_reg |= GML_ESYNC_CLOCK | GML_DOUBLE_SPEED_MODE;
278 DE_ACT(("Input clock 0x%x not supported for Gina24\n", clock));
282 chip->input_clock = clock;
283 return write_control_reg(chip, control_reg, TRUE);
288 static int dsp_set_digital_mode(struct echoaudio *chip, u8 mode)
291 int err, incompatible_clock;
293 /* Set clock to "internal" if it's not compatible with the new mode */
294 incompatible_clock = FALSE;
296 case DIGITAL_MODE_SPDIF_OPTICAL:
297 case DIGITAL_MODE_SPDIF_CDROM:
298 case DIGITAL_MODE_SPDIF_RCA:
299 if (chip->input_clock == ECHO_CLOCK_ADAT)
300 incompatible_clock = TRUE;
302 case DIGITAL_MODE_ADAT:
303 if (chip->input_clock == ECHO_CLOCK_SPDIF)
304 incompatible_clock = TRUE;
307 DE_ACT(("Digital mode not supported: %d\n", mode));
311 spin_lock_irq(&chip->lock);
313 if (incompatible_clock) { /* Switch to 48KHz, internal */
314 chip->sample_rate = 48000;
315 set_input_clock(chip, ECHO_CLOCK_INTERNAL);
318 /* Clear the current digital mode */
319 control_reg = le32_to_cpu(chip->comm_page->control_register);
320 control_reg &= GML_DIGITAL_MODE_CLEAR_MASK;
322 /* Tweak the control reg */
324 case DIGITAL_MODE_SPDIF_OPTICAL:
325 control_reg |= GML_SPDIF_OPTICAL_MODE;
327 case DIGITAL_MODE_SPDIF_CDROM:
328 /* '361 Gina24 cards do not have the S/PDIF CD-ROM mode */
329 if (chip->device_id == DEVICE_ID_56301)
330 control_reg |= GML_SPDIF_CDROM_MODE;
332 case DIGITAL_MODE_SPDIF_RCA:
333 /* GML_SPDIF_OPTICAL_MODE bit cleared */
335 case DIGITAL_MODE_ADAT:
336 control_reg |= GML_ADAT_MODE;
337 control_reg &= ~GML_DOUBLE_SPEED_MODE;
341 err = write_control_reg(chip, control_reg, TRUE);
342 spin_unlock_irq(&chip->lock);
345 chip->digital_mode = mode;
347 DE_ACT(("set_digital_mode to %d\n", chip->digital_mode));
348 return incompatible_clock;