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 | } |
Clemens Ladisch | ca1f30a | 2008-05-13 09:26:01 +0200 | [diff] [blame] | 168 | if (channel == PCM_MULTICH) { |
| 169 | err = snd_pcm_hw_constraint_minmax |
| 170 | (runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 0, 8192000); |
| 171 | if (err < 0) |
| 172 | return err; |
| 173 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 174 | snd_pcm_set_sync(substream); |
| 175 | chip->streams[channel] = substream; |
| 176 | |
| 177 | mutex_lock(&chip->mutex); |
| 178 | chip->pcm_active |= 1 << channel; |
| 179 | if (channel == PCM_SPDIF) { |
| 180 | chip->spdif_pcm_bits = chip->spdif_bits; |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 181 | chip->controls[CONTROL_SPDIF_PCM]->vd[0].access &= |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 182 | ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 183 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 184 | SNDRV_CTL_EVENT_MASK_INFO, |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 185 | &chip->controls[CONTROL_SPDIF_PCM]->id); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 186 | } |
| 187 | mutex_unlock(&chip->mutex); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static int oxygen_rec_a_open(struct snd_pcm_substream *substream) |
| 193 | { |
| 194 | return oxygen_open(substream, PCM_A); |
| 195 | } |
| 196 | |
| 197 | static int oxygen_rec_b_open(struct snd_pcm_substream *substream) |
| 198 | { |
| 199 | return oxygen_open(substream, PCM_B); |
| 200 | } |
| 201 | |
| 202 | static int oxygen_rec_c_open(struct snd_pcm_substream *substream) |
| 203 | { |
| 204 | return oxygen_open(substream, PCM_C); |
| 205 | } |
| 206 | |
| 207 | static int oxygen_spdif_open(struct snd_pcm_substream *substream) |
| 208 | { |
| 209 | return oxygen_open(substream, PCM_SPDIF); |
| 210 | } |
| 211 | |
| 212 | static int oxygen_multich_open(struct snd_pcm_substream *substream) |
| 213 | { |
| 214 | return oxygen_open(substream, PCM_MULTICH); |
| 215 | } |
| 216 | |
| 217 | static int oxygen_ac97_open(struct snd_pcm_substream *substream) |
| 218 | { |
| 219 | return oxygen_open(substream, PCM_AC97); |
| 220 | } |
| 221 | |
| 222 | static int oxygen_close(struct snd_pcm_substream *substream) |
| 223 | { |
| 224 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 225 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 226 | |
| 227 | mutex_lock(&chip->mutex); |
| 228 | chip->pcm_active &= ~(1 << channel); |
| 229 | if (channel == PCM_SPDIF) { |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 230 | chip->controls[CONTROL_SPDIF_PCM]->vd[0].access |= |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 231 | SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 232 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 233 | SNDRV_CTL_EVENT_MASK_INFO, |
Clemens Ladisch | 01a3aff | 2008-01-14 08:56:01 +0100 | [diff] [blame] | 234 | &chip->controls[CONTROL_SPDIF_PCM]->id); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 235 | } |
| 236 | if (channel == PCM_SPDIF || channel == PCM_MULTICH) |
| 237 | oxygen_update_spdif_source(chip); |
| 238 | mutex_unlock(&chip->mutex); |
| 239 | |
| 240 | chip->streams[channel] = NULL; |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | static unsigned int oxygen_format(struct snd_pcm_hw_params *hw_params) |
| 245 | { |
| 246 | if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE) |
| 247 | return OXYGEN_FORMAT_24; |
| 248 | else |
| 249 | return OXYGEN_FORMAT_16; |
| 250 | } |
| 251 | |
| 252 | static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params) |
| 253 | { |
| 254 | switch (params_rate(hw_params)) { |
| 255 | case 32000: |
| 256 | return OXYGEN_RATE_32000; |
| 257 | case 44100: |
| 258 | return OXYGEN_RATE_44100; |
| 259 | default: /* 48000 */ |
| 260 | return OXYGEN_RATE_48000; |
| 261 | case 64000: |
| 262 | return OXYGEN_RATE_64000; |
| 263 | case 88200: |
| 264 | return OXYGEN_RATE_88200; |
| 265 | case 96000: |
| 266 | return OXYGEN_RATE_96000; |
| 267 | case 176400: |
| 268 | return OXYGEN_RATE_176400; |
| 269 | case 192000: |
| 270 | return OXYGEN_RATE_192000; |
| 271 | } |
| 272 | } |
| 273 | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 274 | 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] | 275 | { |
Clemens Ladisch | b78e3db | 2008-01-25 08:39:26 +0100 | [diff] [blame] | 276 | if (params_rate(hw_params) <= 96000) |
| 277 | return OXYGEN_I2S_MCLK_256; |
| 278 | else |
| 279 | return OXYGEN_I2S_MCLK_128; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 282 | 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] | 283 | { |
| 284 | if (params_format(hw_params) == SNDRV_PCM_FORMAT_S32_LE) |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 285 | return OXYGEN_I2S_BITS_24; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 286 | else |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 287 | return OXYGEN_I2S_BITS_16; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static unsigned int oxygen_play_channels(struct snd_pcm_hw_params *hw_params) |
| 291 | { |
| 292 | switch (params_channels(hw_params)) { |
| 293 | default: /* 2 */ |
| 294 | return OXYGEN_PLAY_CHANNELS_2; |
| 295 | case 4: |
| 296 | return OXYGEN_PLAY_CHANNELS_4; |
| 297 | case 6: |
| 298 | return OXYGEN_PLAY_CHANNELS_6; |
| 299 | case 8: |
| 300 | return OXYGEN_PLAY_CHANNELS_8; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | static const unsigned int channel_base_registers[PCM_COUNT] = { |
| 305 | [PCM_A] = OXYGEN_DMA_A_ADDRESS, |
| 306 | [PCM_B] = OXYGEN_DMA_B_ADDRESS, |
| 307 | [PCM_C] = OXYGEN_DMA_C_ADDRESS, |
| 308 | [PCM_SPDIF] = OXYGEN_DMA_SPDIF_ADDRESS, |
| 309 | [PCM_MULTICH] = OXYGEN_DMA_MULTICH_ADDRESS, |
| 310 | [PCM_AC97] = OXYGEN_DMA_AC97_ADDRESS, |
| 311 | }; |
| 312 | |
| 313 | static int oxygen_hw_params(struct snd_pcm_substream *substream, |
| 314 | struct snd_pcm_hw_params *hw_params) |
| 315 | { |
| 316 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 317 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 318 | int err; |
| 319 | |
| 320 | err = snd_pcm_lib_malloc_pages(substream, |
| 321 | params_buffer_bytes(hw_params)); |
| 322 | if (err < 0) |
| 323 | return err; |
| 324 | |
| 325 | oxygen_write32(chip, channel_base_registers[channel], |
| 326 | (u32)substream->runtime->dma_addr); |
| 327 | if (channel == PCM_MULTICH) { |
| 328 | oxygen_write32(chip, OXYGEN_DMA_MULTICH_COUNT, |
| 329 | params_buffer_bytes(hw_params) / 4 - 1); |
| 330 | oxygen_write32(chip, OXYGEN_DMA_MULTICH_TCOUNT, |
| 331 | params_period_bytes(hw_params) / 4 - 1); |
| 332 | } else { |
| 333 | oxygen_write16(chip, channel_base_registers[channel] + 4, |
| 334 | params_buffer_bytes(hw_params) / 4 - 1); |
| 335 | oxygen_write16(chip, channel_base_registers[channel] + 6, |
| 336 | params_period_bytes(hw_params) / 4 - 1); |
| 337 | } |
| 338 | return 0; |
| 339 | } |
| 340 | |
| 341 | static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream, |
| 342 | struct snd_pcm_hw_params *hw_params) |
| 343 | { |
| 344 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 345 | int err; |
| 346 | |
| 347 | err = oxygen_hw_params(substream, hw_params); |
| 348 | if (err < 0) |
| 349 | return err; |
| 350 | |
| 351 | spin_lock_irq(&chip->reg_lock); |
| 352 | oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, |
| 353 | oxygen_format(hw_params) << OXYGEN_REC_FORMAT_A_SHIFT, |
| 354 | OXYGEN_REC_FORMAT_A_MASK); |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 355 | oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT, |
| 356 | oxygen_rate(hw_params) | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 357 | oxygen_i2s_mclk(hw_params) | |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 358 | chip->model->adc_i2s_format | |
| 359 | oxygen_i2s_bits(hw_params), |
| 360 | OXYGEN_I2S_RATE_MASK | |
| 361 | OXYGEN_I2S_FORMAT_MASK | |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 362 | OXYGEN_I2S_MCLK_MASK | |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 363 | OXYGEN_I2S_BITS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 364 | spin_unlock_irq(&chip->reg_lock); |
| 365 | |
| 366 | mutex_lock(&chip->mutex); |
| 367 | chip->model->set_adc_params(chip, hw_params); |
| 368 | mutex_unlock(&chip->mutex); |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream, |
| 373 | struct snd_pcm_hw_params *hw_params) |
| 374 | { |
| 375 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 376 | int is_ac97; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 377 | int err; |
| 378 | |
| 379 | err = oxygen_hw_params(substream, hw_params); |
| 380 | if (err < 0) |
| 381 | return err; |
| 382 | |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 383 | is_ac97 = chip->has_ac97_1 && |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 384 | (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 385 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 386 | spin_lock_irq(&chip->reg_lock); |
| 387 | oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, |
| 388 | oxygen_format(hw_params) << OXYGEN_REC_FORMAT_B_SHIFT, |
| 389 | OXYGEN_REC_FORMAT_B_MASK); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 390 | if (!is_ac97) |
| 391 | oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT, |
| 392 | oxygen_rate(hw_params) | |
| 393 | oxygen_i2s_mclk(hw_params) | |
| 394 | chip->model->adc_i2s_format | |
| 395 | oxygen_i2s_bits(hw_params), |
| 396 | OXYGEN_I2S_RATE_MASK | |
| 397 | OXYGEN_I2S_FORMAT_MASK | |
| 398 | OXYGEN_I2S_MCLK_MASK | |
| 399 | OXYGEN_I2S_BITS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 400 | spin_unlock_irq(&chip->reg_lock); |
| 401 | |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 402 | if (!is_ac97) { |
| 403 | mutex_lock(&chip->mutex); |
| 404 | chip->model->set_adc_params(chip, hw_params); |
| 405 | mutex_unlock(&chip->mutex); |
| 406 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
| 410 | static int oxygen_rec_c_hw_params(struct snd_pcm_substream *substream, |
| 411 | struct snd_pcm_hw_params *hw_params) |
| 412 | { |
| 413 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 414 | int err; |
| 415 | |
| 416 | err = oxygen_hw_params(substream, hw_params); |
| 417 | if (err < 0) |
| 418 | return err; |
| 419 | |
| 420 | spin_lock_irq(&chip->reg_lock); |
| 421 | oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, |
| 422 | oxygen_format(hw_params) << OXYGEN_REC_FORMAT_C_SHIFT, |
| 423 | OXYGEN_REC_FORMAT_C_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 424 | spin_unlock_irq(&chip->reg_lock); |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream, |
| 429 | struct snd_pcm_hw_params *hw_params) |
| 430 | { |
| 431 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 432 | int err; |
| 433 | |
| 434 | err = oxygen_hw_params(substream, hw_params); |
| 435 | if (err < 0) |
| 436 | return err; |
| 437 | |
| 438 | spin_lock_irq(&chip->reg_lock); |
| 439 | oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, |
| 440 | OXYGEN_SPDIF_OUT_ENABLE); |
| 441 | oxygen_write8_masked(chip, OXYGEN_PLAY_FORMAT, |
| 442 | oxygen_format(hw_params) << OXYGEN_SPDIF_FORMAT_SHIFT, |
| 443 | OXYGEN_SPDIF_FORMAT_MASK); |
| 444 | oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL, |
| 445 | oxygen_rate(hw_params) << OXYGEN_SPDIF_OUT_RATE_SHIFT, |
| 446 | OXYGEN_SPDIF_OUT_RATE_MASK); |
| 447 | oxygen_update_spdif_source(chip); |
| 448 | spin_unlock_irq(&chip->reg_lock); |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int oxygen_multich_hw_params(struct snd_pcm_substream *substream, |
| 453 | struct snd_pcm_hw_params *hw_params) |
| 454 | { |
| 455 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 456 | int err; |
| 457 | |
| 458 | err = oxygen_hw_params(substream, hw_params); |
| 459 | if (err < 0) |
| 460 | return err; |
| 461 | |
| 462 | spin_lock_irq(&chip->reg_lock); |
| 463 | oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS, |
| 464 | oxygen_play_channels(hw_params), |
| 465 | OXYGEN_PLAY_CHANNELS_MASK); |
| 466 | oxygen_write8_masked(chip, OXYGEN_PLAY_FORMAT, |
| 467 | oxygen_format(hw_params) << OXYGEN_MULTICH_FORMAT_SHIFT, |
| 468 | OXYGEN_MULTICH_FORMAT_MASK); |
| 469 | oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT, |
Clemens Ladisch | 05855ba | 2008-01-17 09:05:09 +0100 | [diff] [blame] | 470 | oxygen_rate(hw_params) | |
| 471 | chip->model->dac_i2s_format | |
| 472 | oxygen_i2s_bits(hw_params), |
| 473 | OXYGEN_I2S_RATE_MASK | |
| 474 | OXYGEN_I2S_FORMAT_MASK | |
| 475 | OXYGEN_I2S_BITS_MASK); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 476 | oxygen_update_dac_routing(chip); |
| 477 | oxygen_update_spdif_source(chip); |
| 478 | spin_unlock_irq(&chip->reg_lock); |
| 479 | |
| 480 | mutex_lock(&chip->mutex); |
| 481 | chip->model->set_dac_params(chip, hw_params); |
| 482 | mutex_unlock(&chip->mutex); |
| 483 | return 0; |
| 484 | } |
| 485 | |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 486 | static int oxygen_hw_free(struct snd_pcm_substream *substream) |
| 487 | { |
| 488 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 489 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 490 | |
| 491 | spin_lock_irq(&chip->reg_lock); |
| 492 | chip->interrupt_mask &= ~(1 << channel); |
| 493 | oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); |
| 494 | spin_unlock_irq(&chip->reg_lock); |
| 495 | |
| 496 | return snd_pcm_lib_free_pages(substream); |
| 497 | } |
| 498 | |
| 499 | static int oxygen_spdif_hw_free(struct snd_pcm_substream *substream) |
| 500 | { |
| 501 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 502 | |
| 503 | spin_lock_irq(&chip->reg_lock); |
| 504 | oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL, |
| 505 | OXYGEN_SPDIF_OUT_ENABLE); |
| 506 | spin_unlock_irq(&chip->reg_lock); |
| 507 | return oxygen_hw_free(substream); |
| 508 | } |
| 509 | |
| 510 | static int oxygen_prepare(struct snd_pcm_substream *substream) |
| 511 | { |
| 512 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 513 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 514 | unsigned int channel_mask = 1 << channel; |
| 515 | |
| 516 | spin_lock_irq(&chip->reg_lock); |
| 517 | oxygen_set_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask); |
| 518 | oxygen_clear_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask); |
| 519 | |
| 520 | chip->interrupt_mask |= channel_mask; |
| 521 | oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); |
| 522 | spin_unlock_irq(&chip->reg_lock); |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | static int oxygen_trigger(struct snd_pcm_substream *substream, int cmd) |
| 527 | { |
| 528 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 529 | struct snd_pcm_substream *s; |
| 530 | unsigned int mask = 0; |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 531 | int pausing; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 532 | |
| 533 | switch (cmd) { |
| 534 | case SNDRV_PCM_TRIGGER_STOP: |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 535 | case SNDRV_PCM_TRIGGER_START: |
Clemens Ladisch | 4a4bc53 | 2008-05-13 09:24:39 +0200 | [diff] [blame] | 536 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 537 | pausing = 0; |
| 538 | break; |
| 539 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 540 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 541 | pausing = 1; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 542 | break; |
| 543 | default: |
| 544 | return -EINVAL; |
| 545 | } |
| 546 | |
| 547 | snd_pcm_group_for_each_entry(s, substream) { |
| 548 | if (snd_pcm_substream_chip(s) == chip) { |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 549 | mask |= 1 << oxygen_substream_channel(s); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 550 | snd_pcm_trigger_done(s, substream); |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | spin_lock(&chip->reg_lock); |
Clemens Ladisch | db2396d | 2008-01-21 08:44:52 +0100 | [diff] [blame] | 555 | if (!pausing) { |
| 556 | if (cmd == SNDRV_PCM_TRIGGER_START) |
| 557 | chip->pcm_running |= mask; |
| 558 | else |
| 559 | chip->pcm_running &= ~mask; |
| 560 | oxygen_write8(chip, OXYGEN_DMA_STATUS, chip->pcm_running); |
| 561 | } else { |
| 562 | if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) |
| 563 | oxygen_set_bits8(chip, OXYGEN_DMA_PAUSE, mask); |
| 564 | else |
| 565 | oxygen_clear_bits8(chip, OXYGEN_DMA_PAUSE, mask); |
| 566 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 567 | spin_unlock(&chip->reg_lock); |
| 568 | return 0; |
| 569 | } |
| 570 | |
| 571 | static snd_pcm_uframes_t oxygen_pointer(struct snd_pcm_substream *substream) |
| 572 | { |
| 573 | struct oxygen *chip = snd_pcm_substream_chip(substream); |
| 574 | struct snd_pcm_runtime *runtime = substream->runtime; |
Clemens Ladisch | 740eb83 | 2008-01-04 09:22:20 +0100 | [diff] [blame] | 575 | unsigned int channel = oxygen_substream_channel(substream); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 576 | u32 curr_addr; |
| 577 | |
| 578 | /* no spinlock, this read should be atomic */ |
| 579 | curr_addr = oxygen_read32(chip, channel_base_registers[channel]); |
| 580 | return bytes_to_frames(runtime, curr_addr - (u32)runtime->dma_addr); |
| 581 | } |
| 582 | |
| 583 | static struct snd_pcm_ops oxygen_rec_a_ops = { |
| 584 | .open = oxygen_rec_a_open, |
| 585 | .close = oxygen_close, |
| 586 | .ioctl = snd_pcm_lib_ioctl, |
| 587 | .hw_params = oxygen_rec_a_hw_params, |
| 588 | .hw_free = oxygen_hw_free, |
| 589 | .prepare = oxygen_prepare, |
| 590 | .trigger = oxygen_trigger, |
| 591 | .pointer = oxygen_pointer, |
| 592 | }; |
| 593 | |
| 594 | static struct snd_pcm_ops oxygen_rec_b_ops = { |
| 595 | .open = oxygen_rec_b_open, |
| 596 | .close = oxygen_close, |
| 597 | .ioctl = snd_pcm_lib_ioctl, |
| 598 | .hw_params = oxygen_rec_b_hw_params, |
| 599 | .hw_free = oxygen_hw_free, |
| 600 | .prepare = oxygen_prepare, |
| 601 | .trigger = oxygen_trigger, |
| 602 | .pointer = oxygen_pointer, |
| 603 | }; |
| 604 | |
| 605 | static struct snd_pcm_ops oxygen_rec_c_ops = { |
| 606 | .open = oxygen_rec_c_open, |
| 607 | .close = oxygen_close, |
| 608 | .ioctl = snd_pcm_lib_ioctl, |
| 609 | .hw_params = oxygen_rec_c_hw_params, |
| 610 | .hw_free = oxygen_hw_free, |
| 611 | .prepare = oxygen_prepare, |
| 612 | .trigger = oxygen_trigger, |
| 613 | .pointer = oxygen_pointer, |
| 614 | }; |
| 615 | |
| 616 | static struct snd_pcm_ops oxygen_spdif_ops = { |
| 617 | .open = oxygen_spdif_open, |
| 618 | .close = oxygen_close, |
| 619 | .ioctl = snd_pcm_lib_ioctl, |
| 620 | .hw_params = oxygen_spdif_hw_params, |
| 621 | .hw_free = oxygen_spdif_hw_free, |
| 622 | .prepare = oxygen_prepare, |
| 623 | .trigger = oxygen_trigger, |
| 624 | .pointer = oxygen_pointer, |
| 625 | }; |
| 626 | |
| 627 | static struct snd_pcm_ops oxygen_multich_ops = { |
| 628 | .open = oxygen_multich_open, |
| 629 | .close = oxygen_close, |
| 630 | .ioctl = snd_pcm_lib_ioctl, |
| 631 | .hw_params = oxygen_multich_hw_params, |
| 632 | .hw_free = oxygen_hw_free, |
| 633 | .prepare = oxygen_prepare, |
| 634 | .trigger = oxygen_trigger, |
| 635 | .pointer = oxygen_pointer, |
| 636 | }; |
| 637 | |
| 638 | static struct snd_pcm_ops oxygen_ac97_ops = { |
| 639 | .open = oxygen_ac97_open, |
| 640 | .close = oxygen_close, |
| 641 | .ioctl = snd_pcm_lib_ioctl, |
Clemens Ladisch | c2353a0 | 2008-01-18 09:17:53 +0100 | [diff] [blame] | 642 | .hw_params = oxygen_hw_params, |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 643 | .hw_free = oxygen_hw_free, |
| 644 | .prepare = oxygen_prepare, |
| 645 | .trigger = oxygen_trigger, |
| 646 | .pointer = oxygen_pointer, |
| 647 | }; |
| 648 | |
| 649 | static void oxygen_pcm_free(struct snd_pcm *pcm) |
| 650 | { |
| 651 | snd_pcm_lib_preallocate_free_for_all(pcm); |
| 652 | } |
| 653 | |
Takashi Iwai | f007dc0 | 2008-02-22 18:35:22 +0100 | [diff] [blame] | 654 | int oxygen_pcm_init(struct oxygen *chip) |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 655 | { |
| 656 | struct snd_pcm *pcm; |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 657 | int outs, ins; |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 658 | int err; |
| 659 | |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 660 | outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_0_TO_I2S); |
| 661 | ins = !!(chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_1 | |
| 662 | CAPTURE_0_FROM_I2S_2)); |
| 663 | if (outs | ins) { |
| 664 | err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm); |
| 665 | if (err < 0) |
| 666 | return err; |
| 667 | if (outs) |
| 668 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 669 | &oxygen_multich_ops); |
| 670 | if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1) |
| 671 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 672 | &oxygen_rec_a_ops); |
| 673 | else if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_2) |
| 674 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 675 | &oxygen_rec_b_ops); |
| 676 | pcm->private_data = chip; |
| 677 | pcm->private_free = oxygen_pcm_free; |
| 678 | strcpy(pcm->name, "Analog"); |
| 679 | if (outs) |
| 680 | snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].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_MULTICH, |
| 684 | BUFFER_BYTES_MAX_MULTICH); |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 685 | if (ins) |
| 686 | snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, |
| 687 | SNDRV_DMA_TYPE_DEV, |
| 688 | snd_dma_pci_data(chip->pci), |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame] | 689 | DEFAULT_BUFFER_BYTES, |
| 690 | BUFFER_BYTES_MAX); |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 691 | } |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 692 | |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 693 | outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF); |
| 694 | ins = !!(chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF); |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 695 | if (outs | ins) { |
| 696 | err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 697 | if (err < 0) |
| 698 | return err; |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 699 | if (outs) |
| 700 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 701 | &oxygen_spdif_ops); |
| 702 | if (ins) |
| 703 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 704 | &oxygen_rec_c_ops); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 705 | pcm->private_data = chip; |
| 706 | pcm->private_free = oxygen_pcm_free; |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 707 | strcpy(pcm->name, "Digital"); |
| 708 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 709 | snd_dma_pci_data(chip->pci), |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame] | 710 | DEFAULT_BUFFER_BYTES, |
| 711 | BUFFER_BYTES_MAX); |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Clemens Ladisch | f009ad9 | 2008-03-19 08:19:41 +0100 | [diff] [blame] | 714 | if (chip->has_ac97_1) { |
| 715 | outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_2_TO_AC97_1); |
| 716 | ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1); |
| 717 | } else { |
| 718 | outs = 0; |
| 719 | ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_I2S_2); |
| 720 | } |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 721 | if (outs | ins) { |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 722 | err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2", |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 723 | 2, outs, ins, &pcm); |
| 724 | if (err < 0) |
| 725 | return err; |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 726 | if (outs) { |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 727 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 728 | &oxygen_ac97_ops); |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 729 | oxygen_write8_masked(chip, OXYGEN_REC_ROUTING, |
| 730 | OXYGEN_REC_B_ROUTE_AC97_1, |
| 731 | OXYGEN_REC_B_ROUTE_MASK); |
| 732 | } |
Clemens Ladisch | e85e092 | 2008-01-16 08:30:38 +0100 | [diff] [blame] | 733 | if (ins) |
| 734 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 735 | &oxygen_rec_b_ops); |
| 736 | pcm->private_data = chip; |
| 737 | pcm->private_free = oxygen_pcm_free; |
Clemens Ladisch | 5f7b9b4 | 2008-01-28 08:35:47 +0100 | [diff] [blame] | 738 | strcpy(pcm->name, outs ? "Front Panel" : "Analog 2"); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 739 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 740 | snd_dma_pci_data(chip->pci), |
Clemens Ladisch | d55d7a1 | 2008-05-13 09:25:39 +0200 | [diff] [blame] | 741 | DEFAULT_BUFFER_BYTES, |
| 742 | BUFFER_BYTES_MAX); |
Clemens Ladisch | d0ce994 | 2007-12-23 19:50:57 +0100 | [diff] [blame] | 743 | } |
| 744 | return 0; |
| 745 | } |