Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * C-Media CMI8788 driver - PCM code |
| 3 | * |
| 4 | * Copyright (c) Clemens Ladisch <clemens@ladisch.de> |
| 5 | * |
| 6 | * |
| 7 | * This driver is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License, version 2. |
| 9 | * |
| 10 | * This driver is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this driver; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | */ |
| 19 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 20 | #include <linux/pci.h> |
| 21 | #include <sound/control.h> |
| 22 | #include <sound/core.h> |
| 23 | #include <sound/pcm.h> |
| 24 | #include <sound/pcm_params.h> |
| 25 | #include "oxygen.h" |
| 26 | |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 27 | /* most DMA channels have a 16-bit counter for 32-bit words */ |
| 28 | #define BUFFER_BYTES_MAX ((1 << 16) * 4) |
| 29 | /* the multichannel DMA channel has a 24-bit counter */ |
| 30 | #define BUFFER_BYTES_MAX_MULTICH ((1 << 24) * 4) |
| 31 | |
| 32 | #define PERIOD_BYTES_MIN 64 |
| 33 | |
| 34 | #define DEFAULT_BUFFER_BYTES (BUFFER_BYTES_MAX / 2) |
| 35 | #define DEFAULT_BUFFER_BYTES_MULTICH (1024 * 1024) |
| 36 | |
Clemens Ladisch | c57cccc | 2008-01-21 08:54:06 +0100 | [diff] [blame] | 37 | static const struct snd_pcm_hardware oxygen_stereo_hardware = { |
| 38 | .info = SNDRV_PCM_INFO_MMAP | |
| 39 | SNDRV_PCM_INFO_MMAP_VALID | |
| 40 | SNDRV_PCM_INFO_INTERLEAVED | |
| 41 | SNDRV_PCM_INFO_PAUSE | |
| 42 | SNDRV_PCM_INFO_SYNC_START, |
| 43 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 44 | SNDRV_PCM_FMTBIT_S32_LE, |
| 45 | .rates = SNDRV_PCM_RATE_32000 | |
| 46 | SNDRV_PCM_RATE_44100 | |
| 47 | SNDRV_PCM_RATE_48000 | |
| 48 | SNDRV_PCM_RATE_64000 | |
| 49 | SNDRV_PCM_RATE_88200 | |
| 50 | SNDRV_PCM_RATE_96000 | |
| 51 | SNDRV_PCM_RATE_176400 | |
| 52 | SNDRV_PCM_RATE_192000, |
| 53 | .rate_min = 32000, |
| 54 | .rate_max = 192000, |
| 55 | .channels_min = 2, |
| 56 | .channels_max = 2, |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 57 | .buffer_bytes_max = BUFFER_BYTES_MAX, |
| 58 | .period_bytes_min = PERIOD_BYTES_MIN, |
| 59 | .period_bytes_max = BUFFER_BYTES_MAX / 2, |
Clemens Ladisch | c57cccc | 2008-01-21 08:54:06 +0100 | [diff] [blame] | 60 | .periods_min = 2, |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 61 | .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN, |
Clemens Ladisch | c57cccc | 2008-01-21 08:54:06 +0100 | [diff] [blame] | 62 | }; |
| 63 | static const struct snd_pcm_hardware oxygen_multichannel_hardware = { |
| 64 | .info = SNDRV_PCM_INFO_MMAP | |
| 65 | SNDRV_PCM_INFO_MMAP_VALID | |
| 66 | SNDRV_PCM_INFO_INTERLEAVED | |
| 67 | SNDRV_PCM_INFO_PAUSE | |
| 68 | SNDRV_PCM_INFO_SYNC_START, |
| 69 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 70 | SNDRV_PCM_FMTBIT_S32_LE, |
| 71 | .rates = SNDRV_PCM_RATE_32000 | |
| 72 | SNDRV_PCM_RATE_44100 | |
| 73 | SNDRV_PCM_RATE_48000 | |
| 74 | SNDRV_PCM_RATE_64000 | |
| 75 | SNDRV_PCM_RATE_88200 | |
| 76 | SNDRV_PCM_RATE_96000 | |
| 77 | SNDRV_PCM_RATE_176400 | |
| 78 | SNDRV_PCM_RATE_192000, |
| 79 | .rate_min = 32000, |
| 80 | .rate_max = 192000, |
| 81 | .channels_min = 2, |
| 82 | .channels_max = 8, |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 83 | .buffer_bytes_max = BUFFER_BYTES_MAX_MULTICH, |
| 84 | .period_bytes_min = PERIOD_BYTES_MIN, |
| 85 | .period_bytes_max = BUFFER_BYTES_MAX_MULTICH / 2, |
Clemens Ladisch | c57cccc | 2008-01-21 08:54:06 +0100 | [diff] [blame] | 86 | .periods_min = 2, |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 87 | .periods_max = BUFFER_BYTES_MAX_MULTICH / PERIOD_BYTES_MIN, |
Clemens Ladisch | c57cccc | 2008-01-21 08:54:06 +0100 | [diff] [blame] | 88 | }; |
| 89 | static const struct snd_pcm_hardware oxygen_ac97_hardware = { |
| 90 | .info = SNDRV_PCM_INFO_MMAP | |
| 91 | SNDRV_PCM_INFO_MMAP_VALID | |
| 92 | SNDRV_PCM_INFO_INTERLEAVED | |
| 93 | SNDRV_PCM_INFO_PAUSE | |
| 94 | SNDRV_PCM_INFO_SYNC_START, |
| 95 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 96 | .rates = SNDRV_PCM_RATE_48000, |
| 97 | .rate_min = 48000, |
| 98 | .rate_max = 48000, |
| 99 | .channels_min = 2, |
| 100 | .channels_max = 2, |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 101 | .buffer_bytes_max = BUFFER_BYTES_MAX, |
| 102 | .period_bytes_min = PERIOD_BYTES_MIN, |
| 103 | .period_bytes_max = BUFFER_BYTES_MAX / 2, |
Clemens Ladisch | c57cccc | 2008-01-21 08:54:06 +0100 | [diff] [blame] | 104 | .periods_min = 2, |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 105 | .periods_max = BUFFER_BYTES_MAX / PERIOD_BYTES_MIN, |
Clemens Ladisch | c57cccc | 2008-01-21 08:54:06 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | static const struct snd_pcm_hardware *const oxygen_hardware[PCM_COUNT] = { |
| 109 | [PCM_A] = &oxygen_stereo_hardware, |
| 110 | [PCM_B] = &oxygen_stereo_hardware, |
| 111 | [PCM_C] = &oxygen_stereo_hardware, |
| 112 | [PCM_SPDIF] = &oxygen_stereo_hardware, |
| 113 | [PCM_MULTICH] = &oxygen_multichannel_hardware, |
| 114 | [PCM_AC97] = &oxygen_ac97_hardware, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 115 | }; |
| 116 | |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 117 | static inline unsigned int |
| 118 | oxygen_substream_channel(struct snd_pcm_substream *substream) |
| 119 | { |
| 120 | return (unsigned int)(uintptr_t)substream->runtime->private_data; |
| 121 | } |
| 122 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 123 | static int oxygen_open(struct snd_pcm_substream *substream, |
| 124 | unsigned int channel) |
| 125 | { |
| 126 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 127 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 128 | int err; |
| 129 | |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 130 | runtime->private_data = (void *)(uintptr_t)channel; |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 131 | if (channel == PCM_B && chip->has_ac97_1 && |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 132 | (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1)) |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 133 | runtime->hw = oxygen_ac97_hardware; |
| 134 | else |
| 135 | runtime->hw = *oxygen_hardware[channel]; |
Clemens Ladisch | 976cd62 | 2008-01-25 08:37:49 +0100 | [diff] [blame] | 136 | switch (channel) { |
| 137 | case PCM_C: |
Clemens Ladisch | 33c646e | 2008-01-24 08:43:16 +0100 | [diff] [blame] | 138 | runtime->hw.rates &= ~(SNDRV_PCM_RATE_32000 | |
| 139 | SNDRV_PCM_RATE_64000); |
| 140 | runtime->hw.rate_min = 44100; |
Clemens Ladisch | 976cd62 | 2008-01-25 08:37:49 +0100 | [diff] [blame] | 141 | break; |
| 142 | case PCM_MULTICH: |
| 143 | runtime->hw.channels_max = chip->model->dac_channels; |
| 144 | break; |
Clemens Ladisch | 33c646e | 2008-01-24 08:43:16 +0100 | [diff] [blame] | 145 | } |
Clemens Ladisch | 747c601 | 2008-01-16 08:32:53 +0100 | [diff] [blame] | 146 | if (chip->model->pcm_hardware_filter) |
| 147 | chip->model->pcm_hardware_filter(channel, &runtime->hw); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 148 | err = snd_pcm_hw_constraint_step(runtime, 0, |
| 149 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32); |
| 150 | if (err < 0) |
| 151 | return err; |
| 152 | err = snd_pcm_hw_constraint_step(runtime, 0, |
| 153 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32); |
| 154 | if (err < 0) |
| 155 | return err; |
| 156 | if (runtime->hw.formats & SNDRV_PCM_FMTBIT_S32_LE) { |
| 157 | err = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 158 | if (err < 0) |
| 159 | return err; |
| 160 | } |
| 161 | if (runtime->hw.channels_max > 2) { |
| 162 | err = snd_pcm_hw_constraint_step(runtime, 0, |
| 163 | SNDRV_PCM_HW_PARAM_CHANNELS, |
| 164 | 2); |
| 165 | if (err < 0) |
| 166 | return err; |
| 167 | } |
| 168 | snd_pcm_set_sync(substream); |
| 169 | chip->streams[channel] = substream; |
| 170 | |
| 171 | mutex_lock(&chip->mutex); |
| 172 | chip->pcm_active |= 1 << channel; |
| 173 | if (channel == PCM_SPDIF) { |
| 174 | chip->spdif_pcm_bits = chip->spdif_bits; |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 175 | chip->controls[CONTROL_SPDIF_PCM]->vd[0].access &= |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 176 | ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 177 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 178 | SNDRV_CTL_EVENT_MASK_INFO, |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 179 | &chip->controls[CONTROL_SPDIF_PCM]->id); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 180 | } |
| 181 | mutex_unlock(&chip->mutex); |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static int oxygen_rec_a_open(struct snd_pcm_substream *substream) |
| 187 | { |
| 188 | return oxygen_open(substream, PCM_A); |
| 189 | } |
| 190 | |
| 191 | static int oxygen_rec_b_open(struct snd_pcm_substream *substream) |
| 192 | { |
| 193 | return oxygen_open(substream, PCM_B); |
| 194 | } |
| 195 | |
| 196 | static int oxygen_rec_c_open(struct snd_pcm_substream *substream) |
| 197 | { |
| 198 | return oxygen_open(substream, PCM_C); |
| 199 | } |
| 200 | |
| 201 | static int oxygen_spdif_open(struct snd_pcm_substream *substream) |
| 202 | { |
| 203 | return oxygen_open(substream, PCM_SPDIF); |
| 204 | } |
| 205 | |
| 206 | static int oxygen_multich_open(struct snd_pcm_substream *substream) |
| 207 | { |
| 208 | return oxygen_open(substream, PCM_MULTICH); |
| 209 | } |
| 210 | |
| 211 | static int oxygen_ac97_open(struct snd_pcm_substream *substream) |
| 212 | { |
| 213 | return oxygen_open(substream, PCM_AC97); |
| 214 | } |
| 215 | |
| 216 | static int oxygen_close(struct snd_pcm_substream *substream) |
| 217 | { |
| 218 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 219 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 220 | |
| 221 | mutex_lock(&chip->mutex); |
| 222 | chip->pcm_active &= ~(1 << channel); |
| 223 | if (channel == PCM_SPDIF) { |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 224 | chip->controls[CONTROL_SPDIF_PCM]->vd[0].access |= |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 225 | SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 226 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 227 | SNDRV_CTL_EVENT_MASK_INFO, |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 228 | &chip->controls[CONTROL_SPDIF_PCM]->id); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 229 | } |
| 230 | if (channel == PCM_SPDIF || channel == PCM_MULTICH) |
| 231 | oxygen_update_spdif_source(chip); |
| 232 | mutex_unlock(&chip->mutex); |
| 233 | |
| 234 | chip->streams[channel] = NULL; |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static unsigned int oxygen_format(struct snd_pcm_hw_params *hw_params) |
| 239 | { |
| 240 | if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE) |
| 241 | return OXYGEN_FORMAT_24; |
| 242 | else |
| 243 | return OXYGEN_FORMAT_16; |
| 244 | } |
| 245 | |
| 246 | static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params) |
| 247 | { |
| 248 | switch (params_rate(hw_params)) { |
| 249 | case 32000: |
| 250 | return OXYGEN_RATE_32000; |
| 251 | case 44100: |
| 252 | return OXYGEN_RATE_44100; |
| 253 | default: /* 48000 */ |
| 254 | return OXYGEN_RATE_48000; |
| 255 | case 64000: |
| 256 | return OXYGEN_RATE_64000; |
| 257 | case 88200: |
| 258 | return OXYGEN_RATE_88200; |
| 259 | case 96000: |
| 260 | return OXYGEN_RATE_96000; |
| 261 | case 176400: |
| 262 | return OXYGEN_RATE_176400; |
| 263 | case 192000: |
| 264 | return OXYGEN_RATE_192000; |
| 265 | } |
| 266 | } |
| 267 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 268 | static unsigned int oxygen_i2s_mclk(struct snd_pcm_hw_params *hw_params) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 269 | { |
Clemens Ladisch | b78e3db | 2008-01-25 08:39:26 +0100 | [diff] [blame] | 270 | if (params_rate(hw_params) <= 96000) |
| 271 | return OXYGEN_I2S_MCLK_256; |
| 272 | else |
| 273 | return OXYGEN_I2S_MCLK_128; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 276 | static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 277 | { |
| 278 | if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE) |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 279 | return OXYGEN_I2S_BITS_24; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 280 | else |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 281 | return OXYGEN_I2S_BITS_16; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | static unsigned int oxygen_play_channels(struct snd_pcm_hw_params *hw_params) |
| 285 | { |
| 286 | switch (params_channels(hw_params)) { |
| 287 | default: /* 2 */ |
| 288 | return OXYGEN_PLAY_CHANNELS_2; |
| 289 | case 4: |
| 290 | return OXYGEN_PLAY_CHANNELS_4; |
| 291 | case 6: |
| 292 | return OXYGEN_PLAY_CHANNELS_6; |
| 293 | case 8: |
| 294 | return OXYGEN_PLAY_CHANNELS_8; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | static const unsigned int channel_base_registers[PCM_COUNT] = { |
| 299 | [PCM_A] = OXYGEN_DMA_A_ADDRESS, |
| 300 | [PCM_B] = OXYGEN_DMA_B_ADDRESS, |
| 301 | [PCM_C] = OXYGEN_DMA_C_ADDRESS, |
| 302 | [PCM_SPDIF] = OXYGEN_DMA_SPDIF_ADDRESS, |
| 303 | [PCM_MULTICH] = OXYGEN_DMA_MULTICH_ADDRESS, |
| 304 | [PCM_AC97] = OXYGEN_DMA_AC97_ADDRESS, |
| 305 | }; |
| 306 | |
| 307 | static int oxygen_hw_params(struct snd_pcm_substream *substream, |
| 308 | struct snd_pcm_hw_params *hw_params) |
| 309 | { |
| 310 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 311 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 312 | int err; |
| 313 | |
| 314 | err = snd_pcm_lib_malloc_pages(substream, |
| 315 | params_buffer_bytes(hw_params)); |
| 316 | if (err < 0) |
| 317 | return err; |
| 318 | |
| 319 | oxygen_write32(chip, channel_base_registers[channel], |
| 320 | (u32)substream->runtime->dma_addr); |
| 321 | if (channel == PCM_MULTICH) { |
| 322 | oxygen_write32(chip, OXYGEN_DMA_MULTICH_COUNT, |
| 323 | params_buffer_bytes(hw_params) / 4 - 1); |
| 324 | oxygen_write32(chip, OXYGEN_DMA_MULTICH_TCOUNT, |
| 325 | params_period_bytes(hw_params) / 4 - 1); |
| 326 | } else { |
| 327 | oxygen_write16(chip, channel_base_registers[channel] + 4, |
| 328 | params_buffer_bytes(hw_params) / 4 - 1); |
| 329 | oxygen_write16(chip, channel_base_registers[channel] + 6, |
| 330 | params_period_bytes(hw_params) / 4 - 1); |
| 331 | } |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream, |
| 336 | struct snd_pcm_hw_params *hw_params) |
| 337 | { |
| 338 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 339 | int err; |
| 340 | |
| 341 | err = oxygen_hw_params(substream, hw_params); |
| 342 | if (err < 0) |
| 343 | return err; |
| 344 | |
| 345 | spin_lock_irq(&chip->reg_lock); |
| 346 | oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, |
| 347 | oxygen_format(hw_params) << OXYGEN_REC_FORMAT_A_SHIFT, |
| 348 | OXYGEN_REC_FORMAT_A_MASK); |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 349 | oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, |
| 350 | oxygen_rate(hw_params) | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 351 | oxygen_i2s_mclk(hw_params) | |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 352 | chip->model->adc_i2s_format | |
| 353 | oxygen_i2s_bits(hw_params), |
| 354 | OXYGEN_I2S_RATE_MASK | |
| 355 | OXYGEN_I2S_FORMAT_MASK | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 356 | OXYGEN_I2S_MCLK_MASK | |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 357 | OXYGEN_I2S_BITS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 358 | spin_unlock_irq(&chip->reg_lock); |
| 359 | |
| 360 | mutex_lock(&chip->mutex); |
| 361 | chip->model->set_adc_params(chip, hw_params); |
| 362 | mutex_unlock(&chip->mutex); |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream, |
| 367 | struct snd_pcm_hw_params *hw_params) |
| 368 | { |
| 369 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 370 | int is_ac97; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 371 | int err; |
| 372 | |
| 373 | err = oxygen_hw_params(substream, hw_params); |
| 374 | if (err < 0) |
| 375 | return err; |
| 376 | |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 377 | is_ac97 = chip->has_ac97_1 && |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 378 | (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 379 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 380 | spin_lock_irq(&chip->reg_lock); |
| 381 | oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, |
| 382 | oxygen_format(hw_params) << OXYGEN_REC_FORMAT_B_SHIFT, |
| 383 | OXYGEN_REC_FORMAT_B_MASK); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 384 | if (!is_ac97) |
| 385 | oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, |
| 386 | oxygen_rate(hw_params) | |
| 387 | oxygen_i2s_mclk(hw_params) | |
| 388 | chip->model->adc_i2s_format | |
| 389 | oxygen_i2s_bits(hw_params), |
| 390 | OXYGEN_I2S_RATE_MASK | |
| 391 | OXYGEN_I2S_FORMAT_MASK | |
| 392 | OXYGEN_I2S_MCLK_MASK | |
| 393 | OXYGEN_I2S_BITS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 394 | spin_unlock_irq(&chip->reg_lock); |
| 395 | |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 396 | if (!is_ac97) { |
| 397 | mutex_lock(&chip->mutex); |
| 398 | chip->model->set_adc_params(chip, hw_params); |
| 399 | mutex_unlock(&chip->mutex); |
| 400 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static int oxygen_rec_c_hw_params(struct snd_pcm_substream *substream, |
| 405 | struct snd_pcm_hw_params *hw_params) |
| 406 | { |
| 407 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 408 | int err; |
| 409 | |
| 410 | err = oxygen_hw_params(substream, hw_params); |
| 411 | if (err < 0) |
| 412 | return err; |
| 413 | |
| 414 | spin_lock_irq(&chip->reg_lock); |
| 415 | oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, |
| 416 | oxygen_format(hw_params) << OXYGEN_REC_FORMAT_C_SHIFT, |
| 417 | OXYGEN_REC_FORMAT_C_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 418 | spin_unlock_irq(&chip->reg_lock); |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream, |
| 423 | struct snd_pcm_hw_params *hw_params) |
| 424 | { |
| 425 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 426 | int err; |
| 427 | |
| 428 | err = oxygen_hw_params(substream, hw_params); |
| 429 | if (err < 0) |
| 430 | return err; |
| 431 | |
| 432 | spin_lock_irq(&chip->reg_lock); |
| 433 | oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, |
| 434 | OXYGEN_SPDIF_OUT_ENABLE); |
| 435 | oxygen_write8_masked(chip, OXYGEN_PLAY_FORMAT, |
| 436 | oxygen_format(hw_params) << OXYGEN_SPDIF_FORMAT_SHIFT, |
| 437 | OXYGEN_SPDIF_FORMAT_MASK); |
| 438 | oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL, |
| 439 | oxygen_rate(hw_params) << OXYGEN_SPDIF_OUT_RATE_SHIFT, |
| 440 | OXYGEN_SPDIF_OUT_RATE_MASK); |
| 441 | oxygen_update_spdif_source(chip); |
| 442 | spin_unlock_irq(&chip->reg_lock); |
| 443 | return 0; |
| 444 | } |
| 445 | |
| 446 | static int oxygen_multich_hw_params(struct snd_pcm_substream *substream, |
| 447 | struct snd_pcm_hw_params *hw_params) |
| 448 | { |
| 449 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 450 | int err; |
| 451 | |
| 452 | err = oxygen_hw_params(substream, hw_params); |
| 453 | if (err < 0) |
| 454 | return err; |
| 455 | |
| 456 | spin_lock_irq(&chip->reg_lock); |
| 457 | oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS, |
| 458 | oxygen_play_channels(hw_params), |
| 459 | OXYGEN_PLAY_CHANNELS_MASK); |
| 460 | oxygen_write8_masked(chip, OXYGEN_PLAY_FORMAT, |
| 461 | oxygen_format(hw_params) << OXYGEN_MULTICH_FORMAT_SHIFT, |
| 462 | OXYGEN_MULTICH_FORMAT_MASK); |
| 463 | oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 464 | oxygen_rate(hw_params) | |
| 465 | chip->model->dac_i2s_format | |
| 466 | oxygen_i2s_bits(hw_params), |
| 467 | OXYGEN_I2S_RATE_MASK | |
| 468 | OXYGEN_I2S_FORMAT_MASK | |
| 469 | OXYGEN_I2S_BITS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 470 | oxygen_update_dac_routing(chip); |
| 471 | oxygen_update_spdif_source(chip); |
| 472 | spin_unlock_irq(&chip->reg_lock); |
| 473 | |
| 474 | mutex_lock(&chip->mutex); |
| 475 | chip->model->set_dac_params(chip, hw_params); |
| 476 | mutex_unlock(&chip->mutex); |
| 477 | return 0; |
| 478 | } |
| 479 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 480 | static int oxygen_hw_free(struct snd_pcm_substream *substream) |
| 481 | { |
| 482 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 483 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 484 | |
| 485 | spin_lock_irq(&chip->reg_lock); |
| 486 | chip->interrupt_mask &= ~(1 << channel); |
| 487 | oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); |
| 488 | spin_unlock_irq(&chip->reg_lock); |
| 489 | |
| 490 | return snd_pcm_lib_free_pages(substream); |
| 491 | } |
| 492 | |
| 493 | static int oxygen_spdif_hw_free(struct snd_pcm_substream *substream) |
| 494 | { |
| 495 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 496 | |
| 497 | spin_lock_irq(&chip->reg_lock); |
| 498 | oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, |
| 499 | OXYGEN_SPDIF_OUT_ENABLE); |
| 500 | spin_unlock_irq(&chip->reg_lock); |
| 501 | return oxygen_hw_free(substream); |
| 502 | } |
| 503 | |
| 504 | static int oxygen_prepare(struct snd_pcm_substream *substream) |
| 505 | { |
| 506 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 507 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 508 | unsigned int channel_mask = 1 << channel; |
| 509 | |
| 510 | spin_lock_irq(&chip->reg_lock); |
| 511 | oxygen_set_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask); |
| 512 | oxygen_clear_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask); |
| 513 | |
| 514 | chip->interrupt_mask |= channel_mask; |
| 515 | oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); |
| 516 | spin_unlock_irq(&chip->reg_lock); |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static int oxygen_trigger(struct snd_pcm_substream *substream, int cmd) |
| 521 | { |
| 522 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 523 | struct snd_pcm_substream *s; |
| 524 | unsigned int mask = 0; |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 525 | int pausing; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 526 | |
| 527 | switch (cmd) { |
| 528 | case SNDRV_PCM_TRIGGER_STOP: |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 529 | case SNDRV_PCM_TRIGGER_START: |
Clemens Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 530 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 531 | pausing = 0; |
| 532 | break; |
| 533 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 534 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 535 | pausing = 1; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 536 | break; |
| 537 | default: |
| 538 | return -EINVAL; |
| 539 | } |
| 540 | |
| 541 | snd_pcm_group_for_each_entry(s, substream) { |
| 542 | if (snd_pcm_substream_chip(s) == chip) { |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 543 | mask |= 1 << oxygen_substream_channel(s); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 544 | snd_pcm_trigger_done(s, substream); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | spin_lock(&chip->reg_lock); |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 549 | if (!pausing) { |
| 550 | if (cmd == SNDRV_PCM_TRIGGER_START) |
| 551 | chip->pcm_running |= mask; |
| 552 | else |
| 553 | chip->pcm_running &= ~mask; |
| 554 | oxygen_write8(chip, OXYGEN_DMA_STATUS, chip->pcm_running); |
| 555 | } else { |
| 556 | if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) |
| 557 | oxygen_set_bits8(chip, OXYGEN_DMA_PAUSE, mask); |
| 558 | else |
| 559 | oxygen_clear_bits8(chip, OXYGEN_DMA_PAUSE, mask); |
| 560 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 561 | spin_unlock(&chip->reg_lock); |
| 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | static snd_pcm_uframes_t oxygen_pointer(struct snd_pcm_substream *substream) |
| 566 | { |
| 567 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 568 | struct snd_pcm_runtime *runtime = substream->runtime; |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 569 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 570 | u32 curr_addr; |
| 571 | |
| 572 | /* no spinlock, this read should be atomic */ |
| 573 | curr_addr = oxygen_read32(chip, channel_base_registers[channel]); |
| 574 | return bytes_to_frames(runtime, curr_addr - (u32)runtime->dma_addr); |
| 575 | } |
| 576 | |
| 577 | static struct snd_pcm_ops oxygen_rec_a_ops = { |
| 578 | .open = oxygen_rec_a_open, |
| 579 | .close = oxygen_close, |
| 580 | .ioctl = snd_pcm_lib_ioctl, |
| 581 | .hw_params = oxygen_rec_a_hw_params, |
| 582 | .hw_free = oxygen_hw_free, |
| 583 | .prepare = oxygen_prepare, |
| 584 | .trigger = oxygen_trigger, |
| 585 | .pointer = oxygen_pointer, |
| 586 | }; |
| 587 | |
| 588 | static struct snd_pcm_ops oxygen_rec_b_ops = { |
| 589 | .open = oxygen_rec_b_open, |
| 590 | .close = oxygen_close, |
| 591 | .ioctl = snd_pcm_lib_ioctl, |
| 592 | .hw_params = oxygen_rec_b_hw_params, |
| 593 | .hw_free = oxygen_hw_free, |
| 594 | .prepare = oxygen_prepare, |
| 595 | .trigger = oxygen_trigger, |
| 596 | .pointer = oxygen_pointer, |
| 597 | }; |
| 598 | |
| 599 | static struct snd_pcm_ops oxygen_rec_c_ops = { |
| 600 | .open = oxygen_rec_c_open, |
| 601 | .close = oxygen_close, |
| 602 | .ioctl = snd_pcm_lib_ioctl, |
| 603 | .hw_params = oxygen_rec_c_hw_params, |
| 604 | .hw_free = oxygen_hw_free, |
| 605 | .prepare = oxygen_prepare, |
| 606 | .trigger = oxygen_trigger, |
| 607 | .pointer = oxygen_pointer, |
| 608 | }; |
| 609 | |
| 610 | static struct snd_pcm_ops oxygen_spdif_ops = { |
| 611 | .open = oxygen_spdif_open, |
| 612 | .close = oxygen_close, |
| 613 | .ioctl = snd_pcm_lib_ioctl, |
| 614 | .hw_params = oxygen_spdif_hw_params, |
| 615 | .hw_free = oxygen_spdif_hw_free, |
| 616 | .prepare = oxygen_prepare, |
| 617 | .trigger = oxygen_trigger, |
| 618 | .pointer = oxygen_pointer, |
| 619 | }; |
| 620 | |
| 621 | static struct snd_pcm_ops oxygen_multich_ops = { |
| 622 | .open = oxygen_multich_open, |
| 623 | .close = oxygen_close, |
| 624 | .ioctl = snd_pcm_lib_ioctl, |
| 625 | .hw_params = oxygen_multich_hw_params, |
| 626 | .hw_free = oxygen_hw_free, |
| 627 | .prepare = oxygen_prepare, |
| 628 | .trigger = oxygen_trigger, |
| 629 | .pointer = oxygen_pointer, |
| 630 | }; |
| 631 | |
| 632 | static struct snd_pcm_ops oxygen_ac97_ops = { |
| 633 | .open = oxygen_ac97_open, |
| 634 | .close = oxygen_close, |
| 635 | .ioctl = snd_pcm_lib_ioctl, |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 636 | .hw_params = oxygen_hw_params, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 637 | .hw_free = oxygen_hw_free, |
| 638 | .prepare = oxygen_prepare, |
| 639 | .trigger = oxygen_trigger, |
| 640 | .pointer = oxygen_pointer, |
| 641 | }; |
| 642 | |
| 643 | static void oxygen_pcm_free(struct snd_pcm *pcm) |
| 644 | { |
| 645 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 646 | } |
| 647 | |
Takashi Iwai | f007dc0 | 2008-02-22 18:35:22 +0100 | [diff] [blame] | 648 | int oxygen_pcm_init(struct oxygen *chip) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 649 | { |
| 650 | struct snd_pcm *pcm; |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 651 | int outs, ins; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 652 | int err; |
| 653 | |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 654 | outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_0_TO_I2S); |
| 655 | ins = !!(chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_1 | |
| 656 | CAPTURE_0_FROM_I2S_2)); |
| 657 | if (outs | ins) { |
| 658 | err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm); |
| 659 | if (err < 0) |
| 660 | return err; |
| 661 | if (outs) |
| 662 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 663 | &oxygen_multich_ops); |
| 664 | if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1) |
| 665 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 666 | &oxygen_rec_a_ops); |
| 667 | else if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_2) |
| 668 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 669 | &oxygen_rec_b_ops); |
| 670 | pcm->private_data = chip; |
| 671 | pcm->private_free = oxygen_pcm_free; |
| 672 | strcpy(pcm->name, "Analog"); |
| 673 | if (outs) |
| 674 | snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, |
| 675 | SNDRV_DMA_TYPE_DEV, |
| 676 | snd_dma_pci_data(chip->pci), |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 677 | DEFAULT_BUFFER_BYTES_MULTICH, |
| 678 | BUFFER_BYTES_MAX_MULTICH); |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 679 | if (ins) |
| 680 | snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, |
| 681 | SNDRV_DMA_TYPE_DEV, |
| 682 | snd_dma_pci_data(chip->pci), |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 683 | DEFAULT_BUFFER_BYTES, |
| 684 | BUFFER_BYTES_MAX); |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 685 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 686 | |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 687 | outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF); |
| 688 | ins = !!(chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF); |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 689 | if (outs | ins) { |
| 690 | err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 691 | if (err < 0) |
| 692 | return err; |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 693 | if (outs) |
| 694 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 695 | &oxygen_spdif_ops); |
| 696 | if (ins) |
| 697 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 698 | &oxygen_rec_c_ops); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 699 | pcm->private_data = chip; |
| 700 | pcm->private_free = oxygen_pcm_free; |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 701 | strcpy(pcm->name, "Digital"); |
| 702 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 703 | snd_dma_pci_data(chip->pci), |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 704 | DEFAULT_BUFFER_BYTES, |
| 705 | BUFFER_BYTES_MAX); |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 708 | if (chip->has_ac97_1) { |
| 709 | outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_2_TO_AC97_1); |
| 710 | ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1); |
| 711 | } else { |
| 712 | outs = 0; |
| 713 | ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_I2S_2); |
| 714 | } |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 715 | if (outs | ins) { |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 716 | err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2", |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 717 | 2, outs, ins, &pcm); |
| 718 | if (err < 0) |
| 719 | return err; |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 720 | if (outs) { |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 721 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 722 | &oxygen_ac97_ops); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 723 | oxygen_write8_masked(chip, OXYGEN_REC_ROUTING, |
| 724 | OXYGEN_REC_B_ROUTE_AC97_1, |
| 725 | OXYGEN_REC_B_ROUTE_MASK); |
| 726 | } |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 727 | if (ins) |
| 728 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 729 | &oxygen_rec_b_ops); |
| 730 | pcm->private_data = chip; |
| 731 | pcm->private_free = oxygen_pcm_free; |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 732 | strcpy(pcm->name, outs ? "Front Panel" : "Analog 2"); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 733 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 734 | snd_dma_pci_data(chip->pci), |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame^] | 735 | DEFAULT_BUFFER_BYTES, |
| 736 | BUFFER_BYTES_MAX); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 737 | } |
| 738 | return 0; |
| 739 | } |