Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1 | /* |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 2 | * SAA713x ALSA support for V4L |
| 3 | * Ricardo Cerqueira <v4l@cerqueira.org> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 4 | * |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 5 | * |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 6 | * Caveats: |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 7 | * - Volume doesn't work (it's always at max) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 8 | * |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation, version 2 |
| 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 | * |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 24 | #include <sound/driver.h> |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/time.h> |
| 28 | #include <linux/wait.h> |
| 29 | #include <linux/moduleparam.h> |
| 30 | #include <linux/module.h> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 31 | #include <sound/core.h> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 32 | #include <sound/control.h> |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 33 | #include <sound/pcm.h> |
| 34 | #include <sound/rawmidi.h> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 35 | #include <sound/initval.h> |
| 36 | |
| 37 | #include "saa7134.h" |
| 38 | #include "saa7134-reg.h" |
| 39 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 40 | static unsigned int alsa_debug = 0; |
| 41 | module_param(alsa_debug, int, 0644); |
| 42 | MODULE_PARM_DESC(alsa_debug,"enable debug messages [alsa]"); |
| 43 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 44 | /* |
| 45 | * Configuration macros |
| 46 | */ |
| 47 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 48 | /* defaults */ |
| 49 | #define MAX_BUFFER_SIZE (256*1024) |
| 50 | #define USE_FORMATS SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE |
| 51 | #define USE_RATE SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000 |
| 52 | #define USE_RATE_MIN 32000 |
| 53 | #define USE_RATE_MAX 48000 |
| 54 | #define USE_CHANNELS_MIN 1 |
| 55 | #define USE_CHANNELS_MAX 2 |
| 56 | #ifndef USE_PERIODS_MIN |
| 57 | #define USE_PERIODS_MIN 2 |
| 58 | #endif |
| 59 | #ifndef USE_PERIODS_MAX |
| 60 | #define USE_PERIODS_MAX 1024 |
| 61 | #endif |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 62 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 63 | #define MIXER_ADDR_TVTUNER 0 |
| 64 | #define MIXER_ADDR_LINE1 1 |
| 65 | #define MIXER_ADDR_LINE2 2 |
| 66 | #define MIXER_ADDR_LAST 2 |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 67 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 68 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 69 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 70 | static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0}; |
| 71 | |
| 72 | #define dprintk(fmt, arg...) if (alsa_debug) \ |
| 73 | printk(KERN_DEBUG "%s/alsa: " fmt, dev->name , ## arg) |
| 74 | |
| 75 | /* |
| 76 | * Main chip structure |
| 77 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 78 | typedef struct snd_card_saa7134 { |
| 79 | snd_card_t *card; |
| 80 | spinlock_t mixer_lock; |
| 81 | int mixer_volume[MIXER_ADDR_LAST+1][2]; |
| 82 | int capture_source[MIXER_ADDR_LAST+1][2]; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 83 | struct pci_dev *pci; |
| 84 | struct saa7134_dev *saadev; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 85 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 86 | unsigned long iobase; |
| 87 | int irq; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 88 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 89 | spinlock_t lock; |
| 90 | } snd_card_saa7134_t; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 91 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 92 | /* |
| 93 | * PCM structure |
| 94 | */ |
| 95 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 96 | typedef struct snd_card_saa7134_pcm { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 97 | struct saa7134_dev *saadev; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 98 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 99 | spinlock_t lock; |
| 100 | unsigned int pcm_size; /* buffer size */ |
| 101 | unsigned int pcm_count; /* bytes per period */ |
| 102 | unsigned int pcm_bps; /* bytes per second */ |
| 103 | snd_pcm_substream_t *substream; |
| 104 | } snd_card_saa7134_pcm_t; |
| 105 | |
| 106 | static snd_card_t *snd_saa7134_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; |
| 107 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 108 | /* |
| 109 | * saa7134 DMA audio stop |
| 110 | * |
| 111 | * Called when the capture device is released or the buffer overflows |
| 112 | * |
| 113 | * - Copied verbatim from saa7134-oss's dsp_dma_stop. Can be dropped |
| 114 | * if we just share dsp_dma_stop and use it here |
| 115 | * |
| 116 | */ |
| 117 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 118 | static void saa7134_dma_stop(struct saa7134_dev *dev) |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 119 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 120 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 121 | dev->oss.dma_blk = -1; |
| 122 | dev->oss.dma_running = 0; |
| 123 | saa7134_set_dmabits(dev); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 126 | /* |
| 127 | * saa7134 DMA audio start |
| 128 | * |
| 129 | * Called when preparing the capture device for use |
| 130 | * |
| 131 | * - Copied verbatim from saa7134-oss's dsp_dma_start. Can be dropped |
| 132 | * if we just share dsp_dma_start and use it here |
| 133 | * |
| 134 | */ |
| 135 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 136 | static void saa7134_dma_start(struct saa7134_dev *dev) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 137 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 138 | dev->oss.dma_blk = 0; |
| 139 | dev->oss.dma_running = 1; |
| 140 | saa7134_set_dmabits(dev); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 143 | /* |
| 144 | * saa7134 audio DMA IRQ handler |
| 145 | * |
| 146 | * Called whenever we get an SAA7134_IRQ_REPORT_DONE_RA3 interrupt |
| 147 | * Handles shifting between the 2 buffers, manages the read counters, |
| 148 | * and notifies ALSA when periods elapse |
| 149 | * |
| 150 | * - Mostly copied from saa7134-oss's saa7134_irq_oss_done. |
| 151 | * |
| 152 | */ |
| 153 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 154 | void saa7134_irq_alsa_done(struct saa7134_dev *dev, unsigned long status) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 155 | { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 156 | int next_blk, reg = 0; |
| 157 | |
| 158 | spin_lock(&dev->slock); |
| 159 | if (UNSET == dev->oss.dma_blk) { |
| 160 | dprintk("irq: recording stopped\n"); |
| 161 | goto done; |
| 162 | } |
| 163 | if (0 != (status & 0x0f000000)) |
| 164 | dprintk("irq: lost %ld\n", (status >> 24) & 0x0f); |
| 165 | if (0 == (status & 0x10000000)) { |
| 166 | /* odd */ |
| 167 | if (0 == (dev->oss.dma_blk & 0x01)) |
| 168 | reg = SAA7134_RS_BA1(6); |
| 169 | } else { |
| 170 | /* even */ |
| 171 | if (1 == (dev->oss.dma_blk & 0x01)) |
| 172 | reg = SAA7134_RS_BA2(6); |
| 173 | } |
| 174 | if (0 == reg) { |
| 175 | dprintk("irq: field oops [%s]\n", |
| 176 | (status & 0x10000000) ? "even" : "odd"); |
| 177 | goto done; |
| 178 | } |
| 179 | |
| 180 | if (dev->oss.read_count >= dev->oss.blksize * (dev->oss.blocks-2)) { |
| 181 | dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->oss.read_count, |
| 182 | dev->oss.bufsize, dev->oss.blocks); |
| 183 | saa7134_dma_stop(dev); |
| 184 | goto done; |
| 185 | } |
| 186 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 187 | /* next block addr */ |
| 188 | next_blk = (dev->oss.dma_blk + 2) % dev->oss.blocks; |
| 189 | saa_writel(reg,next_blk * dev->oss.blksize); |
| 190 | if (alsa_debug > 2) |
| 191 | dprintk("irq: ok, %s, next_blk=%d, addr=%x, blocks=%u, size=%u, read=%u\n", |
| 192 | (status & 0x10000000) ? "even" : "odd ", next_blk, |
| 193 | next_blk * dev->oss.blksize, dev->oss.blocks, dev->oss.blksize, dev->oss.read_count); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 194 | |
| 195 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 196 | /* update status & wake waiting readers */ |
| 197 | dev->oss.dma_blk = (dev->oss.dma_blk + 1) % dev->oss.blocks; |
| 198 | dev->oss.read_count += dev->oss.blksize; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 199 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 200 | dev->oss.recording_on = reg; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 201 | |
| 202 | if (dev->oss.read_count >= snd_pcm_lib_period_bytes(dev->oss.substream)) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 203 | spin_unlock(&dev->slock); |
| 204 | snd_pcm_period_elapsed(dev->oss.substream); |
| 205 | spin_lock(&dev->slock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 206 | } |
| 207 | done: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 208 | spin_unlock(&dev->slock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 209 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 212 | /* |
| 213 | * ALSA capture trigger |
| 214 | * |
| 215 | * - One of the ALSA capture callbacks. |
| 216 | * |
| 217 | * Called whenever a capture is started or stopped. Must be defined, |
| 218 | * but there's nothing we want to do here |
| 219 | * |
| 220 | */ |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 221 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 222 | static int snd_card_saa7134_capture_trigger(snd_pcm_substream_t * substream, |
| 223 | int cmd) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 224 | { |
| 225 | return 0; |
| 226 | } |
| 227 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 228 | /* |
| 229 | * DMA buffer config |
| 230 | * |
| 231 | * Sets the values that will later be used as the size of the buffer, |
| 232 | * size of the fragments, and total number of fragments. |
| 233 | * Must be called during the preparation stage, before memory is |
| 234 | * allocated |
| 235 | * |
| 236 | * - Copied verbatim from saa7134-oss. Can be dropped |
| 237 | * if we just share dsp_buffer_conf from OSS. |
| 238 | */ |
| 239 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 240 | static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 241 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 242 | if (blksize < 0x100) |
| 243 | blksize = 0x100; |
| 244 | if (blksize > 0x10000) |
| 245 | blksize = 0x10000; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 246 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 247 | if (blocks < 2) |
| 248 | blocks = 2; |
| 249 | if ((blksize * blocks) > 1024*1024) |
| 250 | blocks = 1024*1024 / blksize; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 251 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 252 | dev->oss.blocks = blocks; |
| 253 | dev->oss.blksize = blksize; |
| 254 | dev->oss.bufsize = blksize * blocks; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 255 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 256 | dprintk("buffer config: %d blocks / %d bytes, %d kB total\n", |
| 257 | blocks,blksize,blksize * blocks / 1024); |
| 258 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 259 | } |
| 260 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 261 | /* |
| 262 | * DMA buffer initialization |
| 263 | * |
| 264 | * Uses V4L functions to initialize the DMA. Shouldn't be necessary in |
| 265 | * ALSA, but I was unable to use ALSA's own DMA, and had to force the |
| 266 | * usage of V4L's |
| 267 | * |
| 268 | * - Copied verbatim from saa7134-oss. Can be dropped |
| 269 | * if we just share dsp_buffer_init from OSS. |
| 270 | */ |
| 271 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 272 | static int dsp_buffer_init(struct saa7134_dev *dev) |
| 273 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 274 | int err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 275 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 276 | if (!dev->oss.bufsize) |
| 277 | BUG(); |
| 278 | videobuf_dma_init(&dev->oss.dma); |
| 279 | err = videobuf_dma_init_kernel(&dev->oss.dma, PCI_DMA_FROMDEVICE, |
| 280 | (dev->oss.bufsize + PAGE_SIZE) >> PAGE_SHIFT); |
| 281 | if (0 != err) |
| 282 | return err; |
| 283 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 286 | /* |
| 287 | * ALSA PCM preparation |
| 288 | * |
| 289 | * - One of the ALSA capture callbacks. |
| 290 | * |
| 291 | * Called right after the capture device is opened, this function configures |
| 292 | * the buffer using the previously defined functions, allocates the memory, |
| 293 | * sets up the hardware registers, and then starts the DMA. When this function |
| 294 | * returns, the audio should be flowing. |
| 295 | * |
| 296 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 297 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 298 | static int snd_card_saa7134_capture_prepare(snd_pcm_substream_t * substream) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 299 | { |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 300 | snd_pcm_runtime_t *runtime = substream->runtime; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 301 | int err, bswap, sign; |
| 302 | u32 fmt, control; |
| 303 | unsigned long flags; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 304 | snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 305 | struct saa7134_dev *dev; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 306 | snd_card_saa7134_pcm_t *saapcm = runtime->private_data; |
| 307 | unsigned int bps; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 308 | unsigned long size; |
| 309 | unsigned count; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 310 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 311 | size = snd_pcm_lib_buffer_bytes(substream); |
| 312 | count = snd_pcm_lib_period_bytes(substream); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 313 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 314 | saapcm->saadev->oss.substream = substream; |
| 315 | bps = runtime->rate * runtime->channels; |
| 316 | bps *= snd_pcm_format_width(runtime->format); |
| 317 | bps /= 8; |
| 318 | if (bps <= 0) |
| 319 | return -EINVAL; |
| 320 | saapcm->pcm_bps = bps; |
| 321 | saapcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); |
| 322 | saapcm->pcm_count = snd_pcm_lib_period_bytes(substream); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 323 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 324 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 325 | dev=saa7134->saadev; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 326 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 327 | dsp_buffer_conf(dev,saapcm->pcm_count,(saapcm->pcm_size/saapcm->pcm_count)); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 328 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 329 | err = dsp_buffer_init(dev); |
| 330 | if (0 != err) |
| 331 | goto fail2; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 332 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 333 | /* prepare buffer */ |
| 334 | if (0 != (err = videobuf_dma_pci_map(dev->pci,&dev->oss.dma))) |
| 335 | return err; |
| 336 | if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->oss.pt))) |
| 337 | goto fail1; |
| 338 | if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->oss.pt, |
| 339 | dev->oss.dma.sglist, |
| 340 | dev->oss.dma.sglen, |
| 341 | 0))) |
| 342 | goto fail2; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 343 | |
| 344 | |
| 345 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 346 | switch (runtime->format) { |
| 347 | case SNDRV_PCM_FORMAT_U8: |
| 348 | case SNDRV_PCM_FORMAT_S8: |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 349 | fmt = 0x00; |
| 350 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 351 | case SNDRV_PCM_FORMAT_U16_LE: |
| 352 | case SNDRV_PCM_FORMAT_U16_BE: |
| 353 | case SNDRV_PCM_FORMAT_S16_LE: |
| 354 | case SNDRV_PCM_FORMAT_S16_BE: |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 355 | fmt = 0x01; |
| 356 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 357 | default: |
| 358 | err = -EINVAL; |
| 359 | return 1; |
| 360 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 361 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 362 | switch (runtime->format) { |
| 363 | case SNDRV_PCM_FORMAT_S8: |
| 364 | case SNDRV_PCM_FORMAT_S16_LE: |
| 365 | case SNDRV_PCM_FORMAT_S16_BE: |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 366 | sign = 1; |
| 367 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 368 | default: |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 369 | sign = 0; |
| 370 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 371 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 372 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 373 | switch (runtime->format) { |
| 374 | case SNDRV_PCM_FORMAT_U16_BE: |
| 375 | case SNDRV_PCM_FORMAT_S16_BE: |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 376 | bswap = 1; break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 377 | default: |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 378 | bswap = 0; break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 379 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 380 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 381 | switch (dev->pci->device) { |
| 382 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
| 383 | if (1 == runtime->channels) |
| 384 | fmt |= (1 << 3); |
| 385 | if (2 == runtime->channels) |
| 386 | fmt |= (3 << 3); |
| 387 | if (sign) |
| 388 | fmt |= 0x04; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 389 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 390 | fmt |= (MIXER_ADDR_TVTUNER == dev->oss.input) ? 0xc0 : 0x80; |
| 391 | saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->oss.blksize - 1) & 0x0000ff)); |
| 392 | saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->oss.blksize - 1) & 0x00ff00) >> 8); |
| 393 | saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->oss.blksize - 1) & 0xff0000) >> 16); |
| 394 | saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 395 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 396 | break; |
| 397 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 398 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
| 399 | if (1 == runtime->channels) |
| 400 | fmt |= (1 << 4); |
| 401 | if (2 == runtime->channels) |
| 402 | fmt |= (2 << 4); |
| 403 | if (!sign) |
| 404 | fmt |= 0x04; |
| 405 | saa_writel(SAA7133_NUM_SAMPLES, dev->oss.blksize -1); |
| 406 | saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24)); |
| 407 | //saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210); |
| 408 | break; |
| 409 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 410 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 411 | dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n", |
| 412 | runtime->format, runtime->channels, fmt, |
| 413 | bswap ? 'b' : '-'); |
| 414 | /* dma: setup channel 6 (= AUDIO) */ |
| 415 | control = SAA7134_RS_CONTROL_BURST_16 | |
| 416 | SAA7134_RS_CONTROL_ME | |
| 417 | (dev->oss.pt.dma >> 12); |
| 418 | if (bswap) |
| 419 | control |= SAA7134_RS_CONTROL_BSWAP; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 420 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 421 | /* I should be able to use runtime->dma_addr in the control |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 422 | byte, but it doesn't work. So I allocate the DMA using the |
| 423 | V4L functions, and force ALSA to use that as the DMA area */ |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 424 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 425 | runtime->dma_area = dev->oss.dma.vmalloc; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 426 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 427 | saa_writel(SAA7134_RS_BA1(6),0); |
| 428 | saa_writel(SAA7134_RS_BA2(6),dev->oss.blksize); |
| 429 | saa_writel(SAA7134_RS_PITCH(6),0); |
| 430 | saa_writel(SAA7134_RS_CONTROL(6),control); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 431 | |
| 432 | dev->oss.rate = runtime->rate; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 433 | /* start dma */ |
| 434 | spin_lock_irqsave(&dev->slock,flags); |
| 435 | saa7134_dma_start(dev); |
| 436 | spin_unlock_irqrestore(&dev->slock,flags); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 437 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 438 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 439 | fail2: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 440 | saa7134_pgtable_free(dev->pci,&dev->oss.pt); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 441 | fail1: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 442 | videobuf_dma_pci_unmap(dev->pci,&dev->oss.dma); |
| 443 | return err; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 444 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 445 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 446 | } |
| 447 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 448 | /* |
| 449 | * ALSA pointer fetching |
| 450 | * |
| 451 | * - One of the ALSA capture callbacks. |
| 452 | * |
| 453 | * Called whenever a period elapses, it must return the current hardware |
| 454 | * position of the buffer. |
| 455 | * Also resets the read counter used to prevent overruns |
| 456 | * |
| 457 | */ |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 458 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 459 | static snd_pcm_uframes_t snd_card_saa7134_capture_pointer(snd_pcm_substream_t * substream) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 460 | { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 461 | snd_pcm_runtime_t *runtime = substream->runtime; |
| 462 | snd_card_saa7134_pcm_t *saapcm = runtime->private_data; |
| 463 | struct saa7134_dev *dev=saapcm->saadev; |
| 464 | |
| 465 | |
| 466 | |
| 467 | if (dev->oss.read_count) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 468 | dev->oss.read_count -= snd_pcm_lib_period_bytes(substream); |
| 469 | dev->oss.read_offset += snd_pcm_lib_period_bytes(substream); |
| 470 | if (dev->oss.read_offset == dev->oss.bufsize) |
| 471 | dev->oss.read_offset = 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 474 | return bytes_to_frames(runtime, dev->oss.read_offset); |
| 475 | } |
| 476 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 477 | /* |
| 478 | * ALSA hardware capabilities definition |
| 479 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 480 | |
| 481 | static snd_pcm_hardware_t snd_card_saa7134_capture = |
| 482 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 483 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 484 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 485 | SNDRV_PCM_INFO_MMAP_VALID), |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 486 | .formats = USE_FORMATS, |
| 487 | .rates = USE_RATE, |
| 488 | .rate_min = USE_RATE_MIN, |
| 489 | .rate_max = USE_RATE_MAX, |
| 490 | .channels_min = USE_CHANNELS_MIN, |
| 491 | .channels_max = USE_CHANNELS_MAX, |
| 492 | .buffer_bytes_max = MAX_BUFFER_SIZE, |
| 493 | .period_bytes_min = 64, |
| 494 | .period_bytes_max = MAX_BUFFER_SIZE, |
| 495 | .periods_min = USE_PERIODS_MIN, |
| 496 | .periods_max = USE_PERIODS_MAX, |
| 497 | .fifo_size = 0x08070503, |
| 498 | }; |
| 499 | |
| 500 | static void snd_card_saa7134_runtime_free(snd_pcm_runtime_t *runtime) |
| 501 | { |
| 502 | snd_card_saa7134_pcm_t *saapcm = runtime->private_data; |
| 503 | |
| 504 | kfree(saapcm); |
| 505 | } |
| 506 | |
| 507 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 508 | /* |
| 509 | * ALSA hardware params |
| 510 | * |
| 511 | * - One of the ALSA capture callbacks. |
| 512 | * |
| 513 | * Called on initialization, right before the PCM preparation |
| 514 | * Usually used in ALSA to allocate the DMA, but since we don't use the |
| 515 | * ALSA DMA I'm almost sure this isn't necessary. |
| 516 | * |
| 517 | */ |
| 518 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 519 | static int snd_card_saa7134_hw_params(snd_pcm_substream_t * substream, |
| 520 | snd_pcm_hw_params_t * hw_params) |
| 521 | { |
| 522 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 523 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 524 | |
| 525 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 526 | } |
| 527 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 528 | /* |
| 529 | * ALSA hardware release |
| 530 | * |
| 531 | * - One of the ALSA capture callbacks. |
| 532 | * |
| 533 | * Called after closing the device, but before snd_card_saa7134_capture_close |
| 534 | * Usually used in ALSA to free the DMA, but since we don't use the |
| 535 | * ALSA DMA I'm almost sure this isn't necessary. |
| 536 | * |
| 537 | */ |
| 538 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 539 | static int snd_card_saa7134_hw_free(snd_pcm_substream_t * substream) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 540 | { |
| 541 | return snd_pcm_lib_free_pages(substream); |
| 542 | } |
| 543 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 544 | /* |
| 545 | * DMA buffer release |
| 546 | * |
| 547 | * Called after closing the device, during snd_card_saa7134_capture_close |
| 548 | * |
| 549 | */ |
| 550 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 551 | static int dsp_buffer_free(struct saa7134_dev *dev) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 552 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 553 | if (!dev->oss.blksize) |
| 554 | BUG(); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 555 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 556 | videobuf_dma_free(&dev->oss.dma); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 557 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 558 | dev->oss.blocks = 0; |
| 559 | dev->oss.blksize = 0; |
| 560 | dev->oss.bufsize = 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 561 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 562 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 563 | } |
| 564 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 565 | /* |
| 566 | * ALSA capture finish |
| 567 | * |
| 568 | * - One of the ALSA capture callbacks. |
| 569 | * |
| 570 | * Called after closing the device. It stops the DMA audio and releases |
| 571 | * the buffers |
| 572 | * |
| 573 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 574 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 575 | static int snd_card_saa7134_capture_close(snd_pcm_substream_t * substream) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 576 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 577 | snd_card_saa7134_t *chip = snd_pcm_substream_chip(substream); |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 578 | struct saa7134_dev *dev = chip->saadev; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 579 | unsigned long flags; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 580 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 581 | /* stop dma */ |
| 582 | spin_lock_irqsave(&dev->slock,flags); |
| 583 | saa7134_dma_stop(dev); |
| 584 | spin_unlock_irqrestore(&dev->slock,flags); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 585 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 586 | /* unlock buffer */ |
| 587 | saa7134_pgtable_free(dev->pci,&dev->oss.pt); |
| 588 | videobuf_dma_pci_unmap(dev->pci,&dev->oss.dma); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 589 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 590 | dsp_buffer_free(dev); |
| 591 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 592 | } |
| 593 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 594 | /* |
| 595 | * ALSA capture start |
| 596 | * |
| 597 | * - One of the ALSA capture callbacks. |
| 598 | * |
| 599 | * Called when opening the device. It creates and populates the PCM |
| 600 | * structure |
| 601 | * |
| 602 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 603 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 604 | static int snd_card_saa7134_capture_open(snd_pcm_substream_t * substream) |
| 605 | { |
| 606 | snd_pcm_runtime_t *runtime = substream->runtime; |
| 607 | snd_card_saa7134_pcm_t *saapcm; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 608 | snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); |
| 609 | struct saa7134_dev *dev = saa7134->saadev; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 610 | int err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 611 | |
| 612 | down(&dev->oss.lock); |
| 613 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 614 | dev->oss.afmt = SNDRV_PCM_FORMAT_U8; |
| 615 | dev->oss.channels = 2; |
| 616 | dev->oss.read_count = 0; |
| 617 | dev->oss.read_offset = 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 618 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 619 | up(&dev->oss.lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 620 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 621 | saapcm = kcalloc(1, sizeof(*saapcm), GFP_KERNEL); |
| 622 | if (saapcm == NULL) |
| 623 | return -ENOMEM; |
| 624 | saapcm->saadev=saa7134->saadev; |
| 625 | |
| 626 | spin_lock_init(&saapcm->lock); |
| 627 | |
| 628 | saapcm->substream = substream; |
| 629 | runtime->private_data = saapcm; |
| 630 | runtime->private_free = snd_card_saa7134_runtime_free; |
| 631 | runtime->hw = snd_card_saa7134_capture; |
| 632 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 633 | if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) |
| 634 | return err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 635 | |
| 636 | return 0; |
| 637 | } |
| 638 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 639 | /* |
| 640 | * ALSA capture callbacks definition |
| 641 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 642 | |
| 643 | static snd_pcm_ops_t snd_card_saa7134_capture_ops = { |
| 644 | .open = snd_card_saa7134_capture_open, |
| 645 | .close = snd_card_saa7134_capture_close, |
| 646 | .ioctl = snd_pcm_lib_ioctl, |
| 647 | .hw_params = snd_card_saa7134_hw_params, |
| 648 | .hw_free = snd_card_saa7134_hw_free, |
| 649 | .prepare = snd_card_saa7134_capture_prepare, |
| 650 | .trigger = snd_card_saa7134_capture_trigger, |
| 651 | .pointer = snd_card_saa7134_capture_pointer, |
| 652 | }; |
| 653 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 654 | /* |
| 655 | * ALSA PCM setup |
| 656 | * |
| 657 | * Called when initializing the board. Sets up the name and hooks up |
| 658 | * the callbacks |
| 659 | * |
| 660 | */ |
| 661 | |
| 662 | static int snd_card_saa7134_pcm(snd_card_saa7134_t *saa7134, int device) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 663 | { |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 664 | snd_pcm_t *pcm; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 665 | int err; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 666 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 667 | if ((err = snd_pcm_new(saa7134->card, "SAA7134 PCM", device, 0, 1, &pcm)) < 0) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 668 | return err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 669 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_saa7134_capture_ops); |
| 670 | pcm->private_data = saa7134; |
| 671 | pcm->info_flags = 0; |
| 672 | strcpy(pcm->name, "SAA7134 PCM"); |
| 673 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 674 | snd_dma_pci_data(saa7134->pci), |
| 675 | 128*1024, 256*1024); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 676 | return 0; |
| 677 | } |
| 678 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 679 | #define SAA713x_VOLUME(xname, xindex, addr) \ |
| 680 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 681 | .info = snd_saa7134_volume_info, \ |
| 682 | .get = snd_saa7134_volume_get, .put = snd_saa7134_volume_put, \ |
| 683 | .private_value = addr } |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 684 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 685 | static int snd_saa7134_volume_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo) |
| 686 | { |
| 687 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 688 | uinfo->count = 2; |
| 689 | uinfo->value.integer.min = 0; |
| 690 | uinfo->value.integer.max = 20; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 691 | return 0; |
| 692 | } |
| 693 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 694 | static int snd_saa7134_volume_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 695 | { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 696 | snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
| 697 | unsigned long flags; |
| 698 | int addr = kcontrol->private_value; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 699 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 700 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 701 | ucontrol->value.integer.value[0] = chip->mixer_volume[addr][0]; |
| 702 | ucontrol->value.integer.value[1] = chip->mixer_volume[addr][1]; |
| 703 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 704 | return 0; |
| 705 | } |
| 706 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 707 | static int snd_saa7134_volume_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
| 708 | { |
| 709 | snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
| 710 | unsigned long flags; |
| 711 | int change, addr = kcontrol->private_value; |
| 712 | int left, right; |
| 713 | |
| 714 | left = ucontrol->value.integer.value[0]; |
| 715 | if (left < 0) |
| 716 | left = 0; |
| 717 | if (left > 20) |
| 718 | left = 20; |
| 719 | right = ucontrol->value.integer.value[1]; |
| 720 | if (right < 0) |
| 721 | right = 0; |
| 722 | if (right > 20) |
| 723 | right = 20; |
| 724 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 725 | change = chip->mixer_volume[addr][0] != left || |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 726 | chip->mixer_volume[addr][1] != right; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 727 | chip->mixer_volume[addr][0] = left; |
| 728 | chip->mixer_volume[addr][1] = right; |
| 729 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 730 | return change; |
| 731 | } |
| 732 | |
| 733 | #define SAA713x_CAPSRC(xname, xindex, addr) \ |
| 734 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 735 | .info = snd_saa7134_capsrc_info, \ |
| 736 | .get = snd_saa7134_capsrc_get, .put = snd_saa7134_capsrc_put, \ |
| 737 | .private_value = addr } |
| 738 | |
| 739 | static int snd_saa7134_capsrc_info(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo) |
| 740 | { |
| 741 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 742 | uinfo->count = 2; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 743 | uinfo->value.integer.min = 0; |
| 744 | uinfo->value.integer.max = 1; |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static int snd_saa7134_capsrc_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
| 749 | { |
| 750 | snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
| 751 | unsigned long flags; |
| 752 | int addr = kcontrol->private_value; |
| 753 | |
| 754 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 755 | ucontrol->value.integer.value[0] = chip->capture_source[addr][0]; |
| 756 | ucontrol->value.integer.value[1] = chip->capture_source[addr][1]; |
| 757 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | static int snd_saa7134_capsrc_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) |
| 762 | { |
| 763 | snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
| 764 | unsigned long flags; |
| 765 | int change, addr = kcontrol->private_value; |
| 766 | int left, right; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 767 | u32 anabar, xbarin; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 768 | int analog_io, rate; |
| 769 | struct saa7134_dev *dev; |
| 770 | |
| 771 | dev = chip->saadev; |
| 772 | |
| 773 | left = ucontrol->value.integer.value[0] & 1; |
| 774 | right = ucontrol->value.integer.value[1] & 1; |
| 775 | spin_lock_irqsave(&chip->mixer_lock, flags); |
| 776 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 777 | change = chip->capture_source[addr][0] != left || |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 778 | chip->capture_source[addr][1] != right; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 779 | chip->capture_source[addr][0] = left; |
| 780 | chip->capture_source[addr][1] = right; |
| 781 | dev->oss.input=addr; |
| 782 | spin_unlock_irqrestore(&chip->mixer_lock, flags); |
| 783 | |
| 784 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 785 | if (change) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 786 | switch (dev->pci->device) { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 787 | |
| 788 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 789 | switch (addr) { |
| 790 | case MIXER_ADDR_TVTUNER: |
| 791 | saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0); |
| 792 | saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00); |
| 793 | break; |
| 794 | case MIXER_ADDR_LINE1: |
| 795 | case MIXER_ADDR_LINE2: |
| 796 | analog_io = (MIXER_ADDR_LINE1 == addr) ? 0x00 : 0x08; |
| 797 | rate = (32000 == dev->oss.rate) ? 0x01 : 0x03; |
| 798 | saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io); |
| 799 | saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80); |
| 800 | saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate); |
| 801 | break; |
| 802 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 803 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 804 | break; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 805 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 806 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 807 | xbarin = 0x03; // adc |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 808 | anabar = 0; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 809 | switch (addr) { |
| 810 | case MIXER_ADDR_TVTUNER: |
| 811 | xbarin = 0; // Demodulator |
| 812 | anabar = 2; // DACs |
| 813 | break; |
| 814 | case MIXER_ADDR_LINE1: |
| 815 | anabar = 0; // aux1, aux1 |
| 816 | break; |
| 817 | case MIXER_ADDR_LINE2: |
| 818 | anabar = 9; // aux2, aux2 |
| 819 | break; |
| 820 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 821 | |
| 822 | /* output xbar always main channel */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 823 | saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL1, 0xbbbb10); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 824 | |
| 825 | if (left || right) { // We've got data, turn the input on |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 826 | //saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL2, 0x101010); |
| 827 | saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, xbarin); |
| 828 | saa_writel(SAA7133_ANALOG_IO_SELECT, anabar); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 829 | } else { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 830 | //saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL2, 0x101010); |
| 831 | saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, 0); |
| 832 | saa_writel(SAA7133_ANALOG_IO_SELECT, 0); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 833 | } |
Ricardo Cerqueira | a866623 | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 834 | break; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 835 | } |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 836 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 837 | |
| 838 | return change; |
| 839 | } |
| 840 | |
| 841 | static snd_kcontrol_new_t snd_saa7134_controls[] = { |
| 842 | SAA713x_VOLUME("Video Volume", 0, MIXER_ADDR_TVTUNER), |
| 843 | SAA713x_CAPSRC("Video Capture Switch", 0, MIXER_ADDR_TVTUNER), |
| 844 | SAA713x_VOLUME("Line Volume", 1, MIXER_ADDR_LINE1), |
| 845 | SAA713x_CAPSRC("Line Capture Switch", 1, MIXER_ADDR_LINE1), |
| 846 | SAA713x_VOLUME("Line Volume", 2, MIXER_ADDR_LINE2), |
| 847 | SAA713x_CAPSRC("Line Capture Switch", 2, MIXER_ADDR_LINE2), |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 848 | }; |
| 849 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 850 | /* |
| 851 | * ALSA mixer setup |
| 852 | * |
| 853 | * Called when initializing the board. Sets up the name and hooks up |
| 854 | * the callbacks |
| 855 | * |
| 856 | */ |
| 857 | |
| 858 | static int snd_card_saa7134_new_mixer(snd_card_saa7134_t * chip) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 859 | { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 860 | snd_card_t *card = chip->card; |
| 861 | unsigned int idx; |
| 862 | int err; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 863 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 864 | snd_assert(chip != NULL, return -EINVAL); |
| 865 | strcpy(card->mixername, "SAA7134 Mixer"); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 866 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 867 | for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_controls); idx++) { |
| 868 | if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_saa7134_controls[idx], chip))) < 0) |
| 869 | return err; |
| 870 | } |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 874 | static int snd_saa7134_free(snd_card_saa7134_t *chip) |
| 875 | { |
| 876 | return 0; |
| 877 | } |
| 878 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 879 | static int snd_saa7134_dev_free(snd_device_t *device) |
| 880 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 881 | snd_card_saa7134_t *chip = device->device_data; |
| 882 | return snd_saa7134_free(chip); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 883 | } |
| 884 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 885 | /* |
| 886 | * ALSA initialization |
| 887 | * |
| 888 | * Called by saa7134-core, it creates the basic structures and registers |
| 889 | * the ALSA devices |
| 890 | * |
| 891 | */ |
| 892 | |
Ricardo Cerqueira | a866623 | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 893 | int alsa_card_saa7134_create(struct saa7134_dev *saadev, unsigned int devicenum) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 894 | { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 895 | static int dev; |
| 896 | snd_card_t *card; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 897 | snd_card_saa7134_t *chip; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 898 | int err; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 899 | static snd_device_ops_t ops = { |
| 900 | .dev_free = snd_saa7134_dev_free, |
| 901 | }; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 902 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 903 | if (dev >= SNDRV_CARDS) |
| 904 | return -ENODEV; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 905 | if (!enable[dev]) |
| 906 | return -ENODEV; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 907 | |
Ricardo Cerqueira | a866623 | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 908 | if (devicenum) { |
| 909 | card = snd_card_new(devicenum, id[dev], THIS_MODULE, 0); |
| 910 | } else { |
| 911 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); |
| 912 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 913 | if (card == NULL) |
| 914 | return -ENOMEM; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 915 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 916 | strcpy(card->driver, "SAA7134"); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 917 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 918 | /* Card "creation" */ |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 919 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 920 | chip = kcalloc(1, sizeof(*chip), GFP_KERNEL); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 921 | if (chip == NULL) { |
| 922 | return -ENOMEM; |
| 923 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 924 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 925 | spin_lock_init(&chip->lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 926 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 927 | chip->saadev = saadev; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 928 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 929 | chip->card = card; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 930 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 931 | chip->pci = saadev->pci; |
| 932 | chip->irq = saadev->pci->irq; |
| 933 | chip->iobase = pci_resource_start(saadev->pci, 0); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 934 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 935 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { |
| 936 | snd_saa7134_free(chip); |
| 937 | return err; |
| 938 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 939 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 940 | if ((err = snd_card_saa7134_new_mixer(chip)) < 0) |
| 941 | goto __nodev; |
| 942 | |
| 943 | if ((err = snd_card_saa7134_pcm(chip, 0)) < 0) |
| 944 | goto __nodev; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 945 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 946 | spin_lock_init(&chip->mixer_lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 947 | |
| 948 | snd_card_set_dev(card, &chip->pci->dev); |
| 949 | |
| 950 | /* End of "creation" */ |
| 951 | |
| 952 | strcpy(card->shortname, "SAA7134"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 953 | sprintf(card->longname, "%s at 0x%lx irq %d", |
| 954 | chip->saadev->name, chip->iobase, chip->irq); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 955 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 956 | if ((err = snd_card_register(card)) == 0) { |
| 957 | snd_saa7134_cards[dev] = card; |
| 958 | return 0; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 959 | } |
| 960 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 961 | __nodev: |
| 962 | snd_card_free(card); |
| 963 | kfree(card); |
| 964 | return err; |
| 965 | } |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 966 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 967 | void alsa_card_saa7134_exit(void) |
| 968 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame^] | 969 | int idx; |
| 970 | for (idx = 0; idx < SNDRV_CARDS; idx++) { |
| 971 | snd_card_free(snd_saa7134_cards[idx]); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 972 | } |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 973 | } |