1 |
3 |
xianfeng |
/*
|
2 |
|
|
* Copyright (c) 2004 James Courtier-Dutton <James@superbug.demon.co.uk>
|
3 |
|
|
* Driver CA0106 chips. e.g. Sound Blaster Audigy LS and Live 24bit
|
4 |
|
|
* Version: 0.0.25
|
5 |
|
|
*
|
6 |
|
|
* FEATURES currently supported:
|
7 |
|
|
* Front, Rear and Center/LFE.
|
8 |
|
|
* Surround40 and Surround51.
|
9 |
|
|
* Capture from MIC an LINE IN input.
|
10 |
|
|
* SPDIF digital playback of PCM stereo and AC3/DTS works.
|
11 |
|
|
* (One can use a standard mono mini-jack to one RCA plugs cable.
|
12 |
|
|
* or one can use a standard stereo mini-jack to two RCA plugs cable.
|
13 |
|
|
* Plug one of the RCA plugs into the Coax input of the external decoder/receiver.)
|
14 |
|
|
* ( In theory one could output 3 different AC3 streams at once, to 3 different SPDIF outputs. )
|
15 |
|
|
* Notes on how to capture sound:
|
16 |
|
|
* The AC97 is used in the PLAYBACK direction.
|
17 |
|
|
* The output from the AC97 chip, instead of reaching the speakers, is fed into the Philips 1361T ADC.
|
18 |
|
|
* So, to record from the MIC, set the MIC Playback volume to max,
|
19 |
|
|
* unmute the MIC and turn up the MASTER Playback volume.
|
20 |
|
|
* So, to prevent feedback when capturing, minimise the "Capture feedback into Playback" volume.
|
21 |
|
|
*
|
22 |
|
|
* The only playback controls that currently do anything are: -
|
23 |
|
|
* Analog Front
|
24 |
|
|
* Analog Rear
|
25 |
|
|
* Analog Center/LFE
|
26 |
|
|
* SPDIF Front
|
27 |
|
|
* SPDIF Rear
|
28 |
|
|
* SPDIF Center/LFE
|
29 |
|
|
*
|
30 |
|
|
* For capture from Mic in or Line in.
|
31 |
|
|
* Digital/Analog ( switch must be in Analog mode for CAPTURE. )
|
32 |
|
|
*
|
33 |
|
|
* CAPTURE feedback into PLAYBACK
|
34 |
|
|
*
|
35 |
|
|
* Changelog:
|
36 |
|
|
* Support interrupts per period.
|
37 |
|
|
* Removed noise from Center/LFE channel when in Analog mode.
|
38 |
|
|
* Rename and remove mixer controls.
|
39 |
|
|
* 0.0.6
|
40 |
|
|
* Use separate card based DMA buffer for periods table list.
|
41 |
|
|
* 0.0.7
|
42 |
|
|
* Change remove and rename ctrls into lists.
|
43 |
|
|
* 0.0.8
|
44 |
|
|
* Try to fix capture sources.
|
45 |
|
|
* 0.0.9
|
46 |
|
|
* Fix AC3 output.
|
47 |
|
|
* Enable S32_LE format support.
|
48 |
|
|
* 0.0.10
|
49 |
|
|
* Enable playback 48000 and 96000 rates. (Rates other that these do not work, even with "plug:front".)
|
50 |
|
|
* 0.0.11
|
51 |
|
|
* Add Model name recognition.
|
52 |
|
|
* 0.0.12
|
53 |
|
|
* Correct interrupt timing. interrupt at end of period, instead of in the middle of a playback period.
|
54 |
|
|
* Remove redundent "voice" handling.
|
55 |
|
|
* 0.0.13
|
56 |
|
|
* Single trigger call for multi channels.
|
57 |
|
|
* 0.0.14
|
58 |
|
|
* Set limits based on what the sound card hardware can do.
|
59 |
|
|
* playback periods_min=2, periods_max=8
|
60 |
|
|
* capture hw constraints require period_size = n * 64 bytes.
|
61 |
|
|
* playback hw constraints require period_size = n * 64 bytes.
|
62 |
|
|
* 0.0.15
|
63 |
|
|
* Minor updates.
|
64 |
|
|
* 0.0.16
|
65 |
|
|
* Implement 192000 sample rate.
|
66 |
|
|
* 0.0.17
|
67 |
|
|
* Add support for SB0410 and SB0413.
|
68 |
|
|
* 0.0.18
|
69 |
|
|
* Modified Copyright message.
|
70 |
|
|
* 0.0.19
|
71 |
|
|
* Finally fix support for SB Live 24 bit. SB0410 and SB0413.
|
72 |
|
|
* The output codec needs resetting, otherwise all output is muted.
|
73 |
|
|
* 0.0.20
|
74 |
|
|
* Merge "pci_disable_device(pci);" fixes.
|
75 |
|
|
* 0.0.21
|
76 |
|
|
* Add 4 capture channels. (SPDIF only comes in on channel 0. )
|
77 |
|
|
* Add SPDIF capture using optional digital I/O module for SB Live 24bit. (Analog capture does not yet work.)
|
78 |
|
|
* 0.0.22
|
79 |
|
|
* Add support for MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97. From kiksen, bug #901
|
80 |
|
|
* 0.0.23
|
81 |
|
|
* Implement support for Line-in capture on SB Live 24bit.
|
82 |
|
|
* 0.0.24
|
83 |
|
|
* Add support for mute control on SB Live 24bit (cards w/ SPI DAC)
|
84 |
|
|
* 0.0.25
|
85 |
|
|
* Powerdown SPI DAC channels when not in use
|
86 |
|
|
*
|
87 |
|
|
* BUGS:
|
88 |
|
|
* Some stability problems when unloading the snd-ca0106 kernel module.
|
89 |
|
|
* --
|
90 |
|
|
*
|
91 |
|
|
* TODO:
|
92 |
|
|
* 4 Capture channels, only one implemented so far.
|
93 |
|
|
* Other capture rates apart from 48khz not implemented.
|
94 |
|
|
* MIDI
|
95 |
|
|
* --
|
96 |
|
|
* GENERAL INFO:
|
97 |
|
|
* Model: SB0310
|
98 |
|
|
* P17 Chip: CA0106-DAT
|
99 |
|
|
* AC97 Codec: STAC 9721
|
100 |
|
|
* ADC: Philips 1361T (Stereo 24bit)
|
101 |
|
|
* DAC: WM8746EDS (6-channel, 24bit, 192Khz)
|
102 |
|
|
*
|
103 |
|
|
* GENERAL INFO:
|
104 |
|
|
* Model: SB0410
|
105 |
|
|
* P17 Chip: CA0106-DAT
|
106 |
|
|
* AC97 Codec: None
|
107 |
|
|
* ADC: WM8775EDS (4 Channel)
|
108 |
|
|
* DAC: CS4382 (114 dB, 24-Bit, 192 kHz, 8-Channel D/A Converter with DSD Support)
|
109 |
|
|
* SPDIF Out control switches between Mic in and SPDIF out.
|
110 |
|
|
* No sound out or mic input working yet.
|
111 |
|
|
*
|
112 |
|
|
* GENERAL INFO:
|
113 |
|
|
* Model: SB0413
|
114 |
|
|
* P17 Chip: CA0106-DAT
|
115 |
|
|
* AC97 Codec: None.
|
116 |
|
|
* ADC: Unknown
|
117 |
|
|
* DAC: Unknown
|
118 |
|
|
* Trying to handle it like the SB0410.
|
119 |
|
|
*
|
120 |
|
|
* This code was initally based on code from ALSA's emu10k1x.c which is:
|
121 |
|
|
* Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
|
122 |
|
|
*
|
123 |
|
|
* This program is free software; you can redistribute it and/or modify
|
124 |
|
|
* it under the terms of the GNU General Public License as published by
|
125 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
126 |
|
|
* (at your option) any later version.
|
127 |
|
|
*
|
128 |
|
|
* This program is distributed in the hope that it will be useful,
|
129 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
130 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
131 |
|
|
* GNU General Public License for more details.
|
132 |
|
|
*
|
133 |
|
|
* You should have received a copy of the GNU General Public License
|
134 |
|
|
* along with this program; if not, write to the Free Software
|
135 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
136 |
|
|
*
|
137 |
|
|
*/
|
138 |
|
|
#include <sound/driver.h>
|
139 |
|
|
#include <linux/delay.h>
|
140 |
|
|
#include <linux/init.h>
|
141 |
|
|
#include <linux/interrupt.h>
|
142 |
|
|
#include <linux/pci.h>
|
143 |
|
|
#include <linux/slab.h>
|
144 |
|
|
#include <linux/moduleparam.h>
|
145 |
|
|
#include <linux/dma-mapping.h>
|
146 |
|
|
#include <sound/core.h>
|
147 |
|
|
#include <sound/initval.h>
|
148 |
|
|
#include <sound/pcm.h>
|
149 |
|
|
#include <sound/ac97_codec.h>
|
150 |
|
|
#include <sound/info.h>
|
151 |
|
|
|
152 |
|
|
MODULE_AUTHOR("James Courtier-Dutton <James@superbug.demon.co.uk>");
|
153 |
|
|
MODULE_DESCRIPTION("CA0106");
|
154 |
|
|
MODULE_LICENSE("GPL");
|
155 |
|
|
MODULE_SUPPORTED_DEVICE("{{Creative,SB CA0106 chip}}");
|
156 |
|
|
|
157 |
|
|
// module parameters (see "Module Parameters")
|
158 |
|
|
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
|
159 |
|
|
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
|
160 |
|
|
static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
|
161 |
|
|
static uint subsystem[SNDRV_CARDS]; /* Force card subsystem model */
|
162 |
|
|
|
163 |
|
|
module_param_array(index, int, NULL, 0444);
|
164 |
|
|
MODULE_PARM_DESC(index, "Index value for the CA0106 soundcard.");
|
165 |
|
|
module_param_array(id, charp, NULL, 0444);
|
166 |
|
|
MODULE_PARM_DESC(id, "ID string for the CA0106 soundcard.");
|
167 |
|
|
module_param_array(enable, bool, NULL, 0444);
|
168 |
|
|
MODULE_PARM_DESC(enable, "Enable the CA0106 soundcard.");
|
169 |
|
|
module_param_array(subsystem, uint, NULL, 0444);
|
170 |
|
|
MODULE_PARM_DESC(subsystem, "Force card subsystem model.");
|
171 |
|
|
|
172 |
|
|
#include "ca0106.h"
|
173 |
|
|
|
174 |
|
|
static struct snd_ca0106_details ca0106_chip_details[] = {
|
175 |
|
|
/* Sound Blaster X-Fi Extreme Audio. This does not have an AC97. 53SB079000000 */
|
176 |
|
|
/* It is really just a normal SB Live 24bit. */
|
177 |
|
|
/* Tested:
|
178 |
|
|
* See ALSA bug#3251
|
179 |
|
|
*/
|
180 |
|
|
{ .serial = 0x10131102,
|
181 |
|
|
.name = "X-Fi Extreme Audio [SBxxxx]",
|
182 |
|
|
.gpio_type = 1,
|
183 |
|
|
.i2c_adc = 1 } ,
|
184 |
|
|
/* Sound Blaster X-Fi Extreme Audio. This does not have an AC97. 53SB079000000 */
|
185 |
|
|
/* It is really just a normal SB Live 24bit. */
|
186 |
|
|
/*
|
187 |
|
|
* CTRL:CA0111-WTLF
|
188 |
|
|
* ADC: WM8775SEDS
|
189 |
|
|
* DAC: CS4382-KQZ
|
190 |
|
|
*/
|
191 |
|
|
/* Tested:
|
192 |
|
|
* Playback on front, rear, center/lfe speakers
|
193 |
|
|
* Capture from Mic in.
|
194 |
|
|
* Not-Tested:
|
195 |
|
|
* Capture from Line in.
|
196 |
|
|
* Playback to digital out.
|
197 |
|
|
*/
|
198 |
|
|
{ .serial = 0x10121102,
|
199 |
|
|
.name = "X-Fi Extreme Audio [SB0790]",
|
200 |
|
|
.gpio_type = 1,
|
201 |
|
|
.i2c_adc = 1 } ,
|
202 |
|
|
/* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97. */
|
203 |
|
|
/* AudigyLS[SB0310] */
|
204 |
|
|
{ .serial = 0x10021102,
|
205 |
|
|
.name = "AudigyLS [SB0310]",
|
206 |
|
|
.ac97 = 1 } ,
|
207 |
|
|
/* Unknown AudigyLS that also says SB0310 on it */
|
208 |
|
|
{ .serial = 0x10051102,
|
209 |
|
|
.name = "AudigyLS [SB0310b]",
|
210 |
|
|
.ac97 = 1 } ,
|
211 |
|
|
/* New Sound Blaster Live! 7.1 24bit. This does not have an AC97. 53SB041000001 */
|
212 |
|
|
{ .serial = 0x10061102,
|
213 |
|
|
.name = "Live! 7.1 24bit [SB0410]",
|
214 |
|
|
.gpio_type = 1,
|
215 |
|
|
.i2c_adc = 1 } ,
|
216 |
|
|
/* New Dell Sound Blaster Live! 7.1 24bit. This does not have an AC97. */
|
217 |
|
|
{ .serial = 0x10071102,
|
218 |
|
|
.name = "Live! 7.1 24bit [SB0413]",
|
219 |
|
|
.gpio_type = 1,
|
220 |
|
|
.i2c_adc = 1 } ,
|
221 |
|
|
/* New Audigy SE. Has a different DAC. */
|
222 |
|
|
/* SB0570:
|
223 |
|
|
* CTRL:CA0106-DAT
|
224 |
|
|
* ADC: WM8775EDS
|
225 |
|
|
* DAC: WM8768GEDS
|
226 |
|
|
*/
|
227 |
|
|
{ .serial = 0x100a1102,
|
228 |
|
|
.name = "Audigy SE [SB0570]",
|
229 |
|
|
.gpio_type = 1,
|
230 |
|
|
.i2c_adc = 1,
|
231 |
|
|
.spi_dac = 1 } ,
|
232 |
|
|
/* New Audigy LS. Has a different DAC. */
|
233 |
|
|
/* SB0570:
|
234 |
|
|
* CTRL:CA0106-DAT
|
235 |
|
|
* ADC: WM8775EDS
|
236 |
|
|
* DAC: WM8768GEDS
|
237 |
|
|
*/
|
238 |
|
|
{ .serial = 0x10111102,
|
239 |
|
|
.name = "Audigy SE OEM [SB0570a]",
|
240 |
|
|
.gpio_type = 1,
|
241 |
|
|
.i2c_adc = 1,
|
242 |
|
|
.spi_dac = 1 } ,
|
243 |
|
|
/* MSI K8N Diamond Motherboard with onboard SB Live 24bit without AC97 */
|
244 |
|
|
/* SB0438
|
245 |
|
|
* CTRL:CA0106-DAT
|
246 |
|
|
* ADC: WM8775SEDS
|
247 |
|
|
* DAC: CS4382-KQZ
|
248 |
|
|
*/
|
249 |
|
|
{ .serial = 0x10091462,
|
250 |
|
|
.name = "MSI K8N Diamond MB [SB0438]",
|
251 |
|
|
.gpio_type = 2,
|
252 |
|
|
.i2c_adc = 1 } ,
|
253 |
|
|
/* Shuttle XPC SD31P which has an onboard Creative Labs
|
254 |
|
|
* Sound Blaster Live! 24-bit EAX
|
255 |
|
|
* high-definition 7.1 audio processor".
|
256 |
|
|
* Added using info from andrewvegan in alsa bug #1298
|
257 |
|
|
*/
|
258 |
|
|
{ .serial = 0x30381297,
|
259 |
|
|
.name = "Shuttle XPC SD31P [SD31P]",
|
260 |
|
|
.gpio_type = 1,
|
261 |
|
|
.i2c_adc = 1 } ,
|
262 |
|
|
/* Shuttle XPC SD11G5 which has an onboard Creative Labs
|
263 |
|
|
* Sound Blaster Live! 24-bit EAX
|
264 |
|
|
* high-definition 7.1 audio processor".
|
265 |
|
|
* Fixes ALSA bug#1600
|
266 |
|
|
*/
|
267 |
|
|
{ .serial = 0x30411297,
|
268 |
|
|
.name = "Shuttle XPC SD11G5 [SD11G5]",
|
269 |
|
|
.gpio_type = 1,
|
270 |
|
|
.i2c_adc = 1 } ,
|
271 |
|
|
{ .serial = 0,
|
272 |
|
|
.name = "AudigyLS [Unknown]" }
|
273 |
|
|
};
|
274 |
|
|
|
275 |
|
|
/* hardware definition */
|
276 |
|
|
static struct snd_pcm_hardware snd_ca0106_playback_hw = {
|
277 |
|
|
.info = SNDRV_PCM_INFO_MMAP |
|
278 |
|
|
SNDRV_PCM_INFO_INTERLEAVED |
|
279 |
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
280 |
|
|
SNDRV_PCM_INFO_MMAP_VALID |
|
281 |
|
|
SNDRV_PCM_INFO_SYNC_START,
|
282 |
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
|
283 |
|
|
.rates = (SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 |
|
284 |
|
|
SNDRV_PCM_RATE_192000),
|
285 |
|
|
.rate_min = 48000,
|
286 |
|
|
.rate_max = 192000,
|
287 |
|
|
.channels_min = 2, //1,
|
288 |
|
|
.channels_max = 2, //6,
|
289 |
|
|
.buffer_bytes_max = ((65536 - 64) * 8),
|
290 |
|
|
.period_bytes_min = 64,
|
291 |
|
|
.period_bytes_max = (65536 - 64),
|
292 |
|
|
.periods_min = 2,
|
293 |
|
|
.periods_max = 8,
|
294 |
|
|
.fifo_size = 0,
|
295 |
|
|
};
|
296 |
|
|
|
297 |
|
|
static struct snd_pcm_hardware snd_ca0106_capture_hw = {
|
298 |
|
|
.info = (SNDRV_PCM_INFO_MMAP |
|
299 |
|
|
SNDRV_PCM_INFO_INTERLEAVED |
|
300 |
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
301 |
|
|
SNDRV_PCM_INFO_MMAP_VALID),
|
302 |
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE,
|
303 |
|
|
.rates = (SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
|
304 |
|
|
SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000),
|
305 |
|
|
.rate_min = 44100,
|
306 |
|
|
.rate_max = 192000,
|
307 |
|
|
.channels_min = 2,
|
308 |
|
|
.channels_max = 2,
|
309 |
|
|
.buffer_bytes_max = ((65536 - 64) * 8),
|
310 |
|
|
.period_bytes_min = 64,
|
311 |
|
|
.period_bytes_max = (65536 - 64),
|
312 |
|
|
.periods_min = 2,
|
313 |
|
|
.periods_max = 2,
|
314 |
|
|
.fifo_size = 0,
|
315 |
|
|
};
|
316 |
|
|
|
317 |
|
|
unsigned int snd_ca0106_ptr_read(struct snd_ca0106 * emu,
|
318 |
|
|
unsigned int reg,
|
319 |
|
|
unsigned int chn)
|
320 |
|
|
{
|
321 |
|
|
unsigned long flags;
|
322 |
|
|
unsigned int regptr, val;
|
323 |
|
|
|
324 |
|
|
regptr = (reg << 16) | chn;
|
325 |
|
|
|
326 |
|
|
spin_lock_irqsave(&emu->emu_lock, flags);
|
327 |
|
|
outl(regptr, emu->port + PTR);
|
328 |
|
|
val = inl(emu->port + DATA);
|
329 |
|
|
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
330 |
|
|
return val;
|
331 |
|
|
}
|
332 |
|
|
|
333 |
|
|
void snd_ca0106_ptr_write(struct snd_ca0106 *emu,
|
334 |
|
|
unsigned int reg,
|
335 |
|
|
unsigned int chn,
|
336 |
|
|
unsigned int data)
|
337 |
|
|
{
|
338 |
|
|
unsigned int regptr;
|
339 |
|
|
unsigned long flags;
|
340 |
|
|
|
341 |
|
|
regptr = (reg << 16) | chn;
|
342 |
|
|
|
343 |
|
|
spin_lock_irqsave(&emu->emu_lock, flags);
|
344 |
|
|
outl(regptr, emu->port + PTR);
|
345 |
|
|
outl(data, emu->port + DATA);
|
346 |
|
|
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
347 |
|
|
}
|
348 |
|
|
|
349 |
|
|
int snd_ca0106_spi_write(struct snd_ca0106 * emu,
|
350 |
|
|
unsigned int data)
|
351 |
|
|
{
|
352 |
|
|
unsigned int reset, set;
|
353 |
|
|
unsigned int reg, tmp;
|
354 |
|
|
int n, result;
|
355 |
|
|
reg = SPI;
|
356 |
|
|
if (data > 0xffff) /* Only 16bit values allowed */
|
357 |
|
|
return 1;
|
358 |
|
|
tmp = snd_ca0106_ptr_read(emu, reg, 0);
|
359 |
|
|
reset = (tmp & ~0x3ffff) | 0x20000; /* Set xxx20000 */
|
360 |
|
|
set = reset | 0x10000; /* Set xxx1xxxx */
|
361 |
|
|
snd_ca0106_ptr_write(emu, reg, 0, reset | data);
|
362 |
|
|
tmp = snd_ca0106_ptr_read(emu, reg, 0); /* write post */
|
363 |
|
|
snd_ca0106_ptr_write(emu, reg, 0, set | data);
|
364 |
|
|
result = 1;
|
365 |
|
|
/* Wait for status bit to return to 0 */
|
366 |
|
|
for (n = 0; n < 100; n++) {
|
367 |
|
|
udelay(10);
|
368 |
|
|
tmp = snd_ca0106_ptr_read(emu, reg, 0);
|
369 |
|
|
if (!(tmp & 0x10000)) {
|
370 |
|
|
result = 0;
|
371 |
|
|
break;
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
if (result) /* Timed out */
|
375 |
|
|
return 1;
|
376 |
|
|
snd_ca0106_ptr_write(emu, reg, 0, reset | data);
|
377 |
|
|
tmp = snd_ca0106_ptr_read(emu, reg, 0); /* Write post */
|
378 |
|
|
return 0;
|
379 |
|
|
}
|
380 |
|
|
|
381 |
|
|
/* The ADC does not support i2c read, so only write is implemented */
|
382 |
|
|
int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
|
383 |
|
|
u32 reg,
|
384 |
|
|
u32 value)
|
385 |
|
|
{
|
386 |
|
|
u32 tmp;
|
387 |
|
|
int timeout = 0;
|
388 |
|
|
int status;
|
389 |
|
|
int retry;
|
390 |
|
|
if ((reg > 0x7f) || (value > 0x1ff)) {
|
391 |
|
|
snd_printk(KERN_ERR "i2c_write: invalid values.\n");
|
392 |
|
|
return -EINVAL;
|
393 |
|
|
}
|
394 |
|
|
|
395 |
|
|
tmp = reg << 25 | value << 16;
|
396 |
|
|
// snd_printk("I2C-write:reg=0x%x, value=0x%x\n", reg, value);
|
397 |
|
|
/* Not sure what this I2C channel controls. */
|
398 |
|
|
/* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
|
399 |
|
|
|
400 |
|
|
/* This controls the I2C connected to the WM8775 ADC Codec */
|
401 |
|
|
snd_ca0106_ptr_write(emu, I2C_D1, 0, tmp);
|
402 |
|
|
|
403 |
|
|
for (retry = 0; retry < 10; retry++) {
|
404 |
|
|
/* Send the data to i2c */
|
405 |
|
|
//tmp = snd_ca0106_ptr_read(emu, I2C_A, 0);
|
406 |
|
|
//tmp = tmp & ~(I2C_A_ADC_READ|I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD_MASK);
|
407 |
|
|
tmp = 0;
|
408 |
|
|
tmp = tmp | (I2C_A_ADC_LAST|I2C_A_ADC_START|I2C_A_ADC_ADD);
|
409 |
|
|
snd_ca0106_ptr_write(emu, I2C_A, 0, tmp);
|
410 |
|
|
|
411 |
|
|
/* Wait till the transaction ends */
|
412 |
|
|
while (1) {
|
413 |
|
|
status = snd_ca0106_ptr_read(emu, I2C_A, 0);
|
414 |
|
|
//snd_printk("I2C:status=0x%x\n", status);
|
415 |
|
|
timeout++;
|
416 |
|
|
if ((status & I2C_A_ADC_START) == 0)
|
417 |
|
|
break;
|
418 |
|
|
|
419 |
|
|
if (timeout > 1000)
|
420 |
|
|
break;
|
421 |
|
|
}
|
422 |
|
|
//Read back and see if the transaction is successful
|
423 |
|
|
if ((status & I2C_A_ADC_ABORT) == 0)
|
424 |
|
|
break;
|
425 |
|
|
}
|
426 |
|
|
|
427 |
|
|
if (retry == 10) {
|
428 |
|
|
snd_printk(KERN_ERR "Writing to ADC failed!\n");
|
429 |
|
|
return -EINVAL;
|
430 |
|
|
}
|
431 |
|
|
|
432 |
|
|
return 0;
|
433 |
|
|
}
|
434 |
|
|
|
435 |
|
|
|
436 |
|
|
static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb)
|
437 |
|
|
{
|
438 |
|
|
unsigned long flags;
|
439 |
|
|
unsigned int enable;
|
440 |
|
|
|
441 |
|
|
spin_lock_irqsave(&emu->emu_lock, flags);
|
442 |
|
|
enable = inl(emu->port + INTE) | intrenb;
|
443 |
|
|
outl(enable, emu->port + INTE);
|
444 |
|
|
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb)
|
448 |
|
|
{
|
449 |
|
|
unsigned long flags;
|
450 |
|
|
unsigned int enable;
|
451 |
|
|
|
452 |
|
|
spin_lock_irqsave(&emu->emu_lock, flags);
|
453 |
|
|
enable = inl(emu->port + INTE) & ~intrenb;
|
454 |
|
|
outl(enable, emu->port + INTE);
|
455 |
|
|
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
456 |
|
|
}
|
457 |
|
|
|
458 |
|
|
|
459 |
|
|
static void snd_ca0106_pcm_free_substream(struct snd_pcm_runtime *runtime)
|
460 |
|
|
{
|
461 |
|
|
kfree(runtime->private_data);
|
462 |
|
|
}
|
463 |
|
|
|
464 |
|
|
static const int spi_dacd_reg[] = {
|
465 |
|
|
[PCM_FRONT_CHANNEL] = SPI_DACD4_REG,
|
466 |
|
|
[PCM_REAR_CHANNEL] = SPI_DACD0_REG,
|
467 |
|
|
[PCM_CENTER_LFE_CHANNEL]= SPI_DACD2_REG,
|
468 |
|
|
[PCM_UNKNOWN_CHANNEL] = SPI_DACD1_REG,
|
469 |
|
|
};
|
470 |
|
|
static const int spi_dacd_bit[] = {
|
471 |
|
|
[PCM_FRONT_CHANNEL] = SPI_DACD4_BIT,
|
472 |
|
|
[PCM_REAR_CHANNEL] = SPI_DACD0_BIT,
|
473 |
|
|
[PCM_CENTER_LFE_CHANNEL]= SPI_DACD2_BIT,
|
474 |
|
|
[PCM_UNKNOWN_CHANNEL] = SPI_DACD1_BIT,
|
475 |
|
|
};
|
476 |
|
|
|
477 |
|
|
/* open_playback callback */
|
478 |
|
|
static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substream,
|
479 |
|
|
int channel_id)
|
480 |
|
|
{
|
481 |
|
|
struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
|
482 |
|
|
struct snd_ca0106_channel *channel = &(chip->playback_channels[channel_id]);
|
483 |
|
|
struct snd_ca0106_pcm *epcm;
|
484 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
485 |
|
|
int err;
|
486 |
|
|
|
487 |
|
|
epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
|
488 |
|
|
|
489 |
|
|
if (epcm == NULL)
|
490 |
|
|
return -ENOMEM;
|
491 |
|
|
epcm->emu = chip;
|
492 |
|
|
epcm->substream = substream;
|
493 |
|
|
epcm->channel_id=channel_id;
|
494 |
|
|
|
495 |
|
|
runtime->private_data = epcm;
|
496 |
|
|
runtime->private_free = snd_ca0106_pcm_free_substream;
|
497 |
|
|
|
498 |
|
|
runtime->hw = snd_ca0106_playback_hw;
|
499 |
|
|
|
500 |
|
|
channel->emu = chip;
|
501 |
|
|
channel->number = channel_id;
|
502 |
|
|
|
503 |
|
|
channel->use = 1;
|
504 |
|
|
//printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
|
505 |
|
|
//channel->interrupt = snd_ca0106_pcm_channel_interrupt;
|
506 |
|
|
channel->epcm = epcm;
|
507 |
|
|
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
|
508 |
|
|
return err;
|
509 |
|
|
if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
|
510 |
|
|
return err;
|
511 |
|
|
snd_pcm_set_sync(substream);
|
512 |
|
|
|
513 |
|
|
if (chip->details->spi_dac && channel_id != PCM_FRONT_CHANNEL) {
|
514 |
|
|
const int reg = spi_dacd_reg[channel_id];
|
515 |
|
|
|
516 |
|
|
/* Power up dac */
|
517 |
|
|
chip->spi_dac_reg[reg] &= ~spi_dacd_bit[channel_id];
|
518 |
|
|
err = snd_ca0106_spi_write(chip, chip->spi_dac_reg[reg]);
|
519 |
|
|
if (err < 0)
|
520 |
|
|
return err;
|
521 |
|
|
}
|
522 |
|
|
return 0;
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
/* close callback */
|
526 |
|
|
static int snd_ca0106_pcm_close_playback(struct snd_pcm_substream *substream)
|
527 |
|
|
{
|
528 |
|
|
struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
|
529 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
530 |
|
|
struct snd_ca0106_pcm *epcm = runtime->private_data;
|
531 |
|
|
chip->playback_channels[epcm->channel_id].use = 0;
|
532 |
|
|
|
533 |
|
|
if (chip->details->spi_dac && epcm->channel_id != PCM_FRONT_CHANNEL) {
|
534 |
|
|
const int reg = spi_dacd_reg[epcm->channel_id];
|
535 |
|
|
|
536 |
|
|
/* Power down DAC */
|
537 |
|
|
chip->spi_dac_reg[reg] |= spi_dacd_bit[epcm->channel_id];
|
538 |
|
|
snd_ca0106_spi_write(chip, chip->spi_dac_reg[reg]);
|
539 |
|
|
}
|
540 |
|
|
/* FIXME: maybe zero others */
|
541 |
|
|
return 0;
|
542 |
|
|
}
|
543 |
|
|
|
544 |
|
|
static int snd_ca0106_pcm_open_playback_front(struct snd_pcm_substream *substream)
|
545 |
|
|
{
|
546 |
|
|
return snd_ca0106_pcm_open_playback_channel(substream, PCM_FRONT_CHANNEL);
|
547 |
|
|
}
|
548 |
|
|
|
549 |
|
|
static int snd_ca0106_pcm_open_playback_center_lfe(struct snd_pcm_substream *substream)
|
550 |
|
|
{
|
551 |
|
|
return snd_ca0106_pcm_open_playback_channel(substream, PCM_CENTER_LFE_CHANNEL);
|
552 |
|
|
}
|
553 |
|
|
|
554 |
|
|
static int snd_ca0106_pcm_open_playback_unknown(struct snd_pcm_substream *substream)
|
555 |
|
|
{
|
556 |
|
|
return snd_ca0106_pcm_open_playback_channel(substream, PCM_UNKNOWN_CHANNEL);
|
557 |
|
|
}
|
558 |
|
|
|
559 |
|
|
static int snd_ca0106_pcm_open_playback_rear(struct snd_pcm_substream *substream)
|
560 |
|
|
{
|
561 |
|
|
return snd_ca0106_pcm_open_playback_channel(substream, PCM_REAR_CHANNEL);
|
562 |
|
|
}
|
563 |
|
|
|
564 |
|
|
/* open_capture callback */
|
565 |
|
|
static int snd_ca0106_pcm_open_capture_channel(struct snd_pcm_substream *substream,
|
566 |
|
|
int channel_id)
|
567 |
|
|
{
|
568 |
|
|
struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
|
569 |
|
|
struct snd_ca0106_channel *channel = &(chip->capture_channels[channel_id]);
|
570 |
|
|
struct snd_ca0106_pcm *epcm;
|
571 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
572 |
|
|
int err;
|
573 |
|
|
|
574 |
|
|
epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
|
575 |
|
|
if (epcm == NULL) {
|
576 |
|
|
snd_printk(KERN_ERR "open_capture_channel: failed epcm alloc\n");
|
577 |
|
|
return -ENOMEM;
|
578 |
|
|
}
|
579 |
|
|
epcm->emu = chip;
|
580 |
|
|
epcm->substream = substream;
|
581 |
|
|
epcm->channel_id=channel_id;
|
582 |
|
|
|
583 |
|
|
runtime->private_data = epcm;
|
584 |
|
|
runtime->private_free = snd_ca0106_pcm_free_substream;
|
585 |
|
|
|
586 |
|
|
runtime->hw = snd_ca0106_capture_hw;
|
587 |
|
|
|
588 |
|
|
channel->emu = chip;
|
589 |
|
|
channel->number = channel_id;
|
590 |
|
|
|
591 |
|
|
channel->use = 1;
|
592 |
|
|
//printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel);
|
593 |
|
|
//channel->interrupt = snd_ca0106_pcm_channel_interrupt;
|
594 |
|
|
channel->epcm = epcm;
|
595 |
|
|
if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
|
596 |
|
|
return err;
|
597 |
|
|
//snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_capture_period_sizes);
|
598 |
|
|
if ((err = snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64)) < 0)
|
599 |
|
|
return err;
|
600 |
|
|
return 0;
|
601 |
|
|
}
|
602 |
|
|
|
603 |
|
|
/* close callback */
|
604 |
|
|
static int snd_ca0106_pcm_close_capture(struct snd_pcm_substream *substream)
|
605 |
|
|
{
|
606 |
|
|
struct snd_ca0106 *chip = snd_pcm_substream_chip(substream);
|
607 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
608 |
|
|
struct snd_ca0106_pcm *epcm = runtime->private_data;
|
609 |
|
|
chip->capture_channels[epcm->channel_id].use = 0;
|
610 |
|
|
/* FIXME: maybe zero others */
|
611 |
|
|
return 0;
|
612 |
|
|
}
|
613 |
|
|
|
614 |
|
|
static int snd_ca0106_pcm_open_0_capture(struct snd_pcm_substream *substream)
|
615 |
|
|
{
|
616 |
|
|
return snd_ca0106_pcm_open_capture_channel(substream, 0);
|
617 |
|
|
}
|
618 |
|
|
|
619 |
|
|
static int snd_ca0106_pcm_open_1_capture(struct snd_pcm_substream *substream)
|
620 |
|
|
{
|
621 |
|
|
return snd_ca0106_pcm_open_capture_channel(substream, 1);
|
622 |
|
|
}
|
623 |
|
|
|
624 |
|
|
static int snd_ca0106_pcm_open_2_capture(struct snd_pcm_substream *substream)
|
625 |
|
|
{
|
626 |
|
|
return snd_ca0106_pcm_open_capture_channel(substream, 2);
|
627 |
|
|
}
|
628 |
|
|
|
629 |
|
|
static int snd_ca0106_pcm_open_3_capture(struct snd_pcm_substream *substream)
|
630 |
|
|
{
|
631 |
|
|
return snd_ca0106_pcm_open_capture_channel(substream, 3);
|
632 |
|
|
}
|
633 |
|
|
|
634 |
|
|
/* hw_params callback */
|
635 |
|
|
static int snd_ca0106_pcm_hw_params_playback(struct snd_pcm_substream *substream,
|
636 |
|
|
struct snd_pcm_hw_params *hw_params)
|
637 |
|
|
{
|
638 |
|
|
return snd_pcm_lib_malloc_pages(substream,
|
639 |
|
|
params_buffer_bytes(hw_params));
|
640 |
|
|
}
|
641 |
|
|
|
642 |
|
|
/* hw_free callback */
|
643 |
|
|
static int snd_ca0106_pcm_hw_free_playback(struct snd_pcm_substream *substream)
|
644 |
|
|
{
|
645 |
|
|
return snd_pcm_lib_free_pages(substream);
|
646 |
|
|
}
|
647 |
|
|
|
648 |
|
|
/* hw_params callback */
|
649 |
|
|
static int snd_ca0106_pcm_hw_params_capture(struct snd_pcm_substream *substream,
|
650 |
|
|
struct snd_pcm_hw_params *hw_params)
|
651 |
|
|
{
|
652 |
|
|
return snd_pcm_lib_malloc_pages(substream,
|
653 |
|
|
params_buffer_bytes(hw_params));
|
654 |
|
|
}
|
655 |
|
|
|
656 |
|
|
/* hw_free callback */
|
657 |
|
|
static int snd_ca0106_pcm_hw_free_capture(struct snd_pcm_substream *substream)
|
658 |
|
|
{
|
659 |
|
|
return snd_pcm_lib_free_pages(substream);
|
660 |
|
|
}
|
661 |
|
|
|
662 |
|
|
/* prepare playback callback */
|
663 |
|
|
static int snd_ca0106_pcm_prepare_playback(struct snd_pcm_substream *substream)
|
664 |
|
|
{
|
665 |
|
|
struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
|
666 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
667 |
|
|
struct snd_ca0106_pcm *epcm = runtime->private_data;
|
668 |
|
|
int channel = epcm->channel_id;
|
669 |
|
|
u32 *table_base = (u32 *)(emu->buffer.area+(8*16*channel));
|
670 |
|
|
u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
|
671 |
|
|
u32 hcfg_mask = HCFG_PLAYBACK_S32_LE;
|
672 |
|
|
u32 hcfg_set = 0x00000000;
|
673 |
|
|
u32 hcfg;
|
674 |
|
|
u32 reg40_mask = 0x30000 << (channel<<1);
|
675 |
|
|
u32 reg40_set = 0;
|
676 |
|
|
u32 reg40;
|
677 |
|
|
/* FIXME: Depending on mixer selection of SPDIF out or not, select the spdif rate or the DAC rate. */
|
678 |
|
|
u32 reg71_mask = 0x03030000 ; /* Global. Set SPDIF rate. We only support 44100 to spdif, not to DAC. */
|
679 |
|
|
u32 reg71_set = 0;
|
680 |
|
|
u32 reg71;
|
681 |
|
|
int i;
|
682 |
|
|
|
683 |
|
|
//snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1));
|
684 |
|
|
//snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
|
685 |
|
|
//snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
|
686 |
|
|
/* Rate can be set per channel. */
|
687 |
|
|
/* reg40 control host to fifo */
|
688 |
|
|
/* reg71 controls DAC rate. */
|
689 |
|
|
switch (runtime->rate) {
|
690 |
|
|
case 44100:
|
691 |
|
|
reg40_set = 0x10000 << (channel<<1);
|
692 |
|
|
reg71_set = 0x01010000;
|
693 |
|
|
break;
|
694 |
|
|
case 48000:
|
695 |
|
|
reg40_set = 0;
|
696 |
|
|
reg71_set = 0;
|
697 |
|
|
break;
|
698 |
|
|
case 96000:
|
699 |
|
|
reg40_set = 0x20000 << (channel<<1);
|
700 |
|
|
reg71_set = 0x02020000;
|
701 |
|
|
break;
|
702 |
|
|
case 192000:
|
703 |
|
|
reg40_set = 0x30000 << (channel<<1);
|
704 |
|
|
reg71_set = 0x03030000;
|
705 |
|
|
break;
|
706 |
|
|
default:
|
707 |
|
|
reg40_set = 0;
|
708 |
|
|
reg71_set = 0;
|
709 |
|
|
break;
|
710 |
|
|
}
|
711 |
|
|
/* Format is a global setting */
|
712 |
|
|
/* FIXME: Only let the first channel accessed set this. */
|
713 |
|
|
switch (runtime->format) {
|
714 |
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
715 |
|
|
hcfg_set = 0;
|
716 |
|
|
break;
|
717 |
|
|
case SNDRV_PCM_FORMAT_S32_LE:
|
718 |
|
|
hcfg_set = HCFG_PLAYBACK_S32_LE;
|
719 |
|
|
break;
|
720 |
|
|
default:
|
721 |
|
|
hcfg_set = 0;
|
722 |
|
|
break;
|
723 |
|
|
}
|
724 |
|
|
hcfg = inl(emu->port + HCFG) ;
|
725 |
|
|
hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
|
726 |
|
|
outl(hcfg, emu->port + HCFG);
|
727 |
|
|
reg40 = snd_ca0106_ptr_read(emu, 0x40, 0);
|
728 |
|
|
reg40 = (reg40 & ~reg40_mask) | reg40_set;
|
729 |
|
|
snd_ca0106_ptr_write(emu, 0x40, 0, reg40);
|
730 |
|
|
reg71 = snd_ca0106_ptr_read(emu, 0x71, 0);
|
731 |
|
|
reg71 = (reg71 & ~reg71_mask) | reg71_set;
|
732 |
|
|
snd_ca0106_ptr_write(emu, 0x71, 0, reg71);
|
733 |
|
|
|
734 |
|
|
/* FIXME: Check emu->buffer.size before actually writing to it. */
|
735 |
|
|
for(i=0; i < runtime->periods; i++) {
|
736 |
|
|
table_base[i*2] = runtime->dma_addr + (i * period_size_bytes);
|
737 |
|
|
table_base[i*2+1] = period_size_bytes << 16;
|
738 |
|
|
}
|
739 |
|
|
|
740 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_LIST_ADDR, channel, emu->buffer.addr+(8*16*channel));
|
741 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_LIST_SIZE, channel, (runtime->periods - 1) << 19);
|
742 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_LIST_PTR, channel, 0);
|
743 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_DMA_ADDR, channel, runtime->dma_addr);
|
744 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, frames_to_bytes(runtime, runtime->period_size)<<16); // buffer size in bytes
|
745 |
|
|
/* FIXME test what 0 bytes does. */
|
746 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_PERIOD_SIZE, channel, 0); // buffer size in bytes
|
747 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_POINTER, channel, 0);
|
748 |
|
|
snd_ca0106_ptr_write(emu, 0x07, channel, 0x0);
|
749 |
|
|
snd_ca0106_ptr_write(emu, 0x08, channel, 0);
|
750 |
|
|
snd_ca0106_ptr_write(emu, PLAYBACK_MUTE, 0x0, 0x0); /* Unmute output */
|
751 |
|
|
#if 0
|
752 |
|
|
snd_ca0106_ptr_write(emu, SPCS0, 0,
|
753 |
|
|
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
|
754 |
|
|
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
|
755 |
|
|
SPCS_GENERATIONSTATUS | 0x00001200 |
|
756 |
|
|
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT );
|
757 |
|
|
}
|
758 |
|
|
#endif
|
759 |
|
|
|
760 |
|
|
return 0;
|
761 |
|
|
}
|
762 |
|
|
|
763 |
|
|
/* prepare capture callback */
|
764 |
|
|
static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
|
765 |
|
|
{
|
766 |
|
|
struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
|
767 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
768 |
|
|
struct snd_ca0106_pcm *epcm = runtime->private_data;
|
769 |
|
|
int channel = epcm->channel_id;
|
770 |
|
|
u32 hcfg_mask = HCFG_CAPTURE_S32_LE;
|
771 |
|
|
u32 hcfg_set = 0x00000000;
|
772 |
|
|
u32 hcfg;
|
773 |
|
|
u32 over_sampling=0x2;
|
774 |
|
|
u32 reg71_mask = 0x0000c000 ; /* Global. Set ADC rate. */
|
775 |
|
|
u32 reg71_set = 0;
|
776 |
|
|
u32 reg71;
|
777 |
|
|
|
778 |
|
|
//snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1));
|
779 |
|
|
//snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base);
|
780 |
|
|
//snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
|
781 |
|
|
/* reg71 controls ADC rate. */
|
782 |
|
|
switch (runtime->rate) {
|
783 |
|
|
case 44100:
|
784 |
|
|
reg71_set = 0x00004000;
|
785 |
|
|
break;
|
786 |
|
|
case 48000:
|
787 |
|
|
reg71_set = 0;
|
788 |
|
|
break;
|
789 |
|
|
case 96000:
|
790 |
|
|
reg71_set = 0x00008000;
|
791 |
|
|
over_sampling=0xa;
|
792 |
|
|
break;
|
793 |
|
|
case 192000:
|
794 |
|
|
reg71_set = 0x0000c000;
|
795 |
|
|
over_sampling=0xa;
|
796 |
|
|
break;
|
797 |
|
|
default:
|
798 |
|
|
reg71_set = 0;
|
799 |
|
|
break;
|
800 |
|
|
}
|
801 |
|
|
/* Format is a global setting */
|
802 |
|
|
/* FIXME: Only let the first channel accessed set this. */
|
803 |
|
|
switch (runtime->format) {
|
804 |
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
805 |
|
|
hcfg_set = 0;
|
806 |
|
|
break;
|
807 |
|
|
case SNDRV_PCM_FORMAT_S32_LE:
|
808 |
|
|
hcfg_set = HCFG_CAPTURE_S32_LE;
|
809 |
|
|
break;
|
810 |
|
|
default:
|
811 |
|
|
hcfg_set = 0;
|
812 |
|
|
break;
|
813 |
|
|
}
|
814 |
|
|
hcfg = inl(emu->port + HCFG) ;
|
815 |
|
|
hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
|
816 |
|
|
outl(hcfg, emu->port + HCFG);
|
817 |
|
|
reg71 = snd_ca0106_ptr_read(emu, 0x71, 0);
|
818 |
|
|
reg71 = (reg71 & ~reg71_mask) | reg71_set;
|
819 |
|
|
snd_ca0106_ptr_write(emu, 0x71, 0, reg71);
|
820 |
|
|
if (emu->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
|
821 |
|
|
snd_ca0106_i2c_write(emu, ADC_MASTER, over_sampling); /* Adjust the over sampler to better suit the capture rate. */
|
822 |
|
|
}
|
823 |
|
|
|
824 |
|
|
|
825 |
|
|
//printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1));
|
826 |
|
|
snd_ca0106_ptr_write(emu, 0x13, channel, 0);
|
827 |
|
|
snd_ca0106_ptr_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr);
|
828 |
|
|
snd_ca0106_ptr_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
|
829 |
|
|
snd_ca0106_ptr_write(emu, CAPTURE_POINTER, channel, 0);
|
830 |
|
|
|
831 |
|
|
return 0;
|
832 |
|
|
}
|
833 |
|
|
|
834 |
|
|
/* trigger_playback callback */
|
835 |
|
|
static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
|
836 |
|
|
int cmd)
|
837 |
|
|
{
|
838 |
|
|
struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
|
839 |
|
|
struct snd_pcm_runtime *runtime;
|
840 |
|
|
struct snd_ca0106_pcm *epcm;
|
841 |
|
|
int channel;
|
842 |
|
|
int result = 0;
|
843 |
|
|
struct snd_pcm_substream *s;
|
844 |
|
|
u32 basic = 0;
|
845 |
|
|
u32 extended = 0;
|
846 |
|
|
int running=0;
|
847 |
|
|
|
848 |
|
|
switch (cmd) {
|
849 |
|
|
case SNDRV_PCM_TRIGGER_START:
|
850 |
|
|
running=1;
|
851 |
|
|
break;
|
852 |
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
853 |
|
|
default:
|
854 |
|
|
running=0;
|
855 |
|
|
break;
|
856 |
|
|
}
|
857 |
|
|
snd_pcm_group_for_each_entry(s, substream) {
|
858 |
|
|
if (snd_pcm_substream_chip(s) != emu ||
|
859 |
|
|
s->stream != SNDRV_PCM_STREAM_PLAYBACK)
|
860 |
|
|
continue;
|
861 |
|
|
runtime = s->runtime;
|
862 |
|
|
epcm = runtime->private_data;
|
863 |
|
|
channel = epcm->channel_id;
|
864 |
|
|
//snd_printk("channel=%d\n",channel);
|
865 |
|
|
epcm->running = running;
|
866 |
|
|
basic |= (0x1<<channel);
|
867 |
|
|
extended |= (0x10<<channel);
|
868 |
|
|
snd_pcm_trigger_done(s, substream);
|
869 |
|
|
}
|
870 |
|
|
//snd_printk("basic=0x%x, extended=0x%x\n",basic, extended);
|
871 |
|
|
|
872 |
|
|
switch (cmd) {
|
873 |
|
|
case SNDRV_PCM_TRIGGER_START:
|
874 |
|
|
snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (extended));
|
875 |
|
|
snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(basic));
|
876 |
|
|
break;
|
877 |
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
878 |
|
|
snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(basic));
|
879 |
|
|
snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(extended));
|
880 |
|
|
break;
|
881 |
|
|
default:
|
882 |
|
|
result = -EINVAL;
|
883 |
|
|
break;
|
884 |
|
|
}
|
885 |
|
|
return result;
|
886 |
|
|
}
|
887 |
|
|
|
888 |
|
|
/* trigger_capture callback */
|
889 |
|
|
static int snd_ca0106_pcm_trigger_capture(struct snd_pcm_substream *substream,
|
890 |
|
|
int cmd)
|
891 |
|
|
{
|
892 |
|
|
struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
|
893 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
894 |
|
|
struct snd_ca0106_pcm *epcm = runtime->private_data;
|
895 |
|
|
int channel = epcm->channel_id;
|
896 |
|
|
int result = 0;
|
897 |
|
|
|
898 |
|
|
switch (cmd) {
|
899 |
|
|
case SNDRV_PCM_TRIGGER_START:
|
900 |
|
|
snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (0x110000<<channel));
|
901 |
|
|
snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(0x100<<channel));
|
902 |
|
|
epcm->running = 1;
|
903 |
|
|
break;
|
904 |
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
905 |
|
|
snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(0x100<<channel));
|
906 |
|
|
snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(0x110000<<channel));
|
907 |
|
|
epcm->running = 0;
|
908 |
|
|
break;
|
909 |
|
|
default:
|
910 |
|
|
result = -EINVAL;
|
911 |
|
|
break;
|
912 |
|
|
}
|
913 |
|
|
return result;
|
914 |
|
|
}
|
915 |
|
|
|
916 |
|
|
/* pointer_playback callback */
|
917 |
|
|
static snd_pcm_uframes_t
|
918 |
|
|
snd_ca0106_pcm_pointer_playback(struct snd_pcm_substream *substream)
|
919 |
|
|
{
|
920 |
|
|
struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
|
921 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
922 |
|
|
struct snd_ca0106_pcm *epcm = runtime->private_data;
|
923 |
|
|
snd_pcm_uframes_t ptr, ptr1, ptr2,ptr3,ptr4 = 0;
|
924 |
|
|
int channel = epcm->channel_id;
|
925 |
|
|
|
926 |
|
|
if (!epcm->running)
|
927 |
|
|
return 0;
|
928 |
|
|
|
929 |
|
|
ptr3 = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
|
930 |
|
|
ptr1 = snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel);
|
931 |
|
|
ptr4 = snd_ca0106_ptr_read(emu, PLAYBACK_LIST_PTR, channel);
|
932 |
|
|
if (ptr3 != ptr4) ptr1 = snd_ca0106_ptr_read(emu, PLAYBACK_POINTER, channel);
|
933 |
|
|
ptr2 = bytes_to_frames(runtime, ptr1);
|
934 |
|
|
ptr2+= (ptr4 >> 3) * runtime->period_size;
|
935 |
|
|
ptr=ptr2;
|
936 |
|
|
if (ptr >= runtime->buffer_size)
|
937 |
|
|
ptr -= runtime->buffer_size;
|
938 |
|
|
//printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate);
|
939 |
|
|
|
940 |
|
|
return ptr;
|
941 |
|
|
}
|
942 |
|
|
|
943 |
|
|
/* pointer_capture callback */
|
944 |
|
|
static snd_pcm_uframes_t
|
945 |
|
|
snd_ca0106_pcm_pointer_capture(struct snd_pcm_substream *substream)
|
946 |
|
|
{
|
947 |
|
|
struct snd_ca0106 *emu = snd_pcm_substream_chip(substream);
|
948 |
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
949 |
|
|
struct snd_ca0106_pcm *epcm = runtime->private_data;
|
950 |
|
|
snd_pcm_uframes_t ptr, ptr1, ptr2 = 0;
|
951 |
|
|
int channel = channel=epcm->channel_id;
|
952 |
|
|
|
953 |
|
|
if (!epcm->running)
|
954 |
|
|
return 0;
|
955 |
|
|
|
956 |
|
|
ptr1 = snd_ca0106_ptr_read(emu, CAPTURE_POINTER, channel);
|
957 |
|
|
ptr2 = bytes_to_frames(runtime, ptr1);
|
958 |
|
|
ptr=ptr2;
|
959 |
|
|
if (ptr >= runtime->buffer_size)
|
960 |
|
|
ptr -= runtime->buffer_size;
|
961 |
|
|
//printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate);
|
962 |
|
|
|
963 |
|
|
return ptr;
|
964 |
|
|
}
|
965 |
|
|
|
966 |
|
|
/* operators */
|
967 |
|
|
static struct snd_pcm_ops snd_ca0106_playback_front_ops = {
|
968 |
|
|
.open = snd_ca0106_pcm_open_playback_front,
|
969 |
|
|
.close = snd_ca0106_pcm_close_playback,
|
970 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
971 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_playback,
|
972 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_playback,
|
973 |
|
|
.prepare = snd_ca0106_pcm_prepare_playback,
|
974 |
|
|
.trigger = snd_ca0106_pcm_trigger_playback,
|
975 |
|
|
.pointer = snd_ca0106_pcm_pointer_playback,
|
976 |
|
|
};
|
977 |
|
|
|
978 |
|
|
static struct snd_pcm_ops snd_ca0106_capture_0_ops = {
|
979 |
|
|
.open = snd_ca0106_pcm_open_0_capture,
|
980 |
|
|
.close = snd_ca0106_pcm_close_capture,
|
981 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
982 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_capture,
|
983 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_capture,
|
984 |
|
|
.prepare = snd_ca0106_pcm_prepare_capture,
|
985 |
|
|
.trigger = snd_ca0106_pcm_trigger_capture,
|
986 |
|
|
.pointer = snd_ca0106_pcm_pointer_capture,
|
987 |
|
|
};
|
988 |
|
|
|
989 |
|
|
static struct snd_pcm_ops snd_ca0106_capture_1_ops = {
|
990 |
|
|
.open = snd_ca0106_pcm_open_1_capture,
|
991 |
|
|
.close = snd_ca0106_pcm_close_capture,
|
992 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
993 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_capture,
|
994 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_capture,
|
995 |
|
|
.prepare = snd_ca0106_pcm_prepare_capture,
|
996 |
|
|
.trigger = snd_ca0106_pcm_trigger_capture,
|
997 |
|
|
.pointer = snd_ca0106_pcm_pointer_capture,
|
998 |
|
|
};
|
999 |
|
|
|
1000 |
|
|
static struct snd_pcm_ops snd_ca0106_capture_2_ops = {
|
1001 |
|
|
.open = snd_ca0106_pcm_open_2_capture,
|
1002 |
|
|
.close = snd_ca0106_pcm_close_capture,
|
1003 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
1004 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_capture,
|
1005 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_capture,
|
1006 |
|
|
.prepare = snd_ca0106_pcm_prepare_capture,
|
1007 |
|
|
.trigger = snd_ca0106_pcm_trigger_capture,
|
1008 |
|
|
.pointer = snd_ca0106_pcm_pointer_capture,
|
1009 |
|
|
};
|
1010 |
|
|
|
1011 |
|
|
static struct snd_pcm_ops snd_ca0106_capture_3_ops = {
|
1012 |
|
|
.open = snd_ca0106_pcm_open_3_capture,
|
1013 |
|
|
.close = snd_ca0106_pcm_close_capture,
|
1014 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
1015 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_capture,
|
1016 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_capture,
|
1017 |
|
|
.prepare = snd_ca0106_pcm_prepare_capture,
|
1018 |
|
|
.trigger = snd_ca0106_pcm_trigger_capture,
|
1019 |
|
|
.pointer = snd_ca0106_pcm_pointer_capture,
|
1020 |
|
|
};
|
1021 |
|
|
|
1022 |
|
|
static struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
|
1023 |
|
|
.open = snd_ca0106_pcm_open_playback_center_lfe,
|
1024 |
|
|
.close = snd_ca0106_pcm_close_playback,
|
1025 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
1026 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_playback,
|
1027 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_playback,
|
1028 |
|
|
.prepare = snd_ca0106_pcm_prepare_playback,
|
1029 |
|
|
.trigger = snd_ca0106_pcm_trigger_playback,
|
1030 |
|
|
.pointer = snd_ca0106_pcm_pointer_playback,
|
1031 |
|
|
};
|
1032 |
|
|
|
1033 |
|
|
static struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
|
1034 |
|
|
.open = snd_ca0106_pcm_open_playback_unknown,
|
1035 |
|
|
.close = snd_ca0106_pcm_close_playback,
|
1036 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
1037 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_playback,
|
1038 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_playback,
|
1039 |
|
|
.prepare = snd_ca0106_pcm_prepare_playback,
|
1040 |
|
|
.trigger = snd_ca0106_pcm_trigger_playback,
|
1041 |
|
|
.pointer = snd_ca0106_pcm_pointer_playback,
|
1042 |
|
|
};
|
1043 |
|
|
|
1044 |
|
|
static struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
|
1045 |
|
|
.open = snd_ca0106_pcm_open_playback_rear,
|
1046 |
|
|
.close = snd_ca0106_pcm_close_playback,
|
1047 |
|
|
.ioctl = snd_pcm_lib_ioctl,
|
1048 |
|
|
.hw_params = snd_ca0106_pcm_hw_params_playback,
|
1049 |
|
|
.hw_free = snd_ca0106_pcm_hw_free_playback,
|
1050 |
|
|
.prepare = snd_ca0106_pcm_prepare_playback,
|
1051 |
|
|
.trigger = snd_ca0106_pcm_trigger_playback,
|
1052 |
|
|
.pointer = snd_ca0106_pcm_pointer_playback,
|
1053 |
|
|
};
|
1054 |
|
|
|
1055 |
|
|
|
1056 |
|
|
static unsigned short snd_ca0106_ac97_read(struct snd_ac97 *ac97,
|
1057 |
|
|
unsigned short reg)
|
1058 |
|
|
{
|
1059 |
|
|
struct snd_ca0106 *emu = ac97->private_data;
|
1060 |
|
|
unsigned long flags;
|
1061 |
|
|
unsigned short val;
|
1062 |
|
|
|
1063 |
|
|
spin_lock_irqsave(&emu->emu_lock, flags);
|
1064 |
|
|
outb(reg, emu->port + AC97ADDRESS);
|
1065 |
|
|
val = inw(emu->port + AC97DATA);
|
1066 |
|
|
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
1067 |
|
|
return val;
|
1068 |
|
|
}
|
1069 |
|
|
|
1070 |
|
|
static void snd_ca0106_ac97_write(struct snd_ac97 *ac97,
|
1071 |
|
|
unsigned short reg, unsigned short val)
|
1072 |
|
|
{
|
1073 |
|
|
struct snd_ca0106 *emu = ac97->private_data;
|
1074 |
|
|
unsigned long flags;
|
1075 |
|
|
|
1076 |
|
|
spin_lock_irqsave(&emu->emu_lock, flags);
|
1077 |
|
|
outb(reg, emu->port + AC97ADDRESS);
|
1078 |
|
|
outw(val, emu->port + AC97DATA);
|
1079 |
|
|
spin_unlock_irqrestore(&emu->emu_lock, flags);
|
1080 |
|
|
}
|
1081 |
|
|
|
1082 |
|
|
static int snd_ca0106_ac97(struct snd_ca0106 *chip)
|
1083 |
|
|
{
|
1084 |
|
|
struct snd_ac97_bus *pbus;
|
1085 |
|
|
struct snd_ac97_template ac97;
|
1086 |
|
|
int err;
|
1087 |
|
|
static struct snd_ac97_bus_ops ops = {
|
1088 |
|
|
.write = snd_ca0106_ac97_write,
|
1089 |
|
|
.read = snd_ca0106_ac97_read,
|
1090 |
|
|
};
|
1091 |
|
|
|
1092 |
|
|
if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0)
|
1093 |
|
|
return err;
|
1094 |
|
|
pbus->no_vra = 1; /* we don't need VRA */
|
1095 |
|
|
|
1096 |
|
|
memset(&ac97, 0, sizeof(ac97));
|
1097 |
|
|
ac97.private_data = chip;
|
1098 |
|
|
ac97.scaps = AC97_SCAP_NO_SPDIF;
|
1099 |
|
|
return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
|
1100 |
|
|
}
|
1101 |
|
|
|
1102 |
|
|
static int snd_ca0106_free(struct snd_ca0106 *chip)
|
1103 |
|
|
{
|
1104 |
|
|
if (chip->res_port != NULL) { /* avoid access to already used hardware */
|
1105 |
|
|
// disable interrupts
|
1106 |
|
|
snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0);
|
1107 |
|
|
outl(0, chip->port + INTE);
|
1108 |
|
|
snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0);
|
1109 |
|
|
udelay(1000);
|
1110 |
|
|
// disable audio
|
1111 |
|
|
//outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
|
1112 |
|
|
outl(0, chip->port + HCFG);
|
1113 |
|
|
/* FIXME: We need to stop and DMA transfers here.
|
1114 |
|
|
* But as I am not sure how yet, we cannot from the dma pages.
|
1115 |
|
|
* So we can fix: snd-malloc: Memory leak? pages not freed = 8
|
1116 |
|
|
*/
|
1117 |
|
|
}
|
1118 |
|
|
// release the data
|
1119 |
|
|
#if 1
|
1120 |
|
|
if (chip->buffer.area)
|
1121 |
|
|
snd_dma_free_pages(&chip->buffer);
|
1122 |
|
|
#endif
|
1123 |
|
|
|
1124 |
|
|
// release the i/o port
|
1125 |
|
|
release_and_free_resource(chip->res_port);
|
1126 |
|
|
|
1127 |
|
|
// release the irq
|
1128 |
|
|
if (chip->irq >= 0)
|
1129 |
|
|
free_irq(chip->irq, chip);
|
1130 |
|
|
pci_disable_device(chip->pci);
|
1131 |
|
|
kfree(chip);
|
1132 |
|
|
return 0;
|
1133 |
|
|
}
|
1134 |
|
|
|
1135 |
|
|
static int snd_ca0106_dev_free(struct snd_device *device)
|
1136 |
|
|
{
|
1137 |
|
|
struct snd_ca0106 *chip = device->device_data;
|
1138 |
|
|
return snd_ca0106_free(chip);
|
1139 |
|
|
}
|
1140 |
|
|
|
1141 |
|
|
static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id)
|
1142 |
|
|
{
|
1143 |
|
|
unsigned int status;
|
1144 |
|
|
|
1145 |
|
|
struct snd_ca0106 *chip = dev_id;
|
1146 |
|
|
int i;
|
1147 |
|
|
int mask;
|
1148 |
|
|
unsigned int stat76;
|
1149 |
|
|
struct snd_ca0106_channel *pchannel;
|
1150 |
|
|
|
1151 |
|
|
status = inl(chip->port + IPR);
|
1152 |
|
|
if (! status)
|
1153 |
|
|
return IRQ_NONE;
|
1154 |
|
|
|
1155 |
|
|
stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0);
|
1156 |
|
|
//snd_printk("interrupt status = 0x%08x, stat76=0x%08x\n", status, stat76);
|
1157 |
|
|
//snd_printk("ptr=0x%08x\n",snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0));
|
1158 |
|
|
mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */
|
1159 |
|
|
for(i = 0; i < 4; i++) {
|
1160 |
|
|
pchannel = &(chip->playback_channels[i]);
|
1161 |
|
|
if (stat76 & mask) {
|
1162 |
|
|
/* FIXME: Select the correct substream for period elapsed */
|
1163 |
|
|
if(pchannel->use) {
|
1164 |
|
|
snd_pcm_period_elapsed(pchannel->epcm->substream);
|
1165 |
|
|
//printk(KERN_INFO "interrupt [%d] used\n", i);
|
1166 |
|
|
}
|
1167 |
|
|
}
|
1168 |
|
|
//printk(KERN_INFO "channel=%p\n",pchannel);
|
1169 |
|
|
//printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
|
1170 |
|
|
mask <<= 1;
|
1171 |
|
|
}
|
1172 |
|
|
mask = 0x110000; /* 0x1 for one half, 0x10 for the other half period. */
|
1173 |
|
|
for(i = 0; i < 4; i++) {
|
1174 |
|
|
pchannel = &(chip->capture_channels[i]);
|
1175 |
|
|
if (stat76 & mask) {
|
1176 |
|
|
/* FIXME: Select the correct substream for period elapsed */
|
1177 |
|
|
if(pchannel->use) {
|
1178 |
|
|
snd_pcm_period_elapsed(pchannel->epcm->substream);
|
1179 |
|
|
//printk(KERN_INFO "interrupt [%d] used\n", i);
|
1180 |
|
|
}
|
1181 |
|
|
}
|
1182 |
|
|
//printk(KERN_INFO "channel=%p\n",pchannel);
|
1183 |
|
|
//printk(KERN_INFO "interrupt stat76[%d] = %08x, use=%d, channel=%d\n", i, stat76, pchannel->use, pchannel->number);
|
1184 |
|
|
mask <<= 1;
|
1185 |
|
|
}
|
1186 |
|
|
|
1187 |
|
|
snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
|
1188 |
|
|
|
1189 |
|
|
if (chip->midi.dev_id &&
|
1190 |
|
|
(status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
|
1191 |
|
|
if (chip->midi.interrupt)
|
1192 |
|
|
chip->midi.interrupt(&chip->midi, status);
|
1193 |
|
|
else
|
1194 |
|
|
chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable);
|
1195 |
|
|
}
|
1196 |
|
|
|
1197 |
|
|
// acknowledge the interrupt if necessary
|
1198 |
|
|
outl(status, chip->port+IPR);
|
1199 |
|
|
|
1200 |
|
|
return IRQ_HANDLED;
|
1201 |
|
|
}
|
1202 |
|
|
|
1203 |
|
|
static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct snd_pcm **rpcm)
|
1204 |
|
|
{
|
1205 |
|
|
struct snd_pcm *pcm;
|
1206 |
|
|
struct snd_pcm_substream *substream;
|
1207 |
|
|
int err;
|
1208 |
|
|
|
1209 |
|
|
if (rpcm)
|
1210 |
|
|
*rpcm = NULL;
|
1211 |
|
|
if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0)
|
1212 |
|
|
return err;
|
1213 |
|
|
|
1214 |
|
|
pcm->private_data = emu;
|
1215 |
|
|
|
1216 |
|
|
switch (device) {
|
1217 |
|
|
case 0:
|
1218 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_front_ops);
|
1219 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_0_ops);
|
1220 |
|
|
break;
|
1221 |
|
|
case 1:
|
1222 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_rear_ops);
|
1223 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_1_ops);
|
1224 |
|
|
break;
|
1225 |
|
|
case 2:
|
1226 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_center_lfe_ops);
|
1227 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_2_ops);
|
1228 |
|
|
break;
|
1229 |
|
|
case 3:
|
1230 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ca0106_playback_unknown_ops);
|
1231 |
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ca0106_capture_3_ops);
|
1232 |
|
|
break;
|
1233 |
|
|
}
|
1234 |
|
|
|
1235 |
|
|
pcm->info_flags = 0;
|
1236 |
|
|
pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
|
1237 |
|
|
strcpy(pcm->name, "CA0106");
|
1238 |
|
|
emu->pcm = pcm;
|
1239 |
|
|
|
1240 |
|
|
for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
1241 |
|
|
substream;
|
1242 |
|
|
substream = substream->next) {
|
1243 |
|
|
if ((err = snd_pcm_lib_preallocate_pages(substream,
|
1244 |
|
|
SNDRV_DMA_TYPE_DEV,
|
1245 |
|
|
snd_dma_pci_data(emu->pci),
|
1246 |
|
|
64*1024, 64*1024)) < 0) /* FIXME: 32*1024 for sound buffer, between 32and64 for Periods table. */
|
1247 |
|
|
return err;
|
1248 |
|
|
}
|
1249 |
|
|
|
1250 |
|
|
for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
|
1251 |
|
|
substream;
|
1252 |
|
|
substream = substream->next) {
|
1253 |
|
|
if ((err = snd_pcm_lib_preallocate_pages(substream,
|
1254 |
|
|
SNDRV_DMA_TYPE_DEV,
|
1255 |
|
|
snd_dma_pci_data(emu->pci),
|
1256 |
|
|
64*1024, 64*1024)) < 0)
|
1257 |
|
|
return err;
|
1258 |
|
|
}
|
1259 |
|
|
|
1260 |
|
|
if (rpcm)
|
1261 |
|
|
*rpcm = pcm;
|
1262 |
|
|
|
1263 |
|
|
return 0;
|
1264 |
|
|
}
|
1265 |
|
|
|
1266 |
|
|
#define SPI_REG(reg, value) (((reg) << SPI_REG_SHIFT) | (value))
|
1267 |
|
|
static unsigned int spi_dac_init[] = {
|
1268 |
|
|
SPI_REG(SPI_LDA1_REG, SPI_DA_BIT_0dB), /* 0dB dig. attenuation */
|
1269 |
|
|
SPI_REG(SPI_RDA1_REG, SPI_DA_BIT_0dB),
|
1270 |
|
|
SPI_REG(SPI_PL_REG, SPI_PL_BIT_L_L | SPI_PL_BIT_R_R | SPI_IZD_BIT),
|
1271 |
|
|
SPI_REG(SPI_FMT_REG, SPI_FMT_BIT_I2S | SPI_IWL_BIT_24),
|
1272 |
|
|
SPI_REG(SPI_LDA2_REG, SPI_DA_BIT_0dB),
|
1273 |
|
|
SPI_REG(SPI_RDA2_REG, SPI_DA_BIT_0dB),
|
1274 |
|
|
SPI_REG(SPI_LDA3_REG, SPI_DA_BIT_0dB),
|
1275 |
|
|
SPI_REG(SPI_RDA3_REG, SPI_DA_BIT_0dB),
|
1276 |
|
|
SPI_REG(SPI_MASTDA_REG, SPI_DA_BIT_0dB),
|
1277 |
|
|
SPI_REG(9, 0x00),
|
1278 |
|
|
SPI_REG(SPI_MS_REG, SPI_DACD0_BIT | SPI_DACD1_BIT | SPI_DACD2_BIT),
|
1279 |
|
|
SPI_REG(12, 0x00),
|
1280 |
|
|
SPI_REG(SPI_LDA4_REG, SPI_DA_BIT_0dB),
|
1281 |
|
|
SPI_REG(SPI_RDA4_REG, SPI_DA_BIT_0dB | SPI_DA_BIT_UPDATE),
|
1282 |
|
|
SPI_REG(SPI_DACD4_REG, 0x00),
|
1283 |
|
|
};
|
1284 |
|
|
|
1285 |
|
|
static unsigned int i2c_adc_init[][2] = {
|
1286 |
|
|
{ 0x17, 0x00 }, /* Reset */
|
1287 |
|
|
{ 0x07, 0x00 }, /* Timeout */
|
1288 |
|
|
{ 0x0b, 0x22 }, /* Interface control */
|
1289 |
|
|
{ 0x0c, 0x22 }, /* Master mode control */
|
1290 |
|
|
{ 0x0d, 0x08 }, /* Powerdown control */
|
1291 |
|
|
{ 0x0e, 0xcf }, /* Attenuation Left 0x01 = -103dB, 0xff = 24dB */
|
1292 |
|
|
{ 0x0f, 0xcf }, /* Attenuation Right 0.5dB steps */
|
1293 |
|
|
{ 0x10, 0x7b }, /* ALC Control 1 */
|
1294 |
|
|
{ 0x11, 0x00 }, /* ALC Control 2 */
|
1295 |
|
|
{ 0x12, 0x32 }, /* ALC Control 3 */
|
1296 |
|
|
{ 0x13, 0x00 }, /* Noise gate control */
|
1297 |
|
|
{ 0x14, 0xa6 }, /* Limiter control */
|
1298 |
|
|
{ 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */
|
1299 |
|
|
};
|
1300 |
|
|
|
1301 |
|
|
static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
|
1302 |
|
|
struct pci_dev *pci,
|
1303 |
|
|
struct snd_ca0106 **rchip)
|
1304 |
|
|
{
|
1305 |
|
|
struct snd_ca0106 *chip;
|
1306 |
|
|
struct snd_ca0106_details *c;
|
1307 |
|
|
int err;
|
1308 |
|
|
int ch;
|
1309 |
|
|
static struct snd_device_ops ops = {
|
1310 |
|
|
.dev_free = snd_ca0106_dev_free,
|
1311 |
|
|
};
|
1312 |
|
|
|
1313 |
|
|
*rchip = NULL;
|
1314 |
|
|
|
1315 |
|
|
if ((err = pci_enable_device(pci)) < 0)
|
1316 |
|
|
return err;
|
1317 |
|
|
if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 ||
|
1318 |
|
|
pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) {
|
1319 |
|
|
printk(KERN_ERR "error to set 32bit mask DMA\n");
|
1320 |
|
|
pci_disable_device(pci);
|
1321 |
|
|
return -ENXIO;
|
1322 |
|
|
}
|
1323 |
|
|
|
1324 |
|
|
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
|
1325 |
|
|
if (chip == NULL) {
|
1326 |
|
|
pci_disable_device(pci);
|
1327 |
|
|
return -ENOMEM;
|
1328 |
|
|
}
|
1329 |
|
|
|
1330 |
|
|
chip->card = card;
|
1331 |
|
|
chip->pci = pci;
|
1332 |
|
|
chip->irq = -1;
|
1333 |
|
|
|
1334 |
|
|
spin_lock_init(&chip->emu_lock);
|
1335 |
|
|
|
1336 |
|
|
chip->port = pci_resource_start(pci, 0);
|
1337 |
|
|
if ((chip->res_port = request_region(chip->port, 0x20,
|
1338 |
|
|
"snd_ca0106")) == NULL) {
|
1339 |
|
|
snd_ca0106_free(chip);
|
1340 |
|
|
printk(KERN_ERR "cannot allocate the port\n");
|
1341 |
|
|
return -EBUSY;
|
1342 |
|
|
}
|
1343 |
|
|
|
1344 |
|
|
if (request_irq(pci->irq, snd_ca0106_interrupt,
|
1345 |
|
|
IRQF_SHARED, "snd_ca0106", chip)) {
|
1346 |
|
|
snd_ca0106_free(chip);
|
1347 |
|
|
printk(KERN_ERR "cannot grab irq\n");
|
1348 |
|
|
return -EBUSY;
|
1349 |
|
|
}
|
1350 |
|
|
chip->irq = pci->irq;
|
1351 |
|
|
|
1352 |
|
|
/* This stores the periods table. */
|
1353 |
|
|
if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) {
|
1354 |
|
|
snd_ca0106_free(chip);
|
1355 |
|
|
return -ENOMEM;
|
1356 |
|
|
}
|
1357 |
|
|
|
1358 |
|
|
pci_set_master(pci);
|
1359 |
|
|
/* read serial */
|
1360 |
|
|
pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
|
1361 |
|
|
pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
|
1362 |
|
|
#if 1
|
1363 |
|
|
printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n", chip->model,
|
1364 |
|
|
pci->revision, chip->serial);
|
1365 |
|
|
#endif
|
1366 |
|
|
strcpy(card->driver, "CA0106");
|
1367 |
|
|
strcpy(card->shortname, "CA0106");
|
1368 |
|
|
|
1369 |
|
|
for (c = ca0106_chip_details; c->serial; c++) {
|
1370 |
|
|
if (subsystem[dev]) {
|
1371 |
|
|
if (c->serial == subsystem[dev])
|
1372 |
|
|
break;
|
1373 |
|
|
} else if (c->serial == chip->serial)
|
1374 |
|
|
break;
|
1375 |
|
|
}
|
1376 |
|
|
chip->details = c;
|
1377 |
|
|
if (subsystem[dev]) {
|
1378 |
|
|
printk(KERN_INFO "snd-ca0106: Sound card name=%s, subsystem=0x%x. Forced to subsystem=0x%x\n",
|
1379 |
|
|
c->name, chip->serial, subsystem[dev]);
|
1380 |
|
|
}
|
1381 |
|
|
|
1382 |
|
|
sprintf(card->longname, "%s at 0x%lx irq %i",
|
1383 |
|
|
c->name, chip->port, chip->irq);
|
1384 |
|
|
|
1385 |
|
|
outl(0, chip->port + INTE);
|
1386 |
|
|
|
1387 |
|
|
/*
|
1388 |
|
|
* Init to 0x02109204 :
|
1389 |
|
|
* Clock accuracy = 0 (1000ppm)
|
1390 |
|
|
* Sample Rate = 2 (48kHz)
|
1391 |
|
|
* Audio Channel = 1 (Left of 2)
|
1392 |
|
|
* Source Number = 0 (Unspecified)
|
1393 |
|
|
* Generation Status = 1 (Original for Cat Code 12)
|
1394 |
|
|
* Cat Code = 12 (Digital Signal Mixer)
|
1395 |
|
|
* Mode = 0 (Mode 0)
|
1396 |
|
|
* Emphasis = 0 (None)
|
1397 |
|
|
* CP = 1 (Copyright unasserted)
|
1398 |
|
|
* AN = 0 (Audio data)
|
1399 |
|
|
* P = 0 (Consumer)
|
1400 |
|
|
*/
|
1401 |
|
|
snd_ca0106_ptr_write(chip, SPCS0, 0,
|
1402 |
|
|
chip->spdif_bits[0] =
|
1403 |
|
|
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
|
1404 |
|
|
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
|
1405 |
|
|
SPCS_GENERATIONSTATUS | 0x00001200 |
|
1406 |
|
|
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
|
1407 |
|
|
/* Only SPCS1 has been tested */
|
1408 |
|
|
snd_ca0106_ptr_write(chip, SPCS1, 0,
|
1409 |
|
|
chip->spdif_bits[1] =
|
1410 |
|
|
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
|
1411 |
|
|
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
|
1412 |
|
|
SPCS_GENERATIONSTATUS | 0x00001200 |
|
1413 |
|
|
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
|
1414 |
|
|
snd_ca0106_ptr_write(chip, SPCS2, 0,
|
1415 |
|
|
chip->spdif_bits[2] =
|
1416 |
|
|
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
|
1417 |
|
|
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
|
1418 |
|
|
SPCS_GENERATIONSTATUS | 0x00001200 |
|
1419 |
|
|
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
|
1420 |
|
|
snd_ca0106_ptr_write(chip, SPCS3, 0,
|
1421 |
|
|
chip->spdif_bits[3] =
|
1422 |
|
|
SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
|
1423 |
|
|
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
|
1424 |
|
|
SPCS_GENERATIONSTATUS | 0x00001200 |
|
1425 |
|
|
0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
|
1426 |
|
|
|
1427 |
|
|
snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000);
|
1428 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000);
|
1429 |
|
|
|
1430 |
|
|
/* Write 0x8000 to AC97_REC_GAIN to mute it. */
|
1431 |
|
|
outb(AC97_REC_GAIN, chip->port + AC97ADDRESS);
|
1432 |
|
|
outw(0x8000, chip->port + AC97DATA);
|
1433 |
|
|
#if 0
|
1434 |
|
|
snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006);
|
1435 |
|
|
snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006);
|
1436 |
|
|
snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006);
|
1437 |
|
|
snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006);
|
1438 |
|
|
#endif
|
1439 |
|
|
|
1440 |
|
|
//snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */
|
1441 |
|
|
/* Analog or Digital output */
|
1442 |
|
|
snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf);
|
1443 |
|
|
snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */
|
1444 |
|
|
chip->spdif_enable = 0; /* Set digital SPDIF output off */
|
1445 |
|
|
//snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */
|
1446 |
|
|
//snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */
|
1447 |
|
|
|
1448 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */
|
1449 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */
|
1450 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume */
|
1451 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
|
1452 |
|
|
snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410);
|
1453 |
|
|
snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676);
|
1454 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410);
|
1455 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676);
|
1456 |
|
|
for(ch = 0; ch < 4; ch++) {
|
1457 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); /* Only high 16 bits matter */
|
1458 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030);
|
1459 |
|
|
//snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */
|
1460 |
|
|
//snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */
|
1461 |
|
|
snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); /* Mute */
|
1462 |
|
|
snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); /* Mute */
|
1463 |
|
|
}
|
1464 |
|
|
if (chip->details->i2c_adc == 1) {
|
1465 |
|
|
/* Select MIC, Line in, TAD in, AUX in */
|
1466 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4);
|
1467 |
|
|
/* Default to CAPTURE_SOURCE to i2s in */
|
1468 |
|
|
chip->capture_source = 3;
|
1469 |
|
|
} else if (chip->details->ac97 == 1) {
|
1470 |
|
|
/* Default to AC97 in */
|
1471 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x444400e4);
|
1472 |
|
|
/* Default to CAPTURE_SOURCE to AC97 in */
|
1473 |
|
|
chip->capture_source = 4;
|
1474 |
|
|
} else {
|
1475 |
|
|
/* Select MIC, Line in, TAD in, AUX in */
|
1476 |
|
|
snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4);
|
1477 |
|
|
/* Default to Set CAPTURE_SOURCE to i2s in */
|
1478 |
|
|
chip->capture_source = 3;
|
1479 |
|
|
}
|
1480 |
|
|
|
1481 |
|
|
if (chip->details->gpio_type == 2) { /* The SB0438 use GPIO differently. */
|
1482 |
|
|
/* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */
|
1483 |
|
|
outl(0x0, chip->port+GPIO);
|
1484 |
|
|
//outl(0x00f0e000, chip->port+GPIO); /* Analog */
|
1485 |
|
|
outl(0x005f5301, chip->port+GPIO); /* Analog */
|
1486 |
|
|
} else if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */
|
1487 |
|
|
/* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */
|
1488 |
|
|
outl(0x0, chip->port+GPIO);
|
1489 |
|
|
//outl(0x00f0e000, chip->port+GPIO); /* Analog */
|
1490 |
|
|
outl(0x005f5301, chip->port+GPIO); /* Analog */
|
1491 |
|
|
} else {
|
1492 |
|
|
outl(0x0, chip->port+GPIO);
|
1493 |
|
|
outl(0x005f03a3, chip->port+GPIO); /* Analog */
|
1494 |
|
|
//outl(0x005f02a2, chip->port+GPIO); /* SPDIF */
|
1495 |
|
|
}
|
1496 |
|
|
snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */
|
1497 |
|
|
|
1498 |
|
|
//outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG);
|
1499 |
|
|
//outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */
|
1500 |
|
|
//outl(0x00000009, chip->port+HCFG);
|
1501 |
|
|
outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); /* AC97 2.0, Enable outputs. */
|
1502 |
|
|
|
1503 |
|
|
if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */
|
1504 |
|
|
int size, n;
|
1505 |
|
|
|
1506 |
|
|
size = ARRAY_SIZE(i2c_adc_init);
|
1507 |
|
|
//snd_printk("I2C:array size=0x%x\n", size);
|
1508 |
|
|
for (n=0; n < size; n++) {
|
1509 |
|
|
snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], i2c_adc_init[n][1]);
|
1510 |
|
|
}
|
1511 |
|
|
for (n=0; n < 4; n++) {
|
1512 |
|
|
chip->i2c_capture_volume[n][0]= 0xcf;
|
1513 |
|
|
chip->i2c_capture_volume[n][1]= 0xcf;
|
1514 |
|
|
}
|
1515 |
|
|
chip->i2c_capture_source=2; /* Line in */
|
1516 |
|
|
//snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */
|
1517 |
|
|
}
|
1518 |
|
|
if (chip->details->spi_dac == 1) { /* The SB0570 use SPI to control DAC. */
|
1519 |
|
|
int size, n;
|
1520 |
|
|
|
1521 |
|
|
size = ARRAY_SIZE(spi_dac_init);
|
1522 |
|
|
for (n = 0; n < size; n++) {
|
1523 |
|
|
int reg = spi_dac_init[n] >> SPI_REG_SHIFT;
|
1524 |
|
|
|
1525 |
|
|
snd_ca0106_spi_write(chip, spi_dac_init[n]);
|
1526 |
|
|
if (reg < ARRAY_SIZE(chip->spi_dac_reg))
|
1527 |
|
|
chip->spi_dac_reg[reg] = spi_dac_init[n];
|
1528 |
|
|
}
|
1529 |
|
|
}
|
1530 |
|
|
|
1531 |
|
|
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
|
1532 |
|
|
chip, &ops)) < 0) {
|
1533 |
|
|
snd_ca0106_free(chip);
|
1534 |
|
|
return err;
|
1535 |
|
|
}
|
1536 |
|
|
*rchip = chip;
|
1537 |
|
|
return 0;
|
1538 |
|
|
}
|
1539 |
|
|
|
1540 |
|
|
|
1541 |
|
|
static void ca0106_midi_interrupt_enable(struct snd_ca_midi *midi, int intr)
|
1542 |
|
|
{
|
1543 |
|
|
snd_ca0106_intr_enable((struct snd_ca0106 *)(midi->dev_id), intr);
|
1544 |
|
|
}
|
1545 |
|
|
|
1546 |
|
|
static void ca0106_midi_interrupt_disable(struct snd_ca_midi *midi, int intr)
|
1547 |
|
|
{
|
1548 |
|
|
snd_ca0106_intr_disable((struct snd_ca0106 *)(midi->dev_id), intr);
|
1549 |
|
|
}
|
1550 |
|
|
|
1551 |
|
|
static unsigned char ca0106_midi_read(struct snd_ca_midi *midi, int idx)
|
1552 |
|
|
{
|
1553 |
|
|
return (unsigned char)snd_ca0106_ptr_read((struct snd_ca0106 *)(midi->dev_id),
|
1554 |
|
|
midi->port + idx, 0);
|
1555 |
|
|
}
|
1556 |
|
|
|
1557 |
|
|
static void ca0106_midi_write(struct snd_ca_midi *midi, int data, int idx)
|
1558 |
|
|
{
|
1559 |
|
|
snd_ca0106_ptr_write((struct snd_ca0106 *)(midi->dev_id), midi->port + idx, 0, data);
|
1560 |
|
|
}
|
1561 |
|
|
|
1562 |
|
|
static struct snd_card *ca0106_dev_id_card(void *dev_id)
|
1563 |
|
|
{
|
1564 |
|
|
return ((struct snd_ca0106 *)dev_id)->card;
|
1565 |
|
|
}
|
1566 |
|
|
|
1567 |
|
|
static int ca0106_dev_id_port(void *dev_id)
|
1568 |
|
|
{
|
1569 |
|
|
return ((struct snd_ca0106 *)dev_id)->port;
|
1570 |
|
|
}
|
1571 |
|
|
|
1572 |
|
|
static int __devinit snd_ca0106_midi(struct snd_ca0106 *chip, unsigned int channel)
|
1573 |
|
|
{
|
1574 |
|
|
struct snd_ca_midi *midi;
|
1575 |
|
|
char *name;
|
1576 |
|
|
int err;
|
1577 |
|
|
|
1578 |
|
|
if (channel == CA0106_MIDI_CHAN_B) {
|
1579 |
|
|
name = "CA0106 MPU-401 (UART) B";
|
1580 |
|
|
midi = &chip->midi2;
|
1581 |
|
|
midi->tx_enable = INTE_MIDI_TX_B;
|
1582 |
|
|
midi->rx_enable = INTE_MIDI_RX_B;
|
1583 |
|
|
midi->ipr_tx = IPR_MIDI_TX_B;
|
1584 |
|
|
midi->ipr_rx = IPR_MIDI_RX_B;
|
1585 |
|
|
midi->port = MIDI_UART_B_DATA;
|
1586 |
|
|
} else {
|
1587 |
|
|
name = "CA0106 MPU-401 (UART)";
|
1588 |
|
|
midi = &chip->midi;
|
1589 |
|
|
midi->tx_enable = INTE_MIDI_TX_A;
|
1590 |
|
|
midi->rx_enable = INTE_MIDI_TX_B;
|
1591 |
|
|
midi->ipr_tx = IPR_MIDI_TX_A;
|
1592 |
|
|
midi->ipr_rx = IPR_MIDI_RX_A;
|
1593 |
|
|
midi->port = MIDI_UART_A_DATA;
|
1594 |
|
|
}
|
1595 |
|
|
|
1596 |
|
|
midi->reset = CA0106_MPU401_RESET;
|
1597 |
|
|
midi->enter_uart = CA0106_MPU401_ENTER_UART;
|
1598 |
|
|
midi->ack = CA0106_MPU401_ACK;
|
1599 |
|
|
|
1600 |
|
|
midi->input_avail = CA0106_MIDI_INPUT_AVAIL;
|
1601 |
|
|
midi->output_ready = CA0106_MIDI_OUTPUT_READY;
|
1602 |
|
|
|
1603 |
|
|
midi->channel = channel;
|
1604 |
|
|
|
1605 |
|
|
midi->interrupt_enable = ca0106_midi_interrupt_enable;
|
1606 |
|
|
midi->interrupt_disable = ca0106_midi_interrupt_disable;
|
1607 |
|
|
|
1608 |
|
|
midi->read = ca0106_midi_read;
|
1609 |
|
|
midi->write = ca0106_midi_write;
|
1610 |
|
|
|
1611 |
|
|
midi->get_dev_id_card = ca0106_dev_id_card;
|
1612 |
|
|
midi->get_dev_id_port = ca0106_dev_id_port;
|
1613 |
|
|
|
1614 |
|
|
midi->dev_id = chip;
|
1615 |
|
|
|
1616 |
|
|
if ((err = ca_midi_init(chip, midi, 0, name)) < 0)
|
1617 |
|
|
return err;
|
1618 |
|
|
|
1619 |
|
|
return 0;
|
1620 |
|
|
}
|
1621 |
|
|
|
1622 |
|
|
|
1623 |
|
|
static int __devinit snd_ca0106_probe(struct pci_dev *pci,
|
1624 |
|
|
const struct pci_device_id *pci_id)
|
1625 |
|
|
{
|
1626 |
|
|
static int dev;
|
1627 |
|
|
struct snd_card *card;
|
1628 |
|
|
struct snd_ca0106 *chip;
|
1629 |
|
|
int err;
|
1630 |
|
|
|
1631 |
|
|
if (dev >= SNDRV_CARDS)
|
1632 |
|
|
return -ENODEV;
|
1633 |
|
|
if (!enable[dev]) {
|
1634 |
|
|
dev++;
|
1635 |
|
|
return -ENOENT;
|
1636 |
|
|
}
|
1637 |
|
|
|
1638 |
|
|
card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
|
1639 |
|
|
if (card == NULL)
|
1640 |
|
|
return -ENOMEM;
|
1641 |
|
|
|
1642 |
|
|
if ((err = snd_ca0106_create(dev, card, pci, &chip)) < 0) {
|
1643 |
|
|
snd_card_free(card);
|
1644 |
|
|
return err;
|
1645 |
|
|
}
|
1646 |
|
|
|
1647 |
|
|
if ((err = snd_ca0106_pcm(chip, 0, NULL)) < 0) {
|
1648 |
|
|
snd_card_free(card);
|
1649 |
|
|
return err;
|
1650 |
|
|
}
|
1651 |
|
|
if ((err = snd_ca0106_pcm(chip, 1, NULL)) < 0) {
|
1652 |
|
|
snd_card_free(card);
|
1653 |
|
|
return err;
|
1654 |
|
|
}
|
1655 |
|
|
if ((err = snd_ca0106_pcm(chip, 2, NULL)) < 0) {
|
1656 |
|
|
snd_card_free(card);
|
1657 |
|
|
return err;
|
1658 |
|
|
}
|
1659 |
|
|
if ((err = snd_ca0106_pcm(chip, 3, NULL)) < 0) {
|
1660 |
|
|
snd_card_free(card);
|
1661 |
|
|
return err;
|
1662 |
|
|
}
|
1663 |
|
|
if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */
|
1664 |
|
|
if ((err = snd_ca0106_ac97(chip)) < 0) {
|
1665 |
|
|
snd_card_free(card);
|
1666 |
|
|
return err;
|
1667 |
|
|
}
|
1668 |
|
|
}
|
1669 |
|
|
if ((err = snd_ca0106_mixer(chip)) < 0) {
|
1670 |
|
|
snd_card_free(card);
|
1671 |
|
|
return err;
|
1672 |
|
|
}
|
1673 |
|
|
|
1674 |
|
|
snd_printdd("ca0106: probe for MIDI channel A ...");
|
1675 |
|
|
if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) {
|
1676 |
|
|
snd_card_free(card);
|
1677 |
|
|
snd_printdd(" failed, err=0x%x\n",err);
|
1678 |
|
|
return err;
|
1679 |
|
|
}
|
1680 |
|
|
snd_printdd(" done.\n");
|
1681 |
|
|
|
1682 |
|
|
#ifdef CONFIG_PROC_FS
|
1683 |
|
|
snd_ca0106_proc_init(chip);
|
1684 |
|
|
#endif
|
1685 |
|
|
|
1686 |
|
|
snd_card_set_dev(card, &pci->dev);
|
1687 |
|
|
|
1688 |
|
|
if ((err = snd_card_register(card)) < 0) {
|
1689 |
|
|
snd_card_free(card);
|
1690 |
|
|
return err;
|
1691 |
|
|
}
|
1692 |
|
|
|
1693 |
|
|
pci_set_drvdata(pci, card);
|
1694 |
|
|
dev++;
|
1695 |
|
|
return 0;
|
1696 |
|
|
}
|
1697 |
|
|
|
1698 |
|
|
static void __devexit snd_ca0106_remove(struct pci_dev *pci)
|
1699 |
|
|
{
|
1700 |
|
|
snd_card_free(pci_get_drvdata(pci));
|
1701 |
|
|
pci_set_drvdata(pci, NULL);
|
1702 |
|
|
}
|
1703 |
|
|
|
1704 |
|
|
// PCI IDs
|
1705 |
|
|
static struct pci_device_id snd_ca0106_ids[] = {
|
1706 |
|
|
{ 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */
|
1707 |
|
|
{ 0, }
|
1708 |
|
|
};
|
1709 |
|
|
MODULE_DEVICE_TABLE(pci, snd_ca0106_ids);
|
1710 |
|
|
|
1711 |
|
|
// pci_driver definition
|
1712 |
|
|
static struct pci_driver driver = {
|
1713 |
|
|
.name = "CA0106",
|
1714 |
|
|
.id_table = snd_ca0106_ids,
|
1715 |
|
|
.probe = snd_ca0106_probe,
|
1716 |
|
|
.remove = __devexit_p(snd_ca0106_remove),
|
1717 |
|
|
};
|
1718 |
|
|
|
1719 |
|
|
// initialization of the module
|
1720 |
|
|
static int __init alsa_card_ca0106_init(void)
|
1721 |
|
|
{
|
1722 |
|
|
return pci_register_driver(&driver);
|
1723 |
|
|
}
|
1724 |
|
|
|
1725 |
|
|
// clean up the module
|
1726 |
|
|
static void __exit alsa_card_ca0106_exit(void)
|
1727 |
|
|
{
|
1728 |
|
|
pci_unregister_driver(&driver);
|
1729 |
|
|
}
|
1730 |
|
|
|
1731 |
|
|
module_init(alsa_card_ca0106_init)
|
1732 |
|
|
module_exit(alsa_card_ca0106_exit)
|