blob: 499e27961a30e0f26e2bcb87abe20711ca594c0e [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>
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010028#include <sound/core.h>
29#include <sound/control.h>
30#include <sound/initval.h>
31#include <sound/asoundef.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/ac97_codec.h>
35#include "cs5535audio.h"
36
Takashi Iwai66f8df62005-11-17 14:56:21 +010037static struct snd_pcm_hardware snd_cs5535audio_playback =
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010038{
39 .info = (
40 SNDRV_PCM_INFO_MMAP |
41 SNDRV_PCM_INFO_INTERLEAVED |
42 SNDRV_PCM_INFO_BLOCK_TRANSFER |
43 SNDRV_PCM_INFO_MMAP_VALID |
44 SNDRV_PCM_INFO_PAUSE |
Jaya Kumar9ac25592006-04-28 14:34:49 +020045 SNDRV_PCM_INFO_RESUME
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010046 ),
47 .formats = (
48 SNDRV_PCM_FMTBIT_S16_LE
49 ),
50 .rates = (
51 SNDRV_PCM_RATE_CONTINUOUS |
52 SNDRV_PCM_RATE_8000_48000
53 ),
54 .rate_min = 4000,
55 .rate_max = 48000,
56 .channels_min = 2,
57 .channels_max = 2,
58 .buffer_bytes_max = (128*1024),
59 .period_bytes_min = 64,
60 .period_bytes_max = (64*1024 - 16),
61 .periods_min = 1,
62 .periods_max = CS5535AUDIO_MAX_DESCRIPTORS,
63 .fifo_size = 0,
64};
65
Takashi Iwai66f8df62005-11-17 14:56:21 +010066static struct snd_pcm_hardware snd_cs5535audio_capture =
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010067{
68 .info = (
69 SNDRV_PCM_INFO_MMAP |
70 SNDRV_PCM_INFO_INTERLEAVED |
71 SNDRV_PCM_INFO_BLOCK_TRANSFER |
Clemens Ladischb83f3462007-08-13 17:37:55 +020072 SNDRV_PCM_INFO_MMAP_VALID
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010073 ),
74 .formats = (
75 SNDRV_PCM_FMTBIT_S16_LE
76 ),
77 .rates = (
78 SNDRV_PCM_RATE_CONTINUOUS |
79 SNDRV_PCM_RATE_8000_48000
80 ),
81 .rate_min = 4000,
82 .rate_max = 48000,
83 .channels_min = 2,
84 .channels_max = 2,
85 .buffer_bytes_max = (128*1024),
86 .period_bytes_min = 64,
87 .period_bytes_max = (64*1024 - 16),
88 .periods_min = 1,
89 .periods_max = CS5535AUDIO_MAX_DESCRIPTORS,
90 .fifo_size = 0,
91};
92
Takashi Iwai66f8df62005-11-17 14:56:21 +010093static int snd_cs5535audio_playback_open(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010094{
95 int err;
Takashi Iwai66f8df62005-11-17 14:56:21 +010096 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
97 struct snd_pcm_runtime *runtime = substream->runtime;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +010098
99 runtime->hw = snd_cs5535audio_playback;
100 cs5535au->playback_substream = substream;
101 runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK]);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100102 if ((err = snd_pcm_hw_constraint_integer(runtime,
103 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
104 return err;
105
106 return 0;
107}
108
Takashi Iwai66f8df62005-11-17 14:56:21 +0100109static int snd_cs5535audio_playback_close(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100110{
111 return 0;
112}
113
114#define CS5535AUDIO_DESC_LIST_SIZE \
Takashi Iwai66f8df62005-11-17 14:56:21 +0100115 PAGE_ALIGN(CS5535AUDIO_MAX_DESCRIPTORS * sizeof(struct cs5535audio_dma_desc))
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100116
Takashi Iwai66f8df62005-11-17 14:56:21 +0100117static int cs5535audio_build_dma_packets(struct cs5535audio *cs5535au,
118 struct cs5535audio_dma *dma,
119 struct snd_pcm_substream *substream,
120 unsigned int periods,
121 unsigned int period_bytes)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100122{
123 unsigned int i;
124 u32 addr, desc_addr, jmpprd_addr;
Takashi Iwai66f8df62005-11-17 14:56:21 +0100125 struct cs5535audio_dma_desc *lastdesc;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100126
127 if (periods > CS5535AUDIO_MAX_DESCRIPTORS)
128 return -ENOMEM;
129
130 if (dma->desc_buf.area == NULL) {
131 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
132 snd_dma_pci_data(cs5535au->pci),
133 CS5535AUDIO_DESC_LIST_SIZE+1,
134 &dma->desc_buf) < 0)
135 return -ENOMEM;
136 dma->period_bytes = dma->periods = 0;
137 }
138
139 if (dma->periods == periods && dma->period_bytes == period_bytes)
140 return 0;
141
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200142 /* the u32 cast is okay because in snd*create we successfully told
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100143 pci alloc that we're only 32 bit capable so the uppper will be 0 */
144 addr = (u32) substream->runtime->dma_addr;
145 desc_addr = (u32) dma->desc_buf.addr;
146 for (i = 0; i < periods; i++) {
Takashi Iwai66f8df62005-11-17 14:56:21 +0100147 struct cs5535audio_dma_desc *desc =
148 &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[i];
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100149 desc->addr = cpu_to_le32(addr);
Takashi Iwai3e873172005-11-17 10:15:37 +0100150 desc->size = cpu_to_le32(period_bytes);
151 desc->ctlreserved = cpu_to_le32(PRD_EOP);
Takashi Iwai66f8df62005-11-17 14:56:21 +0100152 desc_addr += sizeof(struct cs5535audio_dma_desc);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100153 addr += period_bytes;
154 }
155 /* we reserved one dummy descriptor at the end to do the PRD jump */
Takashi Iwai66f8df62005-11-17 14:56:21 +0100156 lastdesc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[periods];
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100157 lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr);
158 lastdesc->size = 0;
Takashi Iwai3e873172005-11-17 10:15:37 +0100159 lastdesc->ctlreserved = cpu_to_le32(PRD_JMP);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100160 jmpprd_addr = cpu_to_le32(lastdesc->addr +
Takashi Iwai66f8df62005-11-17 14:56:21 +0100161 (sizeof(struct cs5535audio_dma_desc)*periods));
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100162
Andres Salomon7abcacb2007-09-03 15:41:47 +0200163 dma->substream = substream;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100164 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 Iwai66f8df62005-11-17 14:56:21 +0100173static void cs5535audio_playback_enable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100174{
175 cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_EN);
176}
177
Takashi Iwai66f8df62005-11-17 14:56:21 +0100178static void cs5535audio_playback_disable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100179{
180 cs_writeb(cs5535au, ACC_BM0_CMD, 0);
181}
182
Takashi Iwai66f8df62005-11-17 14:56:21 +0100183static void cs5535audio_playback_pause_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100184{
185 cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_PAUSE);
186}
187
Takashi Iwai66f8df62005-11-17 14:56:21 +0100188static void cs5535audio_playback_setup_prd(struct cs5535audio *cs5535au,
189 u32 prd_addr)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100190{
191 cs_writel(cs5535au, ACC_BM0_PRD, prd_addr);
192}
193
Jaya Kumar9ac25592006-04-28 14:34:49 +0200194static u32 cs5535audio_playback_read_prd(struct cs5535audio *cs5535au)
195{
196 return cs_readl(cs5535au, ACC_BM0_PRD);
197}
198
Takashi Iwai66f8df62005-11-17 14:56:21 +0100199static u32 cs5535audio_playback_read_dma_pntr(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100200{
201 return cs_readl(cs5535au, ACC_BM0_PNTR);
202}
203
Takashi Iwai66f8df62005-11-17 14:56:21 +0100204static void cs5535audio_capture_enable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100205{
206 cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_EN);
207}
208
Takashi Iwai66f8df62005-11-17 14:56:21 +0100209static void cs5535audio_capture_disable_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100210{
211 cs_writeb(cs5535au, ACC_BM1_CMD, 0);
212}
213
Takashi Iwai66f8df62005-11-17 14:56:21 +0100214static void cs5535audio_capture_pause_dma(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100215{
216 cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_PAUSE);
217}
218
Takashi Iwai66f8df62005-11-17 14:56:21 +0100219static void cs5535audio_capture_setup_prd(struct cs5535audio *cs5535au,
220 u32 prd_addr)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100221{
222 cs_writel(cs5535au, ACC_BM1_PRD, prd_addr);
223}
224
Jaya Kumar9ac25592006-04-28 14:34:49 +0200225static u32 cs5535audio_capture_read_prd(struct cs5535audio *cs5535au)
226{
227 return cs_readl(cs5535au, ACC_BM1_PRD);
228}
229
Takashi Iwai66f8df62005-11-17 14:56:21 +0100230static u32 cs5535audio_capture_read_dma_pntr(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100231{
232 return cs_readl(cs5535au, ACC_BM1_PNTR);
233}
234
Takashi Iwai66f8df62005-11-17 14:56:21 +0100235static void cs5535audio_clear_dma_packets(struct cs5535audio *cs5535au,
236 struct cs5535audio_dma *dma,
237 struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100238{
239 snd_dma_free_pages(&dma->desc_buf);
240 dma->desc_buf.area = NULL;
Andres Salomon7abcacb2007-09-03 15:41:47 +0200241 dma->substream = NULL;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100242}
243
Takashi Iwai66f8df62005-11-17 14:56:21 +0100244static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream,
245 struct snd_pcm_hw_params *hw_params)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100246{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100247 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
248 struct cs5535audio_dma *dma = substream->runtime->private_data;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100249 int err;
250
251 err = snd_pcm_lib_malloc_pages(substream,
252 params_buffer_bytes(hw_params));
253 if (err < 0)
254 return err;
255 dma->buf_addr = substream->runtime->dma_addr;
256 dma->buf_bytes = params_buffer_bytes(hw_params);
257
258 err = cs5535audio_build_dma_packets(cs5535au, dma, substream,
Takashi Iwai66f8df62005-11-17 14:56:21 +0100259 params_periods(hw_params),
260 params_period_bytes(hw_params));
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100261 return err;
262}
263
Takashi Iwai66f8df62005-11-17 14:56:21 +0100264static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100265{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100266 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
267 struct cs5535audio_dma *dma = substream->runtime->private_data;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100268
269 cs5535audio_clear_dma_packets(cs5535au, dma, substream);
270 return snd_pcm_lib_free_pages(substream);
271}
272
Takashi Iwai66f8df62005-11-17 14:56:21 +0100273static int snd_cs5535audio_playback_prepare(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100274{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100275 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100276 return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE,
Takashi Iwai66f8df62005-11-17 14:56:21 +0100277 substream->runtime->rate);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100278}
279
Takashi Iwai66f8df62005-11-17 14:56:21 +0100280static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100281{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100282 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
283 struct cs5535audio_dma *dma = substream->runtime->private_data;
Takashi Iwai3e873172005-11-17 10:15:37 +0100284 int err = 0;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100285
Takashi Iwai3e873172005-11-17 10:15:37 +0100286 spin_lock(&cs5535au->reg_lock);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100287 switch (cmd) {
Takashi Iwai3e873172005-11-17 10:15:37 +0100288 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
289 dma->ops->pause_dma(cs5535au);
290 break;
291 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
292 dma->ops->enable_dma(cs5535au);
293 break;
294 case SNDRV_PCM_TRIGGER_START:
295 dma->ops->enable_dma(cs5535au);
296 break;
Jaya Kumar9ac25592006-04-28 14:34:49 +0200297 case SNDRV_PCM_TRIGGER_RESUME:
298 dma->ops->enable_dma(cs5535au);
Jaya Kumar9ac25592006-04-28 14:34:49 +0200299 break;
Takashi Iwai3e873172005-11-17 10:15:37 +0100300 case SNDRV_PCM_TRIGGER_STOP:
301 dma->ops->disable_dma(cs5535au);
302 break;
Jaya Kumar9ac25592006-04-28 14:34:49 +0200303 case SNDRV_PCM_TRIGGER_SUSPEND:
304 dma->ops->disable_dma(cs5535au);
Jaya Kumar9ac25592006-04-28 14:34:49 +0200305 break;
Takashi Iwai3e873172005-11-17 10:15:37 +0100306 default:
307 snd_printk(KERN_ERR "unhandled trigger\n");
308 err = -EINVAL;
309 break;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100310 }
Takashi Iwai3e873172005-11-17 10:15:37 +0100311 spin_unlock(&cs5535au->reg_lock);
312 return err;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100313}
314
Takashi Iwai66f8df62005-11-17 14:56:21 +0100315static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100316 *substream)
317{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100318 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100319 u32 curdma;
Takashi Iwai66f8df62005-11-17 14:56:21 +0100320 struct cs5535audio_dma *dma;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100321
322 dma = substream->runtime->private_data;
323 curdma = dma->ops->read_dma_pntr(cs5535au);
324 if (curdma < dma->buf_addr) {
325 snd_printk(KERN_ERR "curdma=%x < %x bufaddr.\n",
326 curdma, dma->buf_addr);
327 return 0;
328 }
329 curdma -= dma->buf_addr;
330 if (curdma >= dma->buf_bytes) {
331 snd_printk(KERN_ERR "diff=%x >= %x buf_bytes.\n",
332 curdma, dma->buf_bytes);
333 return 0;
334 }
335 return bytes_to_frames(substream->runtime, curdma);
336}
337
Takashi Iwai66f8df62005-11-17 14:56:21 +0100338static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100339{
340 int err;
Takashi Iwai66f8df62005-11-17 14:56:21 +0100341 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
342 struct snd_pcm_runtime *runtime = substream->runtime;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100343
344 runtime->hw = snd_cs5535audio_capture;
345 cs5535au->capture_substream = substream;
346 runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE]);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100347 if ((err = snd_pcm_hw_constraint_integer(runtime,
348 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
349 return err;
350 return 0;
351}
352
Takashi Iwai66f8df62005-11-17 14:56:21 +0100353static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100354{
355 return 0;
356}
357
Takashi Iwai66f8df62005-11-17 14:56:21 +0100358static int snd_cs5535audio_capture_prepare(struct snd_pcm_substream *substream)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100359{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100360 struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100361 return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_LR_ADC_RATE,
Takashi Iwai66f8df62005-11-17 14:56:21 +0100362 substream->runtime->rate);
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100363}
364
Takashi Iwai66f8df62005-11-17 14:56:21 +0100365static struct snd_pcm_ops snd_cs5535audio_playback_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100366 .open = snd_cs5535audio_playback_open,
367 .close = snd_cs5535audio_playback_close,
368 .ioctl = snd_pcm_lib_ioctl,
369 .hw_params = snd_cs5535audio_hw_params,
370 .hw_free = snd_cs5535audio_hw_free,
371 .prepare = snd_cs5535audio_playback_prepare,
372 .trigger = snd_cs5535audio_trigger,
373 .pointer = snd_cs5535audio_pcm_pointer,
374};
375
Takashi Iwai66f8df62005-11-17 14:56:21 +0100376static struct snd_pcm_ops snd_cs5535audio_capture_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100377 .open = snd_cs5535audio_capture_open,
378 .close = snd_cs5535audio_capture_close,
379 .ioctl = snd_pcm_lib_ioctl,
380 .hw_params = snd_cs5535audio_hw_params,
381 .hw_free = snd_cs5535audio_hw_free,
382 .prepare = snd_cs5535audio_capture_prepare,
383 .trigger = snd_cs5535audio_trigger,
384 .pointer = snd_cs5535audio_pcm_pointer,
385};
386
Takashi Iwai66f8df62005-11-17 14:56:21 +0100387static struct cs5535audio_dma_ops snd_cs5535audio_playback_dma_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100388 .type = CS5535AUDIO_DMA_PLAYBACK,
389 .enable_dma = cs5535audio_playback_enable_dma,
390 .disable_dma = cs5535audio_playback_disable_dma,
391 .setup_prd = cs5535audio_playback_setup_prd,
Jaya Kumar9ac25592006-04-28 14:34:49 +0200392 .read_prd = cs5535audio_playback_read_prd,
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100393 .pause_dma = cs5535audio_playback_pause_dma,
394 .read_dma_pntr = cs5535audio_playback_read_dma_pntr,
395};
396
Takashi Iwai66f8df62005-11-17 14:56:21 +0100397static struct cs5535audio_dma_ops snd_cs5535audio_capture_dma_ops = {
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100398 .type = CS5535AUDIO_DMA_CAPTURE,
399 .enable_dma = cs5535audio_capture_enable_dma,
400 .disable_dma = cs5535audio_capture_disable_dma,
401 .setup_prd = cs5535audio_capture_setup_prd,
Jaya Kumar9ac25592006-04-28 14:34:49 +0200402 .read_prd = cs5535audio_capture_read_prd,
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100403 .pause_dma = cs5535audio_capture_pause_dma,
404 .read_dma_pntr = cs5535audio_capture_read_dma_pntr,
405};
406
Takashi Iwai66f8df62005-11-17 14:56:21 +0100407int __devinit snd_cs5535audio_pcm(struct cs5535audio *cs5535au)
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100408{
Takashi Iwai66f8df62005-11-17 14:56:21 +0100409 struct snd_pcm *pcm;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100410 int err;
411
412 err = snd_pcm_new(cs5535au->card, "CS5535 Audio", 0, 1, 1, &pcm);
413 if (err < 0)
414 return err;
415
416 cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK].ops =
417 &snd_cs5535audio_playback_dma_ops;
418 cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE].ops =
419 &snd_cs5535audio_capture_dma_ops;
420 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
421 &snd_cs5535audio_playback_ops);
422 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
423 &snd_cs5535audio_capture_ops);
424
425 pcm->private_data = cs5535au;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100426 pcm->info_flags = 0;
427 strcpy(pcm->name, "CS5535 Audio");
428
429 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
430 snd_dma_pci_data(cs5535au->pci),
431 64*1024, 128*1024);
Jaya Kumar9ac25592006-04-28 14:34:49 +0200432 cs5535au->pcm = pcm;
Jaya Kumar9b4ffa42005-11-17 10:12:23 +0100433
434 return 0;
435}
436