Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Driver for audio on multifunction CS5535 companion device |
| 3 | * Copyright (C) Jaya Kumar |
| 4 | * |
| 5 | * Based on Jaroslav Kysela and Takashi Iwai's examples. |
| 6 | * This work was sponsored by CIS(M) Sdn Bhd. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * todo: add be fmt support, spdif, pm |
| 23 | */ |
| 24 | |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/pci.h> |
| 28 | #include <sound/driver.h> |
| 29 | #include <sound/core.h> |
| 30 | #include <sound/control.h> |
| 31 | #include <sound/initval.h> |
| 32 | #include <sound/asoundef.h> |
| 33 | #include <sound/pcm.h> |
| 34 | #include <sound/pcm_params.h> |
| 35 | #include <sound/ac97_codec.h> |
| 36 | #include "cs5535audio.h" |
| 37 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 38 | static struct snd_pcm_hardware snd_cs5535audio_playback = |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 39 | { |
| 40 | .info = ( |
| 41 | SNDRV_PCM_INFO_MMAP | |
| 42 | SNDRV_PCM_INFO_INTERLEAVED | |
| 43 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 44 | SNDRV_PCM_INFO_MMAP_VALID | |
| 45 | SNDRV_PCM_INFO_PAUSE | |
| 46 | SNDRV_PCM_INFO_SYNC_START |
| 47 | ), |
| 48 | .formats = ( |
| 49 | SNDRV_PCM_FMTBIT_S16_LE |
| 50 | ), |
| 51 | .rates = ( |
| 52 | SNDRV_PCM_RATE_CONTINUOUS | |
| 53 | SNDRV_PCM_RATE_8000_48000 |
| 54 | ), |
| 55 | .rate_min = 4000, |
| 56 | .rate_max = 48000, |
| 57 | .channels_min = 2, |
| 58 | .channels_max = 2, |
| 59 | .buffer_bytes_max = (128*1024), |
| 60 | .period_bytes_min = 64, |
| 61 | .period_bytes_max = (64*1024 - 16), |
| 62 | .periods_min = 1, |
| 63 | .periods_max = CS5535AUDIO_MAX_DESCRIPTORS, |
| 64 | .fifo_size = 0, |
| 65 | }; |
| 66 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 67 | static struct snd_pcm_hardware snd_cs5535audio_capture = |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 68 | { |
| 69 | .info = ( |
| 70 | SNDRV_PCM_INFO_MMAP | |
| 71 | SNDRV_PCM_INFO_INTERLEAVED | |
| 72 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 73 | SNDRV_PCM_INFO_MMAP_VALID | |
| 74 | SNDRV_PCM_INFO_SYNC_START |
| 75 | ), |
| 76 | .formats = ( |
| 77 | SNDRV_PCM_FMTBIT_S16_LE |
| 78 | ), |
| 79 | .rates = ( |
| 80 | SNDRV_PCM_RATE_CONTINUOUS | |
| 81 | SNDRV_PCM_RATE_8000_48000 |
| 82 | ), |
| 83 | .rate_min = 4000, |
| 84 | .rate_max = 48000, |
| 85 | .channels_min = 2, |
| 86 | .channels_max = 2, |
| 87 | .buffer_bytes_max = (128*1024), |
| 88 | .period_bytes_min = 64, |
| 89 | .period_bytes_max = (64*1024 - 16), |
| 90 | .periods_min = 1, |
| 91 | .periods_max = CS5535AUDIO_MAX_DESCRIPTORS, |
| 92 | .fifo_size = 0, |
| 93 | }; |
| 94 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 95 | static int snd_cs5535audio_playback_open(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 96 | { |
| 97 | int err; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 98 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 99 | struct snd_pcm_runtime *runtime = substream->runtime; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 100 | |
| 101 | runtime->hw = snd_cs5535audio_playback; |
| 102 | cs5535au->playback_substream = substream; |
| 103 | runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK]); |
| 104 | snd_pcm_set_sync(substream); |
| 105 | if ((err = snd_pcm_hw_constraint_integer(runtime, |
| 106 | SNDRV_PCM_HW_PARAM_PERIODS)) < 0) |
| 107 | return err; |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 112 | static int snd_cs5535audio_playback_close(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 113 | { |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | #define CS5535AUDIO_DESC_LIST_SIZE \ |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 118 | PAGE_ALIGN(CS5535AUDIO_MAX_DESCRIPTORS * sizeof(struct cs5535audio_dma_desc)) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 119 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 120 | static int cs5535audio_build_dma_packets(struct cs5535audio *cs5535au, |
| 121 | struct cs5535audio_dma *dma, |
| 122 | struct snd_pcm_substream *substream, |
| 123 | unsigned int periods, |
| 124 | unsigned int period_bytes) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 125 | { |
| 126 | unsigned int i; |
| 127 | u32 addr, desc_addr, jmpprd_addr; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 128 | struct cs5535audio_dma_desc *lastdesc; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 129 | |
| 130 | if (periods > CS5535AUDIO_MAX_DESCRIPTORS) |
| 131 | return -ENOMEM; |
| 132 | |
| 133 | if (dma->desc_buf.area == NULL) { |
| 134 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, |
| 135 | snd_dma_pci_data(cs5535au->pci), |
| 136 | CS5535AUDIO_DESC_LIST_SIZE+1, |
| 137 | &dma->desc_buf) < 0) |
| 138 | return -ENOMEM; |
| 139 | dma->period_bytes = dma->periods = 0; |
| 140 | } |
| 141 | |
| 142 | if (dma->periods == periods && dma->period_bytes == period_bytes) |
| 143 | return 0; |
| 144 | |
| 145 | /* the u32 cast is okay because in snd*create we succesfully told |
| 146 | pci alloc that we're only 32 bit capable so the uppper will be 0 */ |
| 147 | addr = (u32) substream->runtime->dma_addr; |
| 148 | desc_addr = (u32) dma->desc_buf.addr; |
| 149 | for (i = 0; i < periods; i++) { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 150 | struct cs5535audio_dma_desc *desc = |
| 151 | &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[i]; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 152 | desc->addr = cpu_to_le32(addr); |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 153 | desc->size = cpu_to_le32(period_bytes); |
| 154 | desc->ctlreserved = cpu_to_le32(PRD_EOP); |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 155 | desc_addr += sizeof(struct cs5535audio_dma_desc); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 156 | addr += period_bytes; |
| 157 | } |
| 158 | /* we reserved one dummy descriptor at the end to do the PRD jump */ |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 159 | lastdesc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[periods]; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 160 | lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr); |
| 161 | lastdesc->size = 0; |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 162 | lastdesc->ctlreserved = cpu_to_le32(PRD_JMP); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 163 | jmpprd_addr = cpu_to_le32(lastdesc->addr + |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 164 | (sizeof(struct cs5535audio_dma_desc)*periods)); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 165 | |
| 166 | dma->period_bytes = period_bytes; |
| 167 | dma->periods = periods; |
| 168 | spin_lock_irq(&cs5535au->reg_lock); |
| 169 | dma->ops->disable_dma(cs5535au); |
| 170 | dma->ops->setup_prd(cs5535au, jmpprd_addr); |
| 171 | spin_unlock_irq(&cs5535au->reg_lock); |
| 172 | return 0; |
| 173 | } |
| 174 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 175 | static void cs5535audio_playback_enable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 176 | { |
| 177 | cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_EN); |
| 178 | } |
| 179 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 180 | static void cs5535audio_playback_disable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 181 | { |
| 182 | cs_writeb(cs5535au, ACC_BM0_CMD, 0); |
| 183 | } |
| 184 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 185 | static void cs5535audio_playback_pause_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 186 | { |
| 187 | cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_PAUSE); |
| 188 | } |
| 189 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 190 | static void cs5535audio_playback_setup_prd(struct cs5535audio *cs5535au, |
| 191 | u32 prd_addr) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 192 | { |
| 193 | cs_writel(cs5535au, ACC_BM0_PRD, prd_addr); |
| 194 | } |
| 195 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 196 | static u32 cs5535audio_playback_read_dma_pntr(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 197 | { |
| 198 | return cs_readl(cs5535au, ACC_BM0_PNTR); |
| 199 | } |
| 200 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 201 | static void cs5535audio_capture_enable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 202 | { |
| 203 | cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_EN); |
| 204 | } |
| 205 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 206 | static void cs5535audio_capture_disable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 207 | { |
| 208 | cs_writeb(cs5535au, ACC_BM1_CMD, 0); |
| 209 | } |
| 210 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 211 | static void cs5535audio_capture_pause_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 212 | { |
| 213 | cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_PAUSE); |
| 214 | } |
| 215 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 216 | static void cs5535audio_capture_setup_prd(struct cs5535audio *cs5535au, |
| 217 | u32 prd_addr) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 218 | { |
| 219 | cs_writel(cs5535au, ACC_BM1_PRD, prd_addr); |
| 220 | } |
| 221 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 222 | static u32 cs5535audio_capture_read_dma_pntr(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 223 | { |
| 224 | return cs_readl(cs5535au, ACC_BM1_PNTR); |
| 225 | } |
| 226 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 227 | static void cs5535audio_clear_dma_packets(struct cs5535audio *cs5535au, |
| 228 | struct cs5535audio_dma *dma, |
| 229 | struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 230 | { |
| 231 | snd_dma_free_pages(&dma->desc_buf); |
| 232 | dma->desc_buf.area = NULL; |
| 233 | } |
| 234 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 235 | static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream, |
| 236 | struct snd_pcm_hw_params *hw_params) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 237 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 238 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 239 | struct cs5535audio_dma *dma = substream->runtime->private_data; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 240 | int err; |
| 241 | |
| 242 | err = snd_pcm_lib_malloc_pages(substream, |
| 243 | params_buffer_bytes(hw_params)); |
| 244 | if (err < 0) |
| 245 | return err; |
| 246 | dma->buf_addr = substream->runtime->dma_addr; |
| 247 | dma->buf_bytes = params_buffer_bytes(hw_params); |
| 248 | |
| 249 | err = cs5535audio_build_dma_packets(cs5535au, dma, substream, |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 250 | params_periods(hw_params), |
| 251 | params_period_bytes(hw_params)); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 252 | return err; |
| 253 | } |
| 254 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 255 | static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 256 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 257 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 258 | struct cs5535audio_dma *dma = substream->runtime->private_data; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 259 | |
| 260 | cs5535audio_clear_dma_packets(cs5535au, dma, substream); |
| 261 | return snd_pcm_lib_free_pages(substream); |
| 262 | } |
| 263 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 264 | static int snd_cs5535audio_playback_prepare(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 265 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 266 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 267 | return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE, |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 268 | substream->runtime->rate); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 269 | } |
| 270 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 271 | static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 272 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 273 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 274 | struct cs5535audio_dma *dma = substream->runtime->private_data; |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 275 | int err = 0; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 276 | |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 277 | spin_lock(&cs5535au->reg_lock); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 278 | switch (cmd) { |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 279 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 280 | dma->ops->pause_dma(cs5535au); |
| 281 | break; |
| 282 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 283 | dma->ops->enable_dma(cs5535au); |
| 284 | break; |
| 285 | case SNDRV_PCM_TRIGGER_START: |
| 286 | dma->ops->enable_dma(cs5535au); |
| 287 | break; |
| 288 | case SNDRV_PCM_TRIGGER_STOP: |
| 289 | dma->ops->disable_dma(cs5535au); |
| 290 | break; |
| 291 | default: |
| 292 | snd_printk(KERN_ERR "unhandled trigger\n"); |
| 293 | err = -EINVAL; |
| 294 | break; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 295 | } |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 296 | spin_unlock(&cs5535au->reg_lock); |
| 297 | return err; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 298 | } |
| 299 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 300 | static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 301 | *substream) |
| 302 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 303 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 304 | u32 curdma; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 305 | struct cs5535audio_dma *dma; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 306 | |
| 307 | dma = substream->runtime->private_data; |
| 308 | curdma = dma->ops->read_dma_pntr(cs5535au); |
| 309 | if (curdma < dma->buf_addr) { |
| 310 | snd_printk(KERN_ERR "curdma=%x < %x bufaddr.\n", |
| 311 | curdma, dma->buf_addr); |
| 312 | return 0; |
| 313 | } |
| 314 | curdma -= dma->buf_addr; |
| 315 | if (curdma >= dma->buf_bytes) { |
| 316 | snd_printk(KERN_ERR "diff=%x >= %x buf_bytes.\n", |
| 317 | curdma, dma->buf_bytes); |
| 318 | return 0; |
| 319 | } |
| 320 | return bytes_to_frames(substream->runtime, curdma); |
| 321 | } |
| 322 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 323 | static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 324 | { |
| 325 | int err; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 326 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 327 | struct snd_pcm_runtime *runtime = substream->runtime; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 328 | |
| 329 | runtime->hw = snd_cs5535audio_capture; |
| 330 | cs5535au->capture_substream = substream; |
| 331 | runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE]); |
| 332 | snd_pcm_set_sync(substream); |
| 333 | if ((err = snd_pcm_hw_constraint_integer(runtime, |
| 334 | SNDRV_PCM_HW_PARAM_PERIODS)) < 0) |
| 335 | return err; |
| 336 | return 0; |
| 337 | } |
| 338 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 339 | static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 340 | { |
| 341 | return 0; |
| 342 | } |
| 343 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 344 | static int snd_cs5535audio_capture_prepare(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 345 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 346 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 347 | return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_LR_ADC_RATE, |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 348 | substream->runtime->rate); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 349 | } |
| 350 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 351 | static struct snd_pcm_ops snd_cs5535audio_playback_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 352 | .open = snd_cs5535audio_playback_open, |
| 353 | .close = snd_cs5535audio_playback_close, |
| 354 | .ioctl = snd_pcm_lib_ioctl, |
| 355 | .hw_params = snd_cs5535audio_hw_params, |
| 356 | .hw_free = snd_cs5535audio_hw_free, |
| 357 | .prepare = snd_cs5535audio_playback_prepare, |
| 358 | .trigger = snd_cs5535audio_trigger, |
| 359 | .pointer = snd_cs5535audio_pcm_pointer, |
| 360 | }; |
| 361 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 362 | static struct snd_pcm_ops snd_cs5535audio_capture_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 363 | .open = snd_cs5535audio_capture_open, |
| 364 | .close = snd_cs5535audio_capture_close, |
| 365 | .ioctl = snd_pcm_lib_ioctl, |
| 366 | .hw_params = snd_cs5535audio_hw_params, |
| 367 | .hw_free = snd_cs5535audio_hw_free, |
| 368 | .prepare = snd_cs5535audio_capture_prepare, |
| 369 | .trigger = snd_cs5535audio_trigger, |
| 370 | .pointer = snd_cs5535audio_pcm_pointer, |
| 371 | }; |
| 372 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 373 | static struct cs5535audio_dma_ops snd_cs5535audio_playback_dma_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 374 | .type = CS5535AUDIO_DMA_PLAYBACK, |
| 375 | .enable_dma = cs5535audio_playback_enable_dma, |
| 376 | .disable_dma = cs5535audio_playback_disable_dma, |
| 377 | .setup_prd = cs5535audio_playback_setup_prd, |
| 378 | .pause_dma = cs5535audio_playback_pause_dma, |
| 379 | .read_dma_pntr = cs5535audio_playback_read_dma_pntr, |
| 380 | }; |
| 381 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 382 | static struct cs5535audio_dma_ops snd_cs5535audio_capture_dma_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 383 | .type = CS5535AUDIO_DMA_CAPTURE, |
| 384 | .enable_dma = cs5535audio_capture_enable_dma, |
| 385 | .disable_dma = cs5535audio_capture_disable_dma, |
| 386 | .setup_prd = cs5535audio_capture_setup_prd, |
| 387 | .pause_dma = cs5535audio_capture_pause_dma, |
| 388 | .read_dma_pntr = cs5535audio_capture_read_dma_pntr, |
| 389 | }; |
| 390 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 391 | int __devinit snd_cs5535audio_pcm(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 392 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 393 | struct snd_pcm *pcm; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 394 | int err; |
| 395 | |
| 396 | err = snd_pcm_new(cs5535au->card, "CS5535 Audio", 0, 1, 1, &pcm); |
| 397 | if (err < 0) |
| 398 | return err; |
| 399 | |
| 400 | cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK].ops = |
| 401 | &snd_cs5535audio_playback_dma_ops; |
| 402 | cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE].ops = |
| 403 | &snd_cs5535audio_capture_dma_ops; |
| 404 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 405 | &snd_cs5535audio_playback_ops); |
| 406 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 407 | &snd_cs5535audio_capture_ops); |
| 408 | |
| 409 | pcm->private_data = cs5535au; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 410 | pcm->info_flags = 0; |
| 411 | strcpy(pcm->name, "CS5535 Audio"); |
| 412 | |
| 413 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 414 | snd_dma_pci_data(cs5535au->pci), |
| 415 | 64*1024, 128*1024); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |