powerpc/ps3: Make ps3av_set_video_mode mode ID signed
[linux/fpc-iii.git] / sound / pci / echoaudio / mia_dsp.c
blob227386602f9b6a86064f8c92c94acbb980a953f3
1 /****************************************************************************
3 Copyright Echo Digital Audio Corporation (c) 1998 - 2004
4 All rights reserved
5 www.echoaudio.com
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
12 Foundation.
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,
22 MA 02111-1307, USA.
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,
36 int gain);
37 static int update_vmixer_level(struct echoaudio *chip);
40 static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
42 int err;
44 DE_INIT(("init_hw() - Mia\n"));
45 if (snd_BUG_ON((subdevice_id & 0xfff0) != MIA))
46 return -ENODEV;
48 if ((err = init_dsp_comm_page(chip))) {
49 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
50 return err;
53 chip->device_id = device_id;
54 chip->subdevice_id = subdevice_id;
55 chip->bad_board = TRUE;
56 chip->dsp_code_to_load = &card_fw[FW_MIA_DSP];
57 /* Since this card has no ASIC, mark it as loaded so everything
58 works OK */
59 chip->asic_loaded = TRUE;
60 if ((subdevice_id & 0x0000f) == MIA_MIDI_REV)
61 chip->has_midi = TRUE;
62 chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL |
63 ECHO_CLOCK_BIT_SPDIF;
65 if ((err = load_firmware(chip)) < 0)
66 return err;
67 chip->bad_board = FALSE;
69 if ((err = init_line_levels(chip)))
70 return err;
72 /* Default routing of the virtual channels: vchannels 0-3 go to analog
73 outputs and vchannels 4-7 go to S/PDIF outputs */
74 set_vmixer_gain(chip, 0, 0, 0);
75 set_vmixer_gain(chip, 1, 1, 0);
76 set_vmixer_gain(chip, 0, 2, 0);
77 set_vmixer_gain(chip, 1, 3, 0);
78 set_vmixer_gain(chip, 2, 4, 0);
79 set_vmixer_gain(chip, 3, 5, 0);
80 set_vmixer_gain(chip, 2, 6, 0);
81 set_vmixer_gain(chip, 3, 7, 0);
82 err = update_vmixer_level(chip);
84 DE_INIT(("init_hw done\n"));
85 return err;
90 static u32 detect_input_clocks(const struct echoaudio *chip)
92 u32 clocks_from_dsp, clock_bits;
94 /* Map the DSP clock detect bits to the generic driver clock
95 detect bits */
96 clocks_from_dsp = le32_to_cpu(chip->comm_page->status_clocks);
98 clock_bits = ECHO_CLOCK_BIT_INTERNAL;
100 if (clocks_from_dsp & GLDM_CLOCK_DETECT_BIT_SPDIF)
101 clock_bits |= ECHO_CLOCK_BIT_SPDIF;
103 return clock_bits;
108 /* The Mia has no ASIC. Just do nothing */
109 static int load_asic(struct echoaudio *chip)
111 return 0;
116 static int set_sample_rate(struct echoaudio *chip, u32 rate)
118 u32 control_reg;
120 switch (rate) {
121 case 96000:
122 control_reg = MIA_96000;
123 break;
124 case 88200:
125 control_reg = MIA_88200;
126 break;
127 case 48000:
128 control_reg = MIA_48000;
129 break;
130 case 44100:
131 control_reg = MIA_44100;
132 break;
133 case 32000:
134 control_reg = MIA_32000;
135 break;
136 default:
137 DE_ACT(("set_sample_rate: %d invalid!\n", rate));
138 return -EINVAL;
141 /* Override the clock setting if this Mia is set to S/PDIF clock */
142 if (chip->input_clock == ECHO_CLOCK_SPDIF)
143 control_reg |= MIA_SPDIF;
145 /* Set the control register if it has changed */
146 if (control_reg != le32_to_cpu(chip->comm_page->control_register)) {
147 if (wait_handshake(chip))
148 return -EIO;
150 chip->comm_page->sample_rate = cpu_to_le32(rate); /* ignored by the DSP */
151 chip->comm_page->control_register = cpu_to_le32(control_reg);
152 chip->sample_rate = rate;
154 clear_handshake(chip);
155 return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
157 return 0;
162 static int set_input_clock(struct echoaudio *chip, u16 clock)
164 DE_ACT(("set_input_clock(%d)\n", clock));
165 if (snd_BUG_ON(clock != ECHO_CLOCK_INTERNAL &&
166 clock != ECHO_CLOCK_SPDIF))
167 return -EINVAL;
169 chip->input_clock = clock;
170 return set_sample_rate(chip, chip->sample_rate);
175 /* This function routes the sound from a virtual channel to a real output */
176 static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
177 int gain)
179 int index;
181 if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
182 output >= num_busses_out(chip)))
183 return -EINVAL;
185 if (wait_handshake(chip))
186 return -EIO;
188 chip->vmixer_gain[output][pipe] = gain;
189 index = output * num_pipes_out(chip) + pipe;
190 chip->comm_page->vmixer[index] = gain;
192 DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain));
193 return 0;
198 /* Tell the DSP to read and update virtual mixer levels in comm page. */
199 static int update_vmixer_level(struct echoaudio *chip)
201 if (wait_handshake(chip))
202 return -EIO;
203 clear_handshake(chip);
204 return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
209 /* Tell the DSP to reread the flags from the comm page */
210 static int update_flags(struct echoaudio *chip)
212 if (wait_handshake(chip))
213 return -EIO;
214 clear_handshake(chip);
215 return send_vector(chip, DSP_VC_UPDATE_FLAGS);
220 static int set_professional_spdif(struct echoaudio *chip, char prof)
222 DE_ACT(("set_professional_spdif %d\n", prof));
223 if (prof)
224 chip->comm_page->flags |=
225 __constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
226 else
227 chip->comm_page->flags &=
228 ~__constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
229 chip->professional_spdif = prof;
230 return update_flags(chip);