blob: 9a1e87fd481577d7d8d2ce97748354358cbbef5c [file] [log] [blame]
Jaya Kumar9b4ffa42005-11-17 10:12:23 +01001/*
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 Iwai66f8df62005-11-17 14:56:21 +010038static struct snd_pcm_hardware snd_cs5535audio_playback =
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010039{
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 Kumar9ac25592006-04-28 14:34:49 +020046 SNDRV_PCM_INFO_RESUME
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010047 ),
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 Iwai66f8df62005-11-17 14:56:21 +010067static struct snd_pcm_hardware snd_cs5535audio_capture =
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010068{
69 .info = (
70 SNDRV_PCM_INFO_MMAP |
71 SNDRV_PCM_INFO_INTERLEAVED |
72 SNDRV_PCM_INFO_BLOCK_TRANSFER |
Clemens Ladischb83f3462007-08-13 17:37:55 +020073 SNDRV_PCM_INFO_MMAP_VALID
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010074 ),
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 Iwai66f8df62005-11-17 14:56:21 +010094static int snd_cs5535audio_playback_open(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010095{
96 int err;
Takashi Iwai66f8df62005-11-17 14:56:21 +010097 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
98 struct snd_pcm_runtime *runtime = substream->runtime;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010099
100 runtime->hw = snd_cs5535audio_playback;
101 cs5535au->playback_substream = substream;
102 runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK]);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100103 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 Iwai66f8df62005-11-17 14:56:21 +0100110static int snd_cs5535audio_playback_close(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100111{
112 return 0;
113}
114
115#define CS5535AUDIO_DESC_LIST_SIZE \
Takashi Iwai66f8df62005-11-17 14:56:21 +0100116 PAGE_ALIGN(CS5535AUDIO_MAX_DESCRIPTORS * sizeof(struct cs5535audio_dma_desc))
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100117
Takashi Iwai66f8df62005-11-17 14:56:21 +0100118static 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 Kumar9b4ffa42005-11-17 10:12:23 +0100123{
124 unsigned int i;
125 u32 addr, desc_addr, jmpprd_addr;
Takashi Iwai66f8df62005-11-17 14:56:21 +0100126 struct cs5535audio_dma_desc *lastdesc;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100127
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 Mohrd6e05ed2006-06-26 18:35:02 +0200143 /* the u32 cast is okay because in snd*create we successfully told
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100144 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 Iwai66f8df62005-11-17 14:56:21 +0100148 struct cs5535audio_dma_desc *desc =
149 &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[i];
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100150 desc->addr = cpu_to_le32(addr);
Takashi Iwai3e873172005-11-17 10:15:37 +0100151 desc->size = cpu_to_le32(period_bytes);
152 desc->ctlreserved = cpu_to_le32(PRD_EOP);
Takashi Iwai66f8df62005-11-17 14:56:21 +0100153 desc_addr += sizeof(struct cs5535audio_dma_desc);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100154 addr += period_bytes;
155 }
156 /* we reserved one dummy descriptor at the end to do the PRD jump */
Takashi Iwai66f8df62005-11-17 14:56:21 +0100157 lastdesc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[periods];
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100158 lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr);
159 lastdesc->size = 0;
Takashi Iwai3e873172005-11-17 10:15:37 +0100160 lastdesc->ctlreserved = cpu_to_le32(PRD_JMP);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100161 jmpprd_addr = cpu_to_le32(lastdesc->addr +
Takashi Iwai66f8df62005-11-17 14:56:21 +0100162 (sizeof(struct cs5535audio_dma_desc)*periods));
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100163
Andres Salomon7abcacb2007-09-03 15:41:47 +0200164 dma->substream = substream;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100165 dma->period_bytes = period_bytes;
166 dma->periods = periods;
167 spin_lock_irq(&cs5535au->reg_lock);
168 dma->ops->disable_dma(cs5535au);
169 dma->ops->setup_prd(cs5535au, jmpprd_addr);
170 spin_unlock_irq(&cs5535au->reg_lock);
171 return 0;
172}
173
Takashi Iwai66f8df62005-11-17 14:56:21 +0100174static void cs5535audio_playback_enable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100175{
176 cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_EN);
177}
178
Takashi Iwai66f8df62005-11-17 14:56:21 +0100179static void cs5535audio_playback_disable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100180{
181 cs_writeb(cs5535au, ACC_BM0_CMD, 0);
182}
183
Takashi Iwai66f8df62005-11-17 14:56:21 +0100184static void cs5535audio_playback_pause_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100185{
186 cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_PAUSE);
187}
188
Takashi Iwai66f8df62005-11-17 14:56:21 +0100189static void cs5535audio_playback_setup_prd(struct cs5535audio *cs5535au,
190 u32 prd_addr)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100191{
192 cs_writel(cs5535au, ACC_BM0_PRD, prd_addr);
193}
194
Jaya Kumar9ac25592006-04-28 14:34:49 +0200195static u32 cs5535audio_playback_read_prd(struct cs5535audio *cs5535au)
196{
197 return cs_readl(cs5535au, ACC_BM0_PRD);
198}
199
Takashi Iwai66f8df62005-11-17 14:56:21 +0100200static u32 cs5535audio_playback_read_dma_pntr(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100201{
202 return cs_readl(cs5535au, ACC_BM0_PNTR);
203}
204
Takashi Iwai66f8df62005-11-17 14:56:21 +0100205static void cs5535audio_capture_enable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100206{
207 cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_EN);
208}
209
Takashi Iwai66f8df62005-11-17 14:56:21 +0100210static void cs5535audio_capture_disable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100211{
212 cs_writeb(cs5535au, ACC_BM1_CMD, 0);
213}
214
Takashi Iwai66f8df62005-11-17 14:56:21 +0100215static void cs5535audio_capture_pause_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100216{
217 cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_PAUSE);
218}
219
Takashi Iwai66f8df62005-11-17 14:56:21 +0100220static void cs5535audio_capture_setup_prd(struct cs5535audio *cs5535au,
221 u32 prd_addr)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100222{
223 cs_writel(cs5535au, ACC_BM1_PRD, prd_addr);
224}
225
Jaya Kumar9ac25592006-04-28 14:34:49 +0200226static u32 cs5535audio_capture_read_prd(struct cs5535audio *cs5535au)
227{
228 return cs_readl(cs5535au, ACC_BM1_PRD);
229}
230
Takashi Iwai66f8df62005-11-17 14:56:21 +0100231static u32 cs5535audio_capture_read_dma_pntr(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100232{
233 return cs_readl(cs5535au, ACC_BM1_PNTR);
234}
235
Takashi Iwai66f8df62005-11-17 14:56:21 +0100236static void cs5535audio_clear_dma_packets(struct cs5535audio *cs5535au,
237 struct cs5535audio_dma *dma,
238 struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100239{
240 snd_dma_free_pages(&dma->desc_buf);
241 dma->desc_buf.area = NULL;
Andres Salomon7abcacb2007-09-03 15:41:47 +0200242 dma->substream = NULL;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100243}
244
Takashi Iwai66f8df62005-11-17 14:56:21 +0100245static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream,
246 struct snd_pcm_hw_params *hw_params)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100247{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100248 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
249 struct cs5535audio_dma *dma = substream->runtime->private_data;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100250 int err;
251
252 err = snd_pcm_lib_malloc_pages(substream,
253 params_buffer_bytes(hw_params));
254 if (err < 0)
255 return err;
256 dma->buf_addr = substream->runtime->dma_addr;
257 dma->buf_bytes = params_buffer_bytes(hw_params);
258
259 err = cs5535audio_build_dma_packets(cs5535au, dma, substream,
Takashi Iwai66f8df62005-11-17 14:56:21 +0100260 params_periods(hw_params),
261 params_period_bytes(hw_params));
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100262 return err;
263}
264
Takashi Iwai66f8df62005-11-17 14:56:21 +0100265static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100266{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100267 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
268 struct cs5535audio_dma *dma = substream->runtime->private_data;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100269
270 cs5535audio_clear_dma_packets(cs5535au, dma, substream);
271 return snd_pcm_lib_free_pages(substream);
272}
273
Takashi Iwai66f8df62005-11-17 14:56:21 +0100274static int snd_cs5535audio_playback_prepare(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100275{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100276 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100277 return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE,
Takashi Iwai66f8df62005-11-17 14:56:21 +0100278 substream->runtime->rate);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100279}
280
Takashi Iwai66f8df62005-11-17 14:56:21 +0100281static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100282{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100283 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
284 struct cs5535audio_dma *dma = substream->runtime->private_data;
Takashi Iwai3e873172005-11-17 10:15:37 +0100285 int err = 0;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100286
Takashi Iwai3e873172005-11-17 10:15:37 +0100287 spin_lock(&cs5535au->reg_lock);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100288 switch (cmd) {
Takashi Iwai3e873172005-11-17 10:15:37 +0100289 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
290 dma->ops->pause_dma(cs5535au);
291 break;
292 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
293 dma->ops->enable_dma(cs5535au);
294 break;
295 case SNDRV_PCM_TRIGGER_START:
296 dma->ops->enable_dma(cs5535au);
297 break;
Jaya Kumar9ac25592006-04-28 14:34:49 +0200298 case SNDRV_PCM_TRIGGER_RESUME:
299 dma->ops->enable_dma(cs5535au);
300 dma->suspended = 0;
301 break;
Takashi Iwai3e873172005-11-17 10:15:37 +0100302 case SNDRV_PCM_TRIGGER_STOP:
303 dma->ops->disable_dma(cs5535au);
304 break;
Jaya Kumar9ac25592006-04-28 14:34:49 +0200305 case SNDRV_PCM_TRIGGER_SUSPEND:
306 dma->ops->disable_dma(cs5535au);
307 dma->suspended = 1;
308 break;
Takashi Iwai3e873172005-11-17 10:15:37 +0100309 default:
310 snd_printk(KERN_ERR "unhandled trigger\n");
311 err = -EINVAL;
312 break;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100313 }
Takashi Iwai3e873172005-11-17 10:15:37 +0100314 spin_unlock(&cs5535au->reg_lock);
315 return err;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100316}
317
Takashi Iwai66f8df62005-11-17 14:56:21 +0100318static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100319 *substream)
320{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100321 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100322 u32 curdma;
Takashi Iwai66f8df62005-11-17 14:56:21 +0100323 struct cs5535audio_dma *dma;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100324
325 dma = substream->runtime->private_data;
326 curdma = dma->ops->read_dma_pntr(cs5535au);
327 if (curdma < dma->buf_addr) {
328 snd_printk(KERN_ERR "curdma=%x < %x bufaddr.\n",
329 curdma, dma->buf_addr);
330 return 0;
331 }
332 curdma -= dma->buf_addr;
333 if (curdma >= dma->buf_bytes) {
334 snd_printk(KERN_ERR "diff=%x >= %x buf_bytes.\n",
335 curdma, dma->buf_bytes);
336 return 0;
337 }
338 return bytes_to_frames(substream->runtime, curdma);
339}
340
Takashi Iwai66f8df62005-11-17 14:56:21 +0100341static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100342{
343 int err;
Takashi Iwai66f8df62005-11-17 14:56:21 +0100344 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
345 struct snd_pcm_runtime *runtime = substream->runtime;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100346
347 runtime->hw = snd_cs5535audio_capture;
348 cs5535au->capture_substream = substream;
349 runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE]);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100350 if ((err = snd_pcm_hw_constraint_integer(runtime,
351 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
352 return err;
353 return 0;
354}
355
Takashi Iwai66f8df62005-11-17 14:56:21 +0100356static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100357{
358 return 0;
359}
360
Takashi Iwai66f8df62005-11-17 14:56:21 +0100361static int snd_cs5535audio_capture_prepare(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100362{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100363 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100364 return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_LR_ADC_RATE,
Takashi Iwai66f8df62005-11-17 14:56:21 +0100365 substream->runtime->rate);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100366}
367
Takashi Iwai66f8df62005-11-17 14:56:21 +0100368static struct snd_pcm_ops snd_cs5535audio_playback_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100369 .open = snd_cs5535audio_playback_open,
370 .close = snd_cs5535audio_playback_close,
371 .ioctl = snd_pcm_lib_ioctl,
372 .hw_params = snd_cs5535audio_hw_params,
373 .hw_free = snd_cs5535audio_hw_free,
374 .prepare = snd_cs5535audio_playback_prepare,
375 .trigger = snd_cs5535audio_trigger,
376 .pointer = snd_cs5535audio_pcm_pointer,
377};
378
Takashi Iwai66f8df62005-11-17 14:56:21 +0100379static struct snd_pcm_ops snd_cs5535audio_capture_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100380 .open = snd_cs5535audio_capture_open,
381 .close = snd_cs5535audio_capture_close,
382 .ioctl = snd_pcm_lib_ioctl,
383 .hw_params = snd_cs5535audio_hw_params,
384 .hw_free = snd_cs5535audio_hw_free,
385 .prepare = snd_cs5535audio_capture_prepare,
386 .trigger = snd_cs5535audio_trigger,
387 .pointer = snd_cs5535audio_pcm_pointer,
388};
389
Takashi Iwai66f8df62005-11-17 14:56:21 +0100390static struct cs5535audio_dma_ops snd_cs5535audio_playback_dma_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100391 .type = CS5535AUDIO_DMA_PLAYBACK,
392 .enable_dma = cs5535audio_playback_enable_dma,
393 .disable_dma = cs5535audio_playback_disable_dma,
394 .setup_prd = cs5535audio_playback_setup_prd,
Jaya Kumar9ac25592006-04-28 14:34:49 +0200395 .read_prd = cs5535audio_playback_read_prd,
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100396 .pause_dma = cs5535audio_playback_pause_dma,
397 .read_dma_pntr = cs5535audio_playback_read_dma_pntr,
398};
399
Takashi Iwai66f8df62005-11-17 14:56:21 +0100400static struct cs5535audio_dma_ops snd_cs5535audio_capture_dma_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100401 .type = CS5535AUDIO_DMA_CAPTURE,
402 .enable_dma = cs5535audio_capture_enable_dma,
403 .disable_dma = cs5535audio_capture_disable_dma,
404 .setup_prd = cs5535audio_capture_setup_prd,
Jaya Kumar9ac25592006-04-28 14:34:49 +0200405 .read_prd = cs5535audio_capture_read_prd,
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100406 .pause_dma = cs5535audio_capture_pause_dma,
407 .read_dma_pntr = cs5535audio_capture_read_dma_pntr,
408};
409
Takashi Iwai66f8df62005-11-17 14:56:21 +0100410int __devinit snd_cs5535audio_pcm(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100411{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100412 struct snd_pcm *pcm;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100413 int err;
414
415 err = snd_pcm_new(cs5535au->card, "CS5535 Audio", 0, 1, 1, &pcm);
416 if (err < 0)
417 return err;
418
419 cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK].ops =
420 &snd_cs5535audio_playback_dma_ops;
421 cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE].ops =
422 &snd_cs5535audio_capture_dma_ops;
423 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
424 &snd_cs5535audio_playback_ops);
425 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
426 &snd_cs5535audio_capture_ops);
427
428 pcm->private_data = cs5535au;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100429 pcm->info_flags = 0;
430 strcpy(pcm->name, "CS5535 Audio");
431
432 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
433 snd_dma_pci_data(cs5535au->pci),
434 64*1024, 128*1024);
Jaya Kumar9ac25592006-04-28 14:34:49 +0200435 cs5535au->pcm = pcm;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100436
437 return 0;
438}
439