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