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