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 | |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 46 | SNDRV_PCM_INFO_RESUME |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 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 | |
Clemens Ladisch | b83f346 | 2007-08-13 17:37:55 +0200 | [diff] [blame^] | 73 | SNDRV_PCM_INFO_MMAP_VALID |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 74 | ), |
| 75 | .formats = ( |
| 76 | SNDRV_PCM_FMTBIT_S16_LE |
| 77 | ), |
| 78 | .rates = ( |
| 79 | SNDRV_PCM_RATE_CONTINUOUS | |
| 80 | SNDRV_PCM_RATE_8000_48000 |
| 81 | ), |
| 82 | .rate_min = 4000, |
| 83 | .rate_max = 48000, |
| 84 | .channels_min = 2, |
| 85 | .channels_max = 2, |
| 86 | .buffer_bytes_max = (128*1024), |
| 87 | .period_bytes_min = 64, |
| 88 | .period_bytes_max = (64*1024 - 16), |
| 89 | .periods_min = 1, |
| 90 | .periods_max = CS5535AUDIO_MAX_DESCRIPTORS, |
| 91 | .fifo_size = 0, |
| 92 | }; |
| 93 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 94 | static int snd_cs5535audio_playback_open(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 95 | { |
| 96 | int err; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 97 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 98 | struct snd_pcm_runtime *runtime = substream->runtime; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 99 | |
| 100 | runtime->hw = snd_cs5535audio_playback; |
| 101 | cs5535au->playback_substream = substream; |
| 102 | runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK]); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 103 | if ((err = snd_pcm_hw_constraint_integer(runtime, |
| 104 | SNDRV_PCM_HW_PARAM_PERIODS)) < 0) |
| 105 | return err; |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 110 | static int snd_cs5535audio_playback_close(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | #define CS5535AUDIO_DESC_LIST_SIZE \ |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 116 | PAGE_ALIGN(CS5535AUDIO_MAX_DESCRIPTORS * sizeof(struct cs5535audio_dma_desc)) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 117 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 118 | static int cs5535audio_build_dma_packets(struct cs5535audio *cs5535au, |
| 119 | struct cs5535audio_dma *dma, |
| 120 | struct snd_pcm_substream *substream, |
| 121 | unsigned int periods, |
| 122 | unsigned int period_bytes) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 123 | { |
| 124 | unsigned int i; |
| 125 | u32 addr, desc_addr, jmpprd_addr; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 126 | struct cs5535audio_dma_desc *lastdesc; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 127 | |
| 128 | if (periods > CS5535AUDIO_MAX_DESCRIPTORS) |
| 129 | return -ENOMEM; |
| 130 | |
| 131 | if (dma->desc_buf.area == NULL) { |
| 132 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, |
| 133 | snd_dma_pci_data(cs5535au->pci), |
| 134 | CS5535AUDIO_DESC_LIST_SIZE+1, |
| 135 | &dma->desc_buf) < 0) |
| 136 | return -ENOMEM; |
| 137 | dma->period_bytes = dma->periods = 0; |
| 138 | } |
| 139 | |
| 140 | if (dma->periods == periods && dma->period_bytes == period_bytes) |
| 141 | return 0; |
| 142 | |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 143 | /* the u32 cast is okay because in snd*create we successfully told |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 144 | pci alloc that we're only 32 bit capable so the uppper will be 0 */ |
| 145 | addr = (u32) substream->runtime->dma_addr; |
| 146 | desc_addr = (u32) dma->desc_buf.addr; |
| 147 | for (i = 0; i < periods; i++) { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 148 | struct cs5535audio_dma_desc *desc = |
| 149 | &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[i]; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 150 | desc->addr = cpu_to_le32(addr); |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 151 | desc->size = cpu_to_le32(period_bytes); |
| 152 | desc->ctlreserved = cpu_to_le32(PRD_EOP); |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 153 | desc_addr += sizeof(struct cs5535audio_dma_desc); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 154 | addr += period_bytes; |
| 155 | } |
| 156 | /* 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] | 157 | lastdesc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[periods]; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 158 | lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr); |
| 159 | lastdesc->size = 0; |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 160 | lastdesc->ctlreserved = cpu_to_le32(PRD_JMP); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 161 | jmpprd_addr = cpu_to_le32(lastdesc->addr + |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 162 | (sizeof(struct cs5535audio_dma_desc)*periods)); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 163 | |
| 164 | dma->period_bytes = period_bytes; |
| 165 | dma->periods = periods; |
| 166 | spin_lock_irq(&cs5535au->reg_lock); |
| 167 | dma->ops->disable_dma(cs5535au); |
| 168 | dma->ops->setup_prd(cs5535au, jmpprd_addr); |
| 169 | spin_unlock_irq(&cs5535au->reg_lock); |
| 170 | return 0; |
| 171 | } |
| 172 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 173 | static void cs5535audio_playback_enable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 174 | { |
| 175 | cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_EN); |
| 176 | } |
| 177 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 178 | static void cs5535audio_playback_disable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 179 | { |
| 180 | cs_writeb(cs5535au, ACC_BM0_CMD, 0); |
| 181 | } |
| 182 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 183 | static void cs5535audio_playback_pause_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 184 | { |
| 185 | cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_PAUSE); |
| 186 | } |
| 187 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 188 | static void cs5535audio_playback_setup_prd(struct cs5535audio *cs5535au, |
| 189 | u32 prd_addr) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 190 | { |
| 191 | cs_writel(cs5535au, ACC_BM0_PRD, prd_addr); |
| 192 | } |
| 193 | |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 194 | static u32 cs5535audio_playback_read_prd(struct cs5535audio *cs5535au) |
| 195 | { |
| 196 | return cs_readl(cs5535au, ACC_BM0_PRD); |
| 197 | } |
| 198 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 199 | static u32 cs5535audio_playback_read_dma_pntr(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 200 | { |
| 201 | return cs_readl(cs5535au, ACC_BM0_PNTR); |
| 202 | } |
| 203 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 204 | static void cs5535audio_capture_enable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 205 | { |
| 206 | cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_EN); |
| 207 | } |
| 208 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 209 | static void cs5535audio_capture_disable_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 210 | { |
| 211 | cs_writeb(cs5535au, ACC_BM1_CMD, 0); |
| 212 | } |
| 213 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 214 | static void cs5535audio_capture_pause_dma(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 215 | { |
| 216 | cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_PAUSE); |
| 217 | } |
| 218 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 219 | static void cs5535audio_capture_setup_prd(struct cs5535audio *cs5535au, |
| 220 | u32 prd_addr) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 221 | { |
| 222 | cs_writel(cs5535au, ACC_BM1_PRD, prd_addr); |
| 223 | } |
| 224 | |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 225 | static u32 cs5535audio_capture_read_prd(struct cs5535audio *cs5535au) |
| 226 | { |
| 227 | return cs_readl(cs5535au, ACC_BM1_PRD); |
| 228 | } |
| 229 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 230 | static u32 cs5535audio_capture_read_dma_pntr(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 231 | { |
| 232 | return cs_readl(cs5535au, ACC_BM1_PNTR); |
| 233 | } |
| 234 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 235 | static void cs5535audio_clear_dma_packets(struct cs5535audio *cs5535au, |
| 236 | struct cs5535audio_dma *dma, |
| 237 | struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 238 | { |
| 239 | snd_dma_free_pages(&dma->desc_buf); |
| 240 | dma->desc_buf.area = NULL; |
| 241 | } |
| 242 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 243 | static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream, |
| 244 | struct snd_pcm_hw_params *hw_params) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 245 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 246 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 247 | struct cs5535audio_dma *dma = substream->runtime->private_data; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 248 | int err; |
| 249 | |
| 250 | err = snd_pcm_lib_malloc_pages(substream, |
| 251 | params_buffer_bytes(hw_params)); |
| 252 | if (err < 0) |
| 253 | return err; |
| 254 | dma->buf_addr = substream->runtime->dma_addr; |
| 255 | dma->buf_bytes = params_buffer_bytes(hw_params); |
| 256 | |
| 257 | err = cs5535audio_build_dma_packets(cs5535au, dma, substream, |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 258 | params_periods(hw_params), |
| 259 | params_period_bytes(hw_params)); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 260 | return err; |
| 261 | } |
| 262 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 263 | static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 264 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 265 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 266 | struct cs5535audio_dma *dma = substream->runtime->private_data; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 267 | |
| 268 | cs5535audio_clear_dma_packets(cs5535au, dma, substream); |
| 269 | return snd_pcm_lib_free_pages(substream); |
| 270 | } |
| 271 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 272 | static int snd_cs5535audio_playback_prepare(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 273 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 274 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 275 | return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE, |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 276 | substream->runtime->rate); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 279 | static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 280 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 281 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 282 | struct cs5535audio_dma *dma = substream->runtime->private_data; |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 283 | int err = 0; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 284 | |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 285 | spin_lock(&cs5535au->reg_lock); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 286 | switch (cmd) { |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 287 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 288 | dma->ops->pause_dma(cs5535au); |
| 289 | break; |
| 290 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 291 | dma->ops->enable_dma(cs5535au); |
| 292 | break; |
| 293 | case SNDRV_PCM_TRIGGER_START: |
| 294 | dma->ops->enable_dma(cs5535au); |
| 295 | break; |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 296 | case SNDRV_PCM_TRIGGER_RESUME: |
| 297 | dma->ops->enable_dma(cs5535au); |
| 298 | dma->suspended = 0; |
| 299 | break; |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 300 | case SNDRV_PCM_TRIGGER_STOP: |
| 301 | dma->ops->disable_dma(cs5535au); |
| 302 | break; |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 303 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 304 | dma->ops->disable_dma(cs5535au); |
| 305 | dma->suspended = 1; |
| 306 | break; |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 307 | default: |
| 308 | snd_printk(KERN_ERR "unhandled trigger\n"); |
| 309 | err = -EINVAL; |
| 310 | break; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 311 | } |
Takashi Iwai | 3e87317 | 2005-11-17 10:15:37 +0100 | [diff] [blame] | 312 | spin_unlock(&cs5535au->reg_lock); |
| 313 | return err; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 314 | } |
| 315 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 316 | 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] | 317 | *substream) |
| 318 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 319 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 320 | u32 curdma; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 321 | struct cs5535audio_dma *dma; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 322 | |
| 323 | dma = substream->runtime->private_data; |
| 324 | curdma = dma->ops->read_dma_pntr(cs5535au); |
| 325 | if (curdma < dma->buf_addr) { |
| 326 | snd_printk(KERN_ERR "curdma=%x < %x bufaddr.\n", |
| 327 | curdma, dma->buf_addr); |
| 328 | return 0; |
| 329 | } |
| 330 | curdma -= dma->buf_addr; |
| 331 | if (curdma >= dma->buf_bytes) { |
| 332 | snd_printk(KERN_ERR "diff=%x >= %x buf_bytes.\n", |
| 333 | curdma, dma->buf_bytes); |
| 334 | return 0; |
| 335 | } |
| 336 | return bytes_to_frames(substream->runtime, curdma); |
| 337 | } |
| 338 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 339 | static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 340 | { |
| 341 | int err; |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 342 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
| 343 | struct snd_pcm_runtime *runtime = substream->runtime; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 344 | |
| 345 | runtime->hw = snd_cs5535audio_capture; |
| 346 | cs5535au->capture_substream = substream; |
| 347 | runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE]); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 348 | if ((err = snd_pcm_hw_constraint_integer(runtime, |
| 349 | SNDRV_PCM_HW_PARAM_PERIODS)) < 0) |
| 350 | return err; |
| 351 | return 0; |
| 352 | } |
| 353 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 354 | static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 355 | { |
| 356 | return 0; |
| 357 | } |
| 358 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 359 | static int snd_cs5535audio_capture_prepare(struct snd_pcm_substream *substream) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 360 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 361 | struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 362 | return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_LR_ADC_RATE, |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 363 | substream->runtime->rate); |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 366 | static struct snd_pcm_ops snd_cs5535audio_playback_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 367 | .open = snd_cs5535audio_playback_open, |
| 368 | .close = snd_cs5535audio_playback_close, |
| 369 | .ioctl = snd_pcm_lib_ioctl, |
| 370 | .hw_params = snd_cs5535audio_hw_params, |
| 371 | .hw_free = snd_cs5535audio_hw_free, |
| 372 | .prepare = snd_cs5535audio_playback_prepare, |
| 373 | .trigger = snd_cs5535audio_trigger, |
| 374 | .pointer = snd_cs5535audio_pcm_pointer, |
| 375 | }; |
| 376 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 377 | static struct snd_pcm_ops snd_cs5535audio_capture_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 378 | .open = snd_cs5535audio_capture_open, |
| 379 | .close = snd_cs5535audio_capture_close, |
| 380 | .ioctl = snd_pcm_lib_ioctl, |
| 381 | .hw_params = snd_cs5535audio_hw_params, |
| 382 | .hw_free = snd_cs5535audio_hw_free, |
| 383 | .prepare = snd_cs5535audio_capture_prepare, |
| 384 | .trigger = snd_cs5535audio_trigger, |
| 385 | .pointer = snd_cs5535audio_pcm_pointer, |
| 386 | }; |
| 387 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 388 | static struct cs5535audio_dma_ops snd_cs5535audio_playback_dma_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 389 | .type = CS5535AUDIO_DMA_PLAYBACK, |
| 390 | .enable_dma = cs5535audio_playback_enable_dma, |
| 391 | .disable_dma = cs5535audio_playback_disable_dma, |
| 392 | .setup_prd = cs5535audio_playback_setup_prd, |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 393 | .read_prd = cs5535audio_playback_read_prd, |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 394 | .pause_dma = cs5535audio_playback_pause_dma, |
| 395 | .read_dma_pntr = cs5535audio_playback_read_dma_pntr, |
| 396 | }; |
| 397 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 398 | static struct cs5535audio_dma_ops snd_cs5535audio_capture_dma_ops = { |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 399 | .type = CS5535AUDIO_DMA_CAPTURE, |
| 400 | .enable_dma = cs5535audio_capture_enable_dma, |
| 401 | .disable_dma = cs5535audio_capture_disable_dma, |
| 402 | .setup_prd = cs5535audio_capture_setup_prd, |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 403 | .read_prd = cs5535audio_capture_read_prd, |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 404 | .pause_dma = cs5535audio_capture_pause_dma, |
| 405 | .read_dma_pntr = cs5535audio_capture_read_dma_pntr, |
| 406 | }; |
| 407 | |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 408 | int __devinit snd_cs5535audio_pcm(struct cs5535audio *cs5535au) |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 409 | { |
Takashi Iwai | 66f8df6 | 2005-11-17 14:56:21 +0100 | [diff] [blame] | 410 | struct snd_pcm *pcm; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 411 | int err; |
| 412 | |
| 413 | err = snd_pcm_new(cs5535au->card, "CS5535 Audio", 0, 1, 1, &pcm); |
| 414 | if (err < 0) |
| 415 | return err; |
| 416 | |
| 417 | cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK].ops = |
| 418 | &snd_cs5535audio_playback_dma_ops; |
| 419 | cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE].ops = |
| 420 | &snd_cs5535audio_capture_dma_ops; |
| 421 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 422 | &snd_cs5535audio_playback_ops); |
| 423 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 424 | &snd_cs5535audio_capture_ops); |
| 425 | |
| 426 | pcm->private_data = cs5535au; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 427 | pcm->info_flags = 0; |
| 428 | strcpy(pcm->name, "CS5535 Audio"); |
| 429 | |
| 430 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 431 | snd_dma_pci_data(cs5535au->pci), |
| 432 | 64*1024, 128*1024); |
Jaya Kumar | 9ac2559 | 2006-04-28 14:34:49 +0200 | [diff] [blame] | 433 | cs5535au->pcm = pcm; |
Jaya Kumar | 9b4ffa4 | 2005-11-17 10:12:23 +0100 | [diff] [blame] | 434 | |
| 435 | return 0; |
| 436 | } |
| 437 | |