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 set_input_clock(struct echoaudio
*chip
, u16 clock
);
33 static int set_professional_spdif(struct echoaudio
*chip
, char prof
);
34 static int update_flags(struct echoaudio
*chip
);
35 static int set_vmixer_gain(struct echoaudio
*chip
, u16 output
, u16 pipe
,
37 static int update_vmixer_level(struct echoaudio
*chip
);
40 static int init_hw(struct echoaudio
*chip
, u16 device_id
, u16 subdevice_id
)
44 if (snd_BUG_ON((subdevice_id
& 0xfff0) != MIA
))
47 err
= init_dsp_comm_page(chip
);
49 dev_err(chip
->card
->dev
,
50 "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
->dsp_code_to_load
= FW_MIA_DSP
;
58 /* Since this card has no ASIC, mark it as loaded so everything
60 chip
->asic_loaded
= true;
61 if ((subdevice_id
& 0x0000f) == MIA_MIDI_REV
)
62 chip
->has_midi
= true;
63 chip
->input_clock_types
= ECHO_CLOCK_BIT_INTERNAL
|
66 err
= load_firmware(chip
);
69 chip
->bad_board
= false;
76 static int set_mixer_defaults(struct echoaudio
*chip
)
78 return init_line_levels(chip
);
83 static u32
detect_input_clocks(const struct echoaudio
*chip
)
85 u32 clocks_from_dsp
, clock_bits
;
87 /* Map the DSP clock detect bits to the generic driver clock
89 clocks_from_dsp
= le32_to_cpu(chip
->comm_page
->status_clocks
);
91 clock_bits
= ECHO_CLOCK_BIT_INTERNAL
;
93 if (clocks_from_dsp
& GLDM_CLOCK_DETECT_BIT_SPDIF
)
94 clock_bits
|= ECHO_CLOCK_BIT_SPDIF
;
101 /* The Mia has no ASIC. Just do nothing */
102 static int load_asic(struct echoaudio
*chip
)
109 static int set_sample_rate(struct echoaudio
*chip
, u32 rate
)
115 control_reg
= MIA_96000
;
118 control_reg
= MIA_88200
;
121 control_reg
= MIA_48000
;
124 control_reg
= MIA_44100
;
127 control_reg
= MIA_32000
;
130 dev_err(chip
->card
->dev
,
131 "set_sample_rate: %d invalid!\n", rate
);
135 /* Override the clock setting if this Mia is set to S/PDIF clock */
136 if (chip
->input_clock
== ECHO_CLOCK_SPDIF
)
137 control_reg
|= MIA_SPDIF
;
139 /* Set the control register if it has changed */
140 if (control_reg
!= le32_to_cpu(chip
->comm_page
->control_register
)) {
141 if (wait_handshake(chip
))
144 chip
->comm_page
->sample_rate
= cpu_to_le32(rate
); /* ignored by the DSP */
145 chip
->comm_page
->control_register
= cpu_to_le32(control_reg
);
146 chip
->sample_rate
= rate
;
148 clear_handshake(chip
);
149 return send_vector(chip
, DSP_VC_UPDATE_CLOCKS
);
156 static int set_input_clock(struct echoaudio
*chip
, u16 clock
)
158 dev_dbg(chip
->card
->dev
, "set_input_clock(%d)\n", clock
);
159 if (snd_BUG_ON(clock
!= ECHO_CLOCK_INTERNAL
&&
160 clock
!= ECHO_CLOCK_SPDIF
))
163 chip
->input_clock
= clock
;
164 return set_sample_rate(chip
, chip
->sample_rate
);
169 /* This function routes the sound from a virtual channel to a real output */
170 static int set_vmixer_gain(struct echoaudio
*chip
, u16 output
, u16 pipe
,
175 if (snd_BUG_ON(pipe
>= num_pipes_out(chip
) ||
176 output
>= num_busses_out(chip
)))
179 if (wait_handshake(chip
))
182 chip
->vmixer_gain
[output
][pipe
] = gain
;
183 index
= output
* num_pipes_out(chip
) + pipe
;
184 chip
->comm_page
->vmixer
[index
] = gain
;
186 dev_dbg(chip
->card
->dev
,
187 "set_vmixer_gain: pipe %d, out %d = %d\n", pipe
, output
, gain
);
193 /* Tell the DSP to read and update virtual mixer levels in comm page. */
194 static int update_vmixer_level(struct echoaudio
*chip
)
196 if (wait_handshake(chip
))
198 clear_handshake(chip
);
199 return send_vector(chip
, DSP_VC_SET_VMIXER_GAIN
);
204 /* Tell the DSP to reread the flags from the comm page */
205 static int update_flags(struct echoaudio
*chip
)
207 if (wait_handshake(chip
))
209 clear_handshake(chip
);
210 return send_vector(chip
, DSP_VC_UPDATE_FLAGS
);
215 static int set_professional_spdif(struct echoaudio
*chip
, char prof
)
217 dev_dbg(chip
->card
->dev
, "set_professional_spdif %d\n", prof
);
219 chip
->comm_page
->flags
|=
220 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF
);
222 chip
->comm_page
->flags
&=
223 ~cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF
);
224 chip
->professional_spdif
= prof
;
225 return update_flags(chip
);