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 |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 3 | * |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, version 2 |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | * |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 17 | */ |
| 18 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 19 | #include <linux/init.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/time.h> |
| 22 | #include <linux/wait.h> |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 23 | #include <linux/module.h> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 24 | #include <sound/core.h> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 25 | #include <sound/control.h> |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 26 | #include <sound/pcm.h> |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 27 | #include <sound/pcm_params.h> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 28 | #include <sound/initval.h> |
Nickolay V. Shmyrev | 871242b | 2005-11-13 16:07:51 -0800 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 30 | |
| 31 | #include "saa7134.h" |
| 32 | #include "saa7134-reg.h" |
| 33 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 34 | static unsigned int debug; |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 35 | module_param(debug, int, 0644); |
| 36 | MODULE_PARM_DESC(debug,"enable debug messages [alsa]"); |
| 37 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 38 | /* |
| 39 | * Configuration macros |
| 40 | */ |
| 41 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 42 | /* defaults */ |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 43 | #define MIXER_ADDR_UNSELECTED -1 |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 44 | #define MIXER_ADDR_TVTUNER 0 |
| 45 | #define MIXER_ADDR_LINE1 1 |
| 46 | #define MIXER_ADDR_LINE2 2 |
| 47 | #define MIXER_ADDR_LAST 2 |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 48 | |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 49 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 50 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 51 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Ricardo Cerqueira | ede2241 | 2006-02-27 00:08:11 -0300 | [diff] [blame] | 52 | static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 1}; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 53 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 54 | module_param_array(index, int, NULL, 0444); |
Ricardo Cerqueira | ede2241 | 2006-02-27 00:08:11 -0300 | [diff] [blame] | 55 | module_param_array(enable, int, NULL, 0444); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 56 | MODULE_PARM_DESC(index, "Index value for SAA7134 capture interface(s)."); |
Ricardo Cerqueira | ede2241 | 2006-02-27 00:08:11 -0300 | [diff] [blame] | 57 | MODULE_PARM_DESC(enable, "Enable (or not) the SAA7134 capture interface(s)."); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 58 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 59 | #define dprintk(fmt, arg...) if (debug) \ |
Jean Delvare | f85c657 | 2005-12-19 08:53:59 -0200 | [diff] [blame] | 60 | printk(KERN_DEBUG "%s/alsa: " fmt, dev->name , ##arg) |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 61 | |
| 62 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * Main chip structure |
| 66 | */ |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 67 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 68 | typedef struct snd_card_saa7134 { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 69 | struct snd_card *card; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 70 | spinlock_t mixer_lock; |
| 71 | int mixer_volume[MIXER_ADDR_LAST+1][2]; |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 72 | int capture_source_addr; |
| 73 | int capture_source[2]; |
| 74 | struct snd_kcontrol *capture_ctl[MIXER_ADDR_LAST+1]; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 75 | struct pci_dev *pci; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 76 | struct saa7134_dev *dev; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 77 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 78 | unsigned long iobase; |
Rafał Bilski | aac0ca6 | 2007-06-20 05:36:26 -0300 | [diff] [blame] | 79 | s16 irq; |
| 80 | u16 mute_was_on; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 81 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 82 | spinlock_t lock; |
| 83 | } snd_card_saa7134_t; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 84 | |
Nickolay V. Shmyrev | 07eef6c | 2005-11-08 21:38:14 -0800 | [diff] [blame] | 85 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 86 | /* |
| 87 | * PCM structure |
| 88 | */ |
| 89 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 90 | typedef struct snd_card_saa7134_pcm { |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 91 | struct saa7134_dev *dev; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 92 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 93 | spinlock_t lock; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 94 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 95 | struct snd_pcm_substream *substream; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 96 | } snd_card_saa7134_pcm_t; |
| 97 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 98 | static struct snd_card *snd_saa7134_cards[SNDRV_CARDS]; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 99 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 100 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 101 | /* |
| 102 | * saa7134 DMA audio stop |
| 103 | * |
| 104 | * Called when the capture device is released or the buffer overflows |
| 105 | * |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 106 | * - Copied verbatim from saa7134-oss's dsp_dma_stop. |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 107 | * |
| 108 | */ |
| 109 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 110 | static void saa7134_dma_stop(struct saa7134_dev *dev) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 111 | { |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 112 | dev->dmasound.dma_blk = -1; |
| 113 | dev->dmasound.dma_running = 0; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 114 | saa7134_set_dmabits(dev); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 117 | /* |
| 118 | * saa7134 DMA audio start |
| 119 | * |
| 120 | * Called when preparing the capture device for use |
| 121 | * |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 122 | * - Copied verbatim from saa7134-oss's dsp_dma_start. |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 123 | * |
| 124 | */ |
| 125 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 126 | static void saa7134_dma_start(struct saa7134_dev *dev) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 127 | { |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 128 | dev->dmasound.dma_blk = 0; |
| 129 | dev->dmasound.dma_running = 1; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 130 | saa7134_set_dmabits(dev); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 133 | /* |
| 134 | * saa7134 audio DMA IRQ handler |
| 135 | * |
| 136 | * Called whenever we get an SAA7134_IRQ_REPORT_DONE_RA3 interrupt |
| 137 | * Handles shifting between the 2 buffers, manages the read counters, |
| 138 | * and notifies ALSA when periods elapse |
| 139 | * |
| 140 | * - Mostly copied from saa7134-oss's saa7134_irq_oss_done. |
| 141 | * |
| 142 | */ |
| 143 | |
Adrian Bunk | 943a490 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 144 | static void saa7134_irq_alsa_done(struct saa7134_dev *dev, |
| 145 | unsigned long status) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 146 | { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 147 | int next_blk, reg = 0; |
| 148 | |
| 149 | spin_lock(&dev->slock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 150 | if (UNSET == dev->dmasound.dma_blk) { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 151 | dprintk("irq: recording stopped\n"); |
| 152 | goto done; |
| 153 | } |
| 154 | if (0 != (status & 0x0f000000)) |
| 155 | dprintk("irq: lost %ld\n", (status >> 24) & 0x0f); |
| 156 | if (0 == (status & 0x10000000)) { |
| 157 | /* odd */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 158 | if (0 == (dev->dmasound.dma_blk & 0x01)) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 159 | reg = SAA7134_RS_BA1(6); |
| 160 | } else { |
| 161 | /* even */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 162 | if (1 == (dev->dmasound.dma_blk & 0x01)) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 163 | reg = SAA7134_RS_BA2(6); |
| 164 | } |
| 165 | if (0 == reg) { |
| 166 | dprintk("irq: field oops [%s]\n", |
| 167 | (status & 0x10000000) ? "even" : "odd"); |
| 168 | goto done; |
| 169 | } |
| 170 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 171 | if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) { |
| 172 | dprintk("irq: overrun [full=%d/%d] - Blocks in %d\n",dev->dmasound.read_count, |
| 173 | dev->dmasound.bufsize, dev->dmasound.blocks); |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 174 | spin_unlock(&dev->slock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 175 | snd_pcm_stop(dev->dmasound.substream,SNDRV_PCM_STATE_XRUN); |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 176 | return; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 179 | /* next block addr */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 180 | next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks; |
| 181 | saa_writel(reg,next_blk * dev->dmasound.blksize); |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 182 | if (debug > 2) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 183 | dprintk("irq: ok, %s, next_blk=%d, addr=%x, blocks=%u, size=%u, read=%u\n", |
| 184 | (status & 0x10000000) ? "even" : "odd ", next_blk, |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 185 | next_blk * dev->dmasound.blksize, dev->dmasound.blocks, dev->dmasound.blksize, dev->dmasound.read_count); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 186 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 187 | /* update status & wake waiting readers */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 188 | dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks; |
| 189 | dev->dmasound.read_count += dev->dmasound.blksize; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 190 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 191 | dev->dmasound.recording_on = reg; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 192 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 193 | if (dev->dmasound.read_count >= snd_pcm_lib_period_bytes(dev->dmasound.substream)) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 194 | spin_unlock(&dev->slock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 195 | snd_pcm_period_elapsed(dev->dmasound.substream); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 196 | spin_lock(&dev->slock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 197 | } |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 198 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 199 | done: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 200 | spin_unlock(&dev->slock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 201 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 202 | } |
| 203 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 204 | /* |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 205 | * IRQ request handler |
| 206 | * |
| 207 | * Runs along with saa7134's IRQ handler, discards anything that isn't |
| 208 | * DMA sound |
| 209 | * |
| 210 | */ |
| 211 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 212 | static irqreturn_t saa7134_alsa_irq(int irq, void *dev_id) |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 213 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 214 | struct saa7134_dmasound *dmasound = dev_id; |
| 215 | struct saa7134_dev *dev = dmasound->priv_data; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 216 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 217 | unsigned long report, status; |
| 218 | int loop, handled = 0; |
| 219 | |
| 220 | for (loop = 0; loop < 10; loop++) { |
| 221 | report = saa_readl(SAA7134_IRQ_REPORT); |
| 222 | status = saa_readl(SAA7134_IRQ_STATUS); |
| 223 | |
| 224 | if (report & SAA7134_IRQ_REPORT_DONE_RA3) { |
| 225 | handled = 1; |
Heikki Lindholm | 843b137 | 2007-11-30 13:27:26 -0300 | [diff] [blame] | 226 | saa_writel(SAA7134_IRQ_REPORT, |
| 227 | SAA7134_IRQ_REPORT_DONE_RA3); |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 228 | saa7134_irq_alsa_done(dev, status); |
| 229 | } else { |
| 230 | goto out; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | if (loop == 10) { |
| 235 | dprintk("error! looping IRQ!"); |
| 236 | } |
| 237 | |
| 238 | out: |
| 239 | return IRQ_RETVAL(handled); |
| 240 | } |
| 241 | |
| 242 | /* |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 243 | * ALSA capture trigger |
| 244 | * |
| 245 | * - One of the ALSA capture callbacks. |
| 246 | * |
| 247 | * Called whenever a capture is started or stopped. Must be defined, |
| 248 | * but there's nothing we want to do here |
| 249 | * |
| 250 | */ |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 251 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 252 | static int snd_card_saa7134_capture_trigger(struct snd_pcm_substream * substream, |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 253 | int cmd) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 254 | { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 255 | struct snd_pcm_runtime *runtime = substream->runtime; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 256 | snd_card_saa7134_pcm_t *pcm = runtime->private_data; |
| 257 | struct saa7134_dev *dev=pcm->dev; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 258 | int err = 0; |
| 259 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 260 | spin_lock(&dev->slock); |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 261 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 262 | /* start dma */ |
| 263 | saa7134_dma_start(dev); |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 264 | } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 265 | /* stop dma */ |
| 266 | saa7134_dma_stop(dev); |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 267 | } else { |
| 268 | err = -EINVAL; |
| 269 | } |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 270 | spin_unlock(&dev->slock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 271 | |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 272 | return err; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 275 | /* |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 276 | * DMA buffer initialization |
| 277 | * |
| 278 | * Uses V4L functions to initialize the DMA. Shouldn't be necessary in |
| 279 | * ALSA, but I was unable to use ALSA's own DMA, and had to force the |
| 280 | * usage of V4L's |
| 281 | * |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 282 | * - Copied verbatim from saa7134-oss. |
| 283 | * |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 284 | */ |
| 285 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 286 | static int dsp_buffer_init(struct saa7134_dev *dev) |
| 287 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 288 | int err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 289 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 290 | BUG_ON(!dev->dmasound.bufsize); |
| 291 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 292 | videobuf_dma_init(&dev->dmasound.dma); |
| 293 | err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE, |
| 294 | (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 295 | if (0 != err) |
| 296 | return err; |
| 297 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 298 | } |
| 299 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 300 | /* |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 301 | * DMA buffer release |
| 302 | * |
| 303 | * Called after closing the device, during snd_card_saa7134_capture_close |
| 304 | * |
| 305 | */ |
| 306 | |
| 307 | static int dsp_buffer_free(struct saa7134_dev *dev) |
| 308 | { |
Eric Sesterhenn | ae24601 | 2006-03-13 13:17:11 -0300 | [diff] [blame] | 309 | BUG_ON(!dev->dmasound.blksize); |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 310 | |
| 311 | videobuf_dma_free(&dev->dmasound.dma); |
| 312 | |
| 313 | dev->dmasound.blocks = 0; |
| 314 | dev->dmasound.blksize = 0; |
| 315 | dev->dmasound.bufsize = 0; |
| 316 | |
Michael Krufky | b930e1d | 2007-08-27 18:16:54 -0300 | [diff] [blame] | 317 | return 0; |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 320 | /* |
| 321 | * Setting the capture source and updating the ALSA controls |
| 322 | */ |
| 323 | static int snd_saa7134_capsrc_set(struct snd_kcontrol *kcontrol, |
| 324 | int left, int right, bool force_notify) |
| 325 | { |
| 326 | snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
| 327 | int change = 0, addr = kcontrol->private_value; |
| 328 | int active, old_addr; |
| 329 | u32 anabar, xbarin; |
| 330 | int analog_io, rate; |
| 331 | struct saa7134_dev *dev; |
| 332 | |
| 333 | dev = chip->dev; |
| 334 | |
| 335 | spin_lock_irq(&chip->mixer_lock); |
| 336 | |
| 337 | active = left != 0 || right != 0; |
| 338 | old_addr = chip->capture_source_addr; |
| 339 | |
| 340 | /* The active capture source cannot be deactivated */ |
| 341 | if (active) { |
| 342 | change = old_addr != addr || |
| 343 | chip->capture_source[0] != left || |
| 344 | chip->capture_source[1] != right; |
| 345 | |
| 346 | chip->capture_source[0] = left; |
| 347 | chip->capture_source[1] = right; |
| 348 | chip->capture_source_addr = addr; |
| 349 | dev->dmasound.input = addr; |
| 350 | } |
| 351 | spin_unlock_irq(&chip->mixer_lock); |
| 352 | |
| 353 | if (change) { |
| 354 | switch (dev->pci->device) { |
| 355 | |
| 356 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
| 357 | switch (addr) { |
| 358 | case MIXER_ADDR_TVTUNER: |
| 359 | saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, |
| 360 | 0xc0, 0xc0); |
| 361 | saa_andorb(SAA7134_SIF_SAMPLE_FREQ, |
| 362 | 0x03, 0x00); |
| 363 | break; |
| 364 | case MIXER_ADDR_LINE1: |
| 365 | case MIXER_ADDR_LINE2: |
| 366 | analog_io = (MIXER_ADDR_LINE1 == addr) ? |
| 367 | 0x00 : 0x08; |
| 368 | rate = (32000 == dev->dmasound.rate) ? |
| 369 | 0x01 : 0x03; |
| 370 | saa_andorb(SAA7134_ANALOG_IO_SELECT, |
| 371 | 0x08, analog_io); |
| 372 | saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, |
| 373 | 0xc0, 0x80); |
| 374 | saa_andorb(SAA7134_SIF_SAMPLE_FREQ, |
| 375 | 0x03, rate); |
| 376 | break; |
| 377 | } |
| 378 | |
| 379 | break; |
| 380 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 381 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
| 382 | xbarin = 0x03; /* adc */ |
| 383 | anabar = 0; |
| 384 | switch (addr) { |
| 385 | case MIXER_ADDR_TVTUNER: |
| 386 | xbarin = 0; /* Demodulator */ |
| 387 | anabar = 2; /* DACs */ |
| 388 | break; |
| 389 | case MIXER_ADDR_LINE1: |
| 390 | anabar = 0; /* aux1, aux1 */ |
| 391 | break; |
| 392 | case MIXER_ADDR_LINE2: |
| 393 | anabar = 9; /* aux2, aux2 */ |
| 394 | break; |
| 395 | } |
| 396 | |
| 397 | /* output xbar always main channel */ |
| 398 | saa_dsp_writel(dev, SAA7133_DIGITAL_OUTPUT_SEL1, |
| 399 | 0xbbbb10); |
| 400 | |
| 401 | if (left || right) { |
| 402 | /* We've got data, turn the input on */ |
| 403 | saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, |
| 404 | xbarin); |
| 405 | saa_writel(SAA7133_ANALOG_IO_SELECT, anabar); |
| 406 | } else { |
| 407 | saa_dsp_writel(dev, SAA7133_DIGITAL_INPUT_XBAR1, |
| 408 | 0); |
| 409 | saa_writel(SAA7133_ANALOG_IO_SELECT, 0); |
| 410 | } |
| 411 | break; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | if (change) { |
| 416 | if (force_notify) |
| 417 | snd_ctl_notify(chip->card, |
| 418 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 419 | &chip->capture_ctl[addr]->id); |
| 420 | |
| 421 | if (old_addr != MIXER_ADDR_UNSELECTED && old_addr != addr) |
| 422 | snd_ctl_notify(chip->card, |
| 423 | SNDRV_CTL_EVENT_MASK_VALUE, |
| 424 | &chip->capture_ctl[old_addr]->id); |
| 425 | } |
| 426 | |
| 427 | return change; |
| 428 | } |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 429 | |
| 430 | /* |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 431 | * ALSA PCM preparation |
| 432 | * |
| 433 | * - One of the ALSA capture callbacks. |
| 434 | * |
| 435 | * Called right after the capture device is opened, this function configures |
| 436 | * the buffer using the previously defined functions, allocates the memory, |
| 437 | * sets up the hardware registers, and then starts the DMA. When this function |
| 438 | * returns, the audio should be flowing. |
| 439 | * |
| 440 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 441 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 442 | static int snd_card_saa7134_capture_prepare(struct snd_pcm_substream * substream) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 443 | { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 444 | struct snd_pcm_runtime *runtime = substream->runtime; |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 445 | int bswap, sign; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 446 | u32 fmt, control; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 447 | snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 448 | struct saa7134_dev *dev; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 449 | snd_card_saa7134_pcm_t *pcm = runtime->private_data; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 450 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 451 | pcm->dev->dmasound.substream = substream; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 452 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 453 | dev = saa7134->dev; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 454 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 455 | if (snd_pcm_format_width(runtime->format) == 8) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 456 | fmt = 0x00; |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 457 | else |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 458 | fmt = 0x01; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 459 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 460 | if (snd_pcm_format_signed(runtime->format)) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 461 | sign = 1; |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 462 | else |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 463 | sign = 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 464 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 465 | if (snd_pcm_format_big_endian(runtime->format)) |
| 466 | bswap = 1; |
| 467 | else |
| 468 | bswap = 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 469 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 470 | switch (dev->pci->device) { |
| 471 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
| 472 | if (1 == runtime->channels) |
| 473 | fmt |= (1 << 3); |
| 474 | if (2 == runtime->channels) |
| 475 | fmt |= (3 << 3); |
| 476 | if (sign) |
| 477 | fmt |= 0x04; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 478 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 479 | fmt |= (MIXER_ADDR_TVTUNER == dev->dmasound.input) ? 0xc0 : 0x80; |
| 480 | saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->dmasound.blksize - 1) & 0x0000ff)); |
| 481 | saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->dmasound.blksize - 1) & 0x00ff00) >> 8); |
| 482 | saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->dmasound.blksize - 1) & 0xff0000) >> 16); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 483 | saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 484 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 485 | break; |
| 486 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 487 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
| 488 | if (1 == runtime->channels) |
| 489 | fmt |= (1 << 4); |
| 490 | if (2 == runtime->channels) |
| 491 | fmt |= (2 << 4); |
| 492 | if (!sign) |
| 493 | fmt |= 0x04; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 494 | saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -1); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 495 | saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24)); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 496 | break; |
| 497 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 498 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 499 | dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n", |
| 500 | runtime->format, runtime->channels, fmt, |
| 501 | bswap ? 'b' : '-'); |
| 502 | /* dma: setup channel 6 (= AUDIO) */ |
| 503 | control = SAA7134_RS_CONTROL_BURST_16 | |
| 504 | SAA7134_RS_CONTROL_ME | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 505 | (dev->dmasound.pt.dma >> 12); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 506 | if (bswap) |
| 507 | control |= SAA7134_RS_CONTROL_BSWAP; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 508 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 509 | saa_writel(SAA7134_RS_BA1(6),0); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 510 | saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 511 | saa_writel(SAA7134_RS_PITCH(6),0); |
| 512 | saa_writel(SAA7134_RS_CONTROL(6),control); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 513 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 514 | dev->dmasound.rate = runtime->rate; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 515 | |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 516 | /* Setup and update the card/ALSA controls */ |
| 517 | snd_saa7134_capsrc_set(saa7134->capture_ctl[dev->dmasound.input], 1, 1, |
| 518 | true); |
| 519 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 520 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 521 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 522 | } |
| 523 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 524 | /* |
| 525 | * ALSA pointer fetching |
| 526 | * |
| 527 | * - One of the ALSA capture callbacks. |
| 528 | * |
| 529 | * Called whenever a period elapses, it must return the current hardware |
| 530 | * position of the buffer. |
| 531 | * Also resets the read counter used to prevent overruns |
| 532 | * |
| 533 | */ |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 534 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 535 | static snd_pcm_uframes_t |
| 536 | snd_card_saa7134_capture_pointer(struct snd_pcm_substream * substream) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 537 | { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 538 | struct snd_pcm_runtime *runtime = substream->runtime; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 539 | snd_card_saa7134_pcm_t *pcm = runtime->private_data; |
| 540 | struct saa7134_dev *dev=pcm->dev; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 541 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 542 | if (dev->dmasound.read_count) { |
| 543 | dev->dmasound.read_count -= snd_pcm_lib_period_bytes(substream); |
| 544 | dev->dmasound.read_offset += snd_pcm_lib_period_bytes(substream); |
| 545 | if (dev->dmasound.read_offset == dev->dmasound.bufsize) |
| 546 | dev->dmasound.read_offset = 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 549 | return bytes_to_frames(runtime, dev->dmasound.read_offset); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 550 | } |
| 551 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 552 | /* |
| 553 | * ALSA hardware capabilities definition |
Oldřich Jedlička | 7b54360 | 2009-08-18 16:24:54 -0300 | [diff] [blame] | 554 | * |
| 555 | * Report only 32kHz for ALSA: |
| 556 | * |
| 557 | * - SAA7133/35 uses DDEP (DemDec Easy Programming mode), which works in 32kHz |
| 558 | * only |
| 559 | * - SAA7134 for TV mode uses DemDec mode (32kHz) |
| 560 | * - Radio works in 32kHz only |
| 561 | * - When recording 48kHz from Line1/Line2, switching of capture source to TV |
| 562 | * means |
| 563 | * switching to 32kHz without any frequency translation |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 564 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 565 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 566 | static struct snd_pcm_hardware snd_card_saa7134_capture = |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 567 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 568 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
Mauro Carvalho Chehab | f2421ca | 2005-11-08 21:37:45 -0800 | [diff] [blame] | 569 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 570 | SNDRV_PCM_INFO_MMAP_VALID), |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 571 | .formats = SNDRV_PCM_FMTBIT_S16_LE | \ |
| 572 | SNDRV_PCM_FMTBIT_S16_BE | \ |
| 573 | SNDRV_PCM_FMTBIT_S8 | \ |
| 574 | SNDRV_PCM_FMTBIT_U8 | \ |
| 575 | SNDRV_PCM_FMTBIT_U16_LE | \ |
| 576 | SNDRV_PCM_FMTBIT_U16_BE, |
Oldřich Jedlička | 7b54360 | 2009-08-18 16:24:54 -0300 | [diff] [blame] | 577 | .rates = SNDRV_PCM_RATE_32000, |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 578 | .rate_min = 32000, |
Oldřich Jedlička | 7b54360 | 2009-08-18 16:24:54 -0300 | [diff] [blame] | 579 | .rate_max = 32000, |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 580 | .channels_min = 1, |
| 581 | .channels_max = 2, |
| 582 | .buffer_bytes_max = (256*1024), |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 583 | .period_bytes_min = 64, |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 584 | .period_bytes_max = (256*1024), |
Heikki Lindholm | 174eb8e | 2007-11-23 18:59:18 -0300 | [diff] [blame] | 585 | .periods_min = 4, |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 586 | .periods_max = 1024, |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 587 | }; |
| 588 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 589 | static void snd_card_saa7134_runtime_free(struct snd_pcm_runtime *runtime) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 590 | { |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 591 | snd_card_saa7134_pcm_t *pcm = runtime->private_data; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 592 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 593 | kfree(pcm); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 597 | /* |
| 598 | * ALSA hardware params |
| 599 | * |
| 600 | * - One of the ALSA capture callbacks. |
| 601 | * |
| 602 | * Called on initialization, right before the PCM preparation |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 603 | * |
| 604 | */ |
| 605 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 606 | static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream, |
| 607 | struct snd_pcm_hw_params * hw_params) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 608 | { |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 609 | snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); |
| 610 | struct saa7134_dev *dev; |
| 611 | unsigned int period_size, periods; |
| 612 | int err; |
| 613 | |
| 614 | period_size = params_period_bytes(hw_params); |
| 615 | periods = params_periods(hw_params); |
| 616 | |
Takashi Iwai | 5e246b8 | 2008-08-08 17:12:47 +0200 | [diff] [blame] | 617 | if (period_size < 0x100 || period_size > 0x10000) |
| 618 | return -EINVAL; |
| 619 | if (periods < 4) |
| 620 | return -EINVAL; |
| 621 | if (period_size * periods > 1024 * 1024) |
| 622 | return -EINVAL; |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 623 | |
| 624 | dev = saa7134->dev; |
| 625 | |
| 626 | if (dev->dmasound.blocks == periods && |
| 627 | dev->dmasound.blksize == period_size) |
| 628 | return 0; |
| 629 | |
| 630 | /* release the old buffer */ |
| 631 | if (substream->runtime->dma_area) { |
| 632 | saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 633 | videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 634 | dsp_buffer_free(dev); |
| 635 | substream->runtime->dma_area = NULL; |
| 636 | } |
| 637 | dev->dmasound.blocks = periods; |
| 638 | dev->dmasound.blksize = period_size; |
| 639 | dev->dmasound.bufsize = period_size * periods; |
| 640 | |
| 641 | err = dsp_buffer_init(dev); |
| 642 | if (0 != err) { |
| 643 | dev->dmasound.blocks = 0; |
| 644 | dev->dmasound.blksize = 0; |
| 645 | dev->dmasound.bufsize = 0; |
| 646 | return err; |
| 647 | } |
| 648 | |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 649 | if (0 != (err = videobuf_dma_map(&dev->pci->dev, &dev->dmasound.dma))) { |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 650 | dsp_buffer_free(dev); |
| 651 | return err; |
| 652 | } |
| 653 | if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) { |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 654 | videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 655 | dsp_buffer_free(dev); |
| 656 | return err; |
| 657 | } |
| 658 | if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->dmasound.pt, |
| 659 | dev->dmasound.dma.sglist, |
| 660 | dev->dmasound.dma.sglen, |
| 661 | 0))) { |
| 662 | saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 663 | videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 664 | dsp_buffer_free(dev); |
| 665 | return err; |
| 666 | } |
| 667 | |
| 668 | /* I should be able to use runtime->dma_addr in the control |
| 669 | byte, but it doesn't work. So I allocate the DMA using the |
| 670 | V4L functions, and force ALSA to use that as the DMA area */ |
| 671 | |
Laurent Pinchart | bb6dbe7 | 2010-05-11 10:36:34 -0300 | [diff] [blame] | 672 | substream->runtime->dma_area = dev->dmasound.dma.vaddr; |
Alexander E. Patrakov | 32d111a | 2007-10-31 11:40:09 -0300 | [diff] [blame] | 673 | substream->runtime->dma_bytes = dev->dmasound.bufsize; |
| 674 | substream->runtime->dma_addr = 0; |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 675 | |
Alexander E. Patrakov | 32d111a | 2007-10-31 11:40:09 -0300 | [diff] [blame] | 676 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 677 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 678 | } |
| 679 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 680 | /* |
| 681 | * ALSA hardware release |
| 682 | * |
| 683 | * - One of the ALSA capture callbacks. |
| 684 | * |
| 685 | * Called after closing the device, but before snd_card_saa7134_capture_close |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 686 | * It stops the DMA audio and releases the buffers. |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 687 | * |
| 688 | */ |
| 689 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 690 | static int snd_card_saa7134_hw_free(struct snd_pcm_substream * substream) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 691 | { |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 692 | snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); |
| 693 | struct saa7134_dev *dev; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 694 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 695 | dev = saa7134->dev; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 696 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 697 | if (substream->runtime->dma_area) { |
| 698 | saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); |
Laurent Pinchart | 9526840 | 2010-05-11 10:36:30 -0300 | [diff] [blame] | 699 | videobuf_dma_unmap(&dev->pci->dev, &dev->dmasound.dma); |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 700 | dsp_buffer_free(dev); |
| 701 | substream->runtime->dma_area = NULL; |
| 702 | } |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 703 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 704 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 705 | } |
| 706 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 707 | /* |
| 708 | * ALSA capture finish |
| 709 | * |
| 710 | * - One of the ALSA capture callbacks. |
| 711 | * |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 712 | * Called after closing the device. |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 713 | * |
| 714 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 715 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 716 | static int snd_card_saa7134_capture_close(struct snd_pcm_substream * substream) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 717 | { |
Ricardo Cerqueira | dafcaaf | 2006-09-06 06:25:38 -0300 | [diff] [blame] | 718 | snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); |
| 719 | struct saa7134_dev *dev = saa7134->dev; |
| 720 | |
Rafał Bilski | aac0ca6 | 2007-06-20 05:36:26 -0300 | [diff] [blame] | 721 | if (saa7134->mute_was_on) { |
| 722 | dev->ctl_mute = 1; |
| 723 | saa7134_tvaudio_setmute(dev); |
| 724 | } |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 725 | return 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 726 | } |
| 727 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 728 | /* |
| 729 | * ALSA capture start |
| 730 | * |
| 731 | * - One of the ALSA capture callbacks. |
| 732 | * |
| 733 | * Called when opening the device. It creates and populates the PCM |
| 734 | * structure |
| 735 | * |
| 736 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 737 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 738 | static int snd_card_saa7134_capture_open(struct snd_pcm_substream * substream) |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 739 | { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 740 | struct snd_pcm_runtime *runtime = substream->runtime; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 741 | snd_card_saa7134_pcm_t *pcm; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 742 | snd_card_saa7134_t *saa7134 = snd_pcm_substream_chip(substream); |
Mauro Carvalho Chehab | 83ee87a | 2008-06-14 09:41:18 -0300 | [diff] [blame] | 743 | struct saa7134_dev *dev; |
Hartmut Hackmann | 5cfbacd | 2006-11-21 19:59:27 -0300 | [diff] [blame] | 744 | int amux, err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 745 | |
Mauro Carvalho Chehab | 83ee87a | 2008-06-14 09:41:18 -0300 | [diff] [blame] | 746 | if (!saa7134) { |
| 747 | printk(KERN_ERR "BUG: saa7134 can't find device struct." |
| 748 | " Can't proceed with open\n"); |
| 749 | return -ENODEV; |
| 750 | } |
| 751 | dev = saa7134->dev; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 752 | mutex_lock(&dev->dmasound.lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 753 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 754 | dev->dmasound.read_count = 0; |
| 755 | dev->dmasound.read_offset = 0; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 756 | |
Hartmut Hackmann | 5cfbacd | 2006-11-21 19:59:27 -0300 | [diff] [blame] | 757 | amux = dev->input->amux; |
| 758 | if ((amux < 1) || (amux > 3)) |
| 759 | amux = 1; |
| 760 | dev->dmasound.input = amux - 1; |
| 761 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 762 | mutex_unlock(&dev->dmasound.lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 763 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 764 | pcm = kzalloc(sizeof(*pcm), GFP_KERNEL); |
| 765 | if (pcm == NULL) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 766 | return -ENOMEM; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 767 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 768 | pcm->dev=saa7134->dev; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 769 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 770 | spin_lock_init(&pcm->lock); |
| 771 | |
| 772 | pcm->substream = substream; |
| 773 | runtime->private_data = pcm; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 774 | runtime->private_free = snd_card_saa7134_runtime_free; |
| 775 | runtime->hw = snd_card_saa7134_capture; |
| 776 | |
Rafał Bilski | aac0ca6 | 2007-06-20 05:36:26 -0300 | [diff] [blame] | 777 | if (dev->ctl_mute != 0) { |
| 778 | saa7134->mute_was_on = 1; |
| 779 | dev->ctl_mute = 0; |
| 780 | saa7134_tvaudio_setmute(dev); |
| 781 | } |
Ricardo Cerqueira | dafcaaf | 2006-09-06 06:25:38 -0300 | [diff] [blame] | 782 | |
Heikki Lindholm | 174eb8e | 2007-11-23 18:59:18 -0300 | [diff] [blame] | 783 | err = snd_pcm_hw_constraint_integer(runtime, |
| 784 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 785 | if (err < 0) |
| 786 | return err; |
| 787 | |
| 788 | err = snd_pcm_hw_constraint_step(runtime, 0, |
| 789 | SNDRV_PCM_HW_PARAM_PERIODS, 2); |
| 790 | if (err < 0) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 791 | return err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 796 | /* |
Alexander E. Patrakov | 32d111a | 2007-10-31 11:40:09 -0300 | [diff] [blame] | 797 | * page callback (needed for mmap) |
| 798 | */ |
| 799 | |
| 800 | static struct page *snd_card_saa7134_page(struct snd_pcm_substream *substream, |
| 801 | unsigned long offset) |
| 802 | { |
| 803 | void *pageptr = substream->runtime->dma_area + offset; |
| 804 | return vmalloc_to_page(pageptr); |
| 805 | } |
| 806 | |
| 807 | /* |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 808 | * ALSA capture callbacks definition |
| 809 | */ |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 810 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 811 | static struct snd_pcm_ops snd_card_saa7134_capture_ops = { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 812 | .open = snd_card_saa7134_capture_open, |
| 813 | .close = snd_card_saa7134_capture_close, |
| 814 | .ioctl = snd_pcm_lib_ioctl, |
| 815 | .hw_params = snd_card_saa7134_hw_params, |
| 816 | .hw_free = snd_card_saa7134_hw_free, |
| 817 | .prepare = snd_card_saa7134_capture_prepare, |
| 818 | .trigger = snd_card_saa7134_capture_trigger, |
| 819 | .pointer = snd_card_saa7134_capture_pointer, |
Alexander E. Patrakov | 32d111a | 2007-10-31 11:40:09 -0300 | [diff] [blame] | 820 | .page = snd_card_saa7134_page, |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 821 | }; |
| 822 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 823 | /* |
| 824 | * ALSA PCM setup |
| 825 | * |
| 826 | * Called when initializing the board. Sets up the name and hooks up |
| 827 | * the callbacks |
| 828 | * |
| 829 | */ |
| 830 | |
| 831 | 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] | 832 | { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 833 | struct snd_pcm *pcm; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 834 | int err; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 835 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 836 | 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] | 837 | return err; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 838 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_saa7134_capture_ops); |
| 839 | pcm->private_data = saa7134; |
| 840 | pcm->info_flags = 0; |
| 841 | strcpy(pcm->name, "SAA7134 PCM"); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 842 | return 0; |
| 843 | } |
| 844 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 845 | #define SAA713x_VOLUME(xname, xindex, addr) \ |
| 846 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 847 | .info = snd_saa7134_volume_info, \ |
| 848 | .get = snd_saa7134_volume_get, .put = snd_saa7134_volume_put, \ |
| 849 | .private_value = addr } |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 850 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 851 | static int snd_saa7134_volume_info(struct snd_kcontrol * kcontrol, |
| 852 | struct snd_ctl_elem_info * uinfo) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 853 | { |
| 854 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 855 | uinfo->count = 2; |
| 856 | uinfo->value.integer.min = 0; |
| 857 | uinfo->value.integer.max = 20; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 858 | return 0; |
| 859 | } |
| 860 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 861 | static int snd_saa7134_volume_get(struct snd_kcontrol * kcontrol, |
| 862 | struct snd_ctl_elem_value * ucontrol) |
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_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 865 | int addr = kcontrol->private_value; |
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 | ucontrol->value.integer.value[0] = chip->mixer_volume[addr][0]; |
| 868 | ucontrol->value.integer.value[1] = chip->mixer_volume[addr][1]; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 869 | return 0; |
| 870 | } |
| 871 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 872 | static int snd_saa7134_volume_put(struct snd_kcontrol * kcontrol, |
| 873 | struct snd_ctl_elem_value * ucontrol) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 874 | { |
| 875 | snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
Hartmut Hackmann | 5cfbacd | 2006-11-21 19:59:27 -0300 | [diff] [blame] | 876 | struct saa7134_dev *dev = chip->dev; |
| 877 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 878 | int change, addr = kcontrol->private_value; |
| 879 | int left, right; |
| 880 | |
| 881 | left = ucontrol->value.integer.value[0]; |
| 882 | if (left < 0) |
| 883 | left = 0; |
| 884 | if (left > 20) |
| 885 | left = 20; |
| 886 | right = ucontrol->value.integer.value[1]; |
| 887 | if (right < 0) |
| 888 | right = 0; |
| 889 | if (right > 20) |
| 890 | right = 20; |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 891 | spin_lock_irq(&chip->mixer_lock); |
Hartmut Hackmann | 5cfbacd | 2006-11-21 19:59:27 -0300 | [diff] [blame] | 892 | change = 0; |
| 893 | if (chip->mixer_volume[addr][0] != left) { |
| 894 | change = 1; |
| 895 | right = left; |
| 896 | } |
| 897 | if (chip->mixer_volume[addr][1] != right) { |
| 898 | change = 1; |
| 899 | left = right; |
| 900 | } |
| 901 | if (change) { |
| 902 | switch (dev->pci->device) { |
| 903 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
| 904 | switch (addr) { |
| 905 | case MIXER_ADDR_TVTUNER: |
| 906 | left = 20; |
| 907 | break; |
| 908 | case MIXER_ADDR_LINE1: |
| 909 | saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10, |
| 910 | (left > 10) ? 0x00 : 0x10); |
| 911 | break; |
| 912 | case MIXER_ADDR_LINE2: |
| 913 | saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20, |
| 914 | (left > 10) ? 0x00 : 0x20); |
| 915 | break; |
| 916 | } |
| 917 | break; |
| 918 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 919 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
| 920 | switch (addr) { |
| 921 | case MIXER_ADDR_TVTUNER: |
| 922 | left = 20; |
| 923 | break; |
| 924 | case MIXER_ADDR_LINE1: |
| 925 | saa_andorb(0x0594, 0x10, |
| 926 | (left > 10) ? 0x00 : 0x10); |
| 927 | break; |
| 928 | case MIXER_ADDR_LINE2: |
| 929 | saa_andorb(0x0594, 0x20, |
| 930 | (left > 10) ? 0x00 : 0x20); |
| 931 | break; |
| 932 | } |
| 933 | break; |
| 934 | } |
| 935 | chip->mixer_volume[addr][0] = left; |
| 936 | chip->mixer_volume[addr][1] = right; |
| 937 | } |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 938 | spin_unlock_irq(&chip->mixer_lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 939 | return change; |
| 940 | } |
| 941 | |
| 942 | #define SAA713x_CAPSRC(xname, xindex, addr) \ |
| 943 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 944 | .info = snd_saa7134_capsrc_info, \ |
| 945 | .get = snd_saa7134_capsrc_get, .put = snd_saa7134_capsrc_put, \ |
| 946 | .private_value = addr } |
| 947 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 948 | static int snd_saa7134_capsrc_info(struct snd_kcontrol * kcontrol, |
| 949 | struct snd_ctl_elem_info * uinfo) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 950 | { |
| 951 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 952 | uinfo->count = 2; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 953 | uinfo->value.integer.min = 0; |
| 954 | uinfo->value.integer.max = 1; |
| 955 | return 0; |
| 956 | } |
| 957 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 958 | static int snd_saa7134_capsrc_get(struct snd_kcontrol * kcontrol, |
| 959 | struct snd_ctl_elem_value * ucontrol) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 960 | { |
| 961 | snd_card_saa7134_t *chip = snd_kcontrol_chip(kcontrol); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 962 | int addr = kcontrol->private_value; |
| 963 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 964 | spin_lock_irq(&chip->mixer_lock); |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 965 | if (chip->capture_source_addr == addr) { |
| 966 | ucontrol->value.integer.value[0] = chip->capture_source[0]; |
| 967 | ucontrol->value.integer.value[1] = chip->capture_source[1]; |
| 968 | } else { |
| 969 | ucontrol->value.integer.value[0] = 0; |
| 970 | ucontrol->value.integer.value[1] = 0; |
| 971 | } |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 972 | spin_unlock_irq(&chip->mixer_lock); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 973 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 974 | return 0; |
| 975 | } |
| 976 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 977 | static int snd_saa7134_capsrc_put(struct snd_kcontrol * kcontrol, |
| 978 | struct snd_ctl_elem_value * ucontrol) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 979 | { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 980 | int left, right; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 981 | left = ucontrol->value.integer.value[0] & 1; |
| 982 | right = ucontrol->value.integer.value[1] & 1; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 983 | |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 984 | return snd_saa7134_capsrc_set(kcontrol, left, right, false); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 985 | } |
| 986 | |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 987 | static struct snd_kcontrol_new snd_saa7134_volume_controls[] = { |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 988 | SAA713x_VOLUME("Video Volume", 0, MIXER_ADDR_TVTUNER), |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 989 | SAA713x_VOLUME("Line Volume", 1, MIXER_ADDR_LINE1), |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 990 | SAA713x_VOLUME("Line Volume", 2, MIXER_ADDR_LINE2), |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 991 | }; |
| 992 | |
| 993 | static struct snd_kcontrol_new snd_saa7134_capture_controls[] = { |
| 994 | SAA713x_CAPSRC("Video Capture Switch", 0, MIXER_ADDR_TVTUNER), |
| 995 | SAA713x_CAPSRC("Line Capture Switch", 1, MIXER_ADDR_LINE1), |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 996 | SAA713x_CAPSRC("Line Capture Switch", 2, MIXER_ADDR_LINE2), |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 997 | }; |
| 998 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 999 | /* |
| 1000 | * ALSA mixer setup |
| 1001 | * |
| 1002 | * Called when initializing the board. Sets up the name and hooks up |
| 1003 | * the callbacks |
| 1004 | * |
| 1005 | */ |
| 1006 | |
| 1007 | 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] | 1008 | { |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 1009 | struct snd_card *card = chip->card; |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 1010 | struct snd_kcontrol *kcontrol; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1011 | unsigned int idx; |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 1012 | int err, addr; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1013 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1014 | strcpy(card->mixername, "SAA7134 Mixer"); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1015 | |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 1016 | for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_volume_controls); idx++) { |
| 1017 | kcontrol = snd_ctl_new1(&snd_saa7134_volume_controls[idx], |
| 1018 | chip); |
| 1019 | err = snd_ctl_add(card, kcontrol); |
| 1020 | if (err < 0) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1021 | return err; |
| 1022 | } |
Oldřich Jedlička | 736dada | 2009-08-22 15:13:51 -0300 | [diff] [blame] | 1023 | |
| 1024 | for (idx = 0; idx < ARRAY_SIZE(snd_saa7134_capture_controls); idx++) { |
| 1025 | kcontrol = snd_ctl_new1(&snd_saa7134_capture_controls[idx], |
| 1026 | chip); |
| 1027 | addr = snd_saa7134_capture_controls[idx].private_value; |
| 1028 | chip->capture_ctl[addr] = kcontrol; |
| 1029 | err = snd_ctl_add(card, kcontrol); |
| 1030 | if (err < 0) |
| 1031 | return err; |
| 1032 | } |
| 1033 | |
| 1034 | chip->capture_source_addr = MIXER_ADDR_UNSELECTED; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1035 | return 0; |
| 1036 | } |
| 1037 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 1038 | static void snd_saa7134_free(struct snd_card * card) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1039 | { |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 1040 | snd_card_saa7134_t *chip = card->private_data; |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 1041 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1042 | if (chip->dev->dmasound.priv_data == NULL) |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 1043 | return; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1044 | |
Jeff Garzik | f000fd8 | 2008-04-22 13:50:34 +0200 | [diff] [blame] | 1045 | if (chip->irq >= 0) |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1046 | free_irq(chip->irq, &chip->dev->dmasound); |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 1047 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1048 | chip->dev->dmasound.priv_data = NULL; |
| 1049 | |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1050 | } |
| 1051 | |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 1052 | /* |
| 1053 | * ALSA initialization |
| 1054 | * |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 1055 | * Called by the init routine, once for each saa7134 device present, |
| 1056 | * it creates the basic structures and registers the ALSA devices |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 1057 | * |
| 1058 | */ |
| 1059 | |
Adrian Bunk | 943a490 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 1060 | static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum) |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1061 | { |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1062 | |
Takashi Iwai | f7cbb7f | 2006-01-13 18:48:06 +0100 | [diff] [blame] | 1063 | struct snd_card *card; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 1064 | snd_card_saa7134_t *chip; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1065 | int err; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1066 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1067 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1068 | if (devnum >= SNDRV_CARDS) |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1069 | return -ENODEV; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1070 | if (!enable[devnum]) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1071 | return -ENODEV; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 1072 | |
Takashi Iwai | 758021b | 2009-01-12 15:17:09 +0100 | [diff] [blame] | 1073 | err = snd_card_create(index[devnum], id[devnum], THIS_MODULE, |
| 1074 | sizeof(snd_card_saa7134_t), &card); |
| 1075 | if (err < 0) |
| 1076 | return err; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1077 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1078 | strcpy(card->driver, "SAA7134"); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1079 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1080 | /* Card "creation" */ |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 1081 | |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 1082 | card->private_free = snd_saa7134_free; |
Joe Perches | abf8438 | 2010-07-12 17:50:03 -0300 | [diff] [blame] | 1083 | chip = card->private_data; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1084 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1085 | spin_lock_init(&chip->lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 1086 | spin_lock_init(&chip->mixer_lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1087 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1088 | chip->dev = dev; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1089 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1090 | chip->card = card; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 1091 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1092 | chip->pci = dev->pci; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1093 | chip->iobase = pci_resource_start(dev->pci, 0); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1094 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1095 | |
| 1096 | err = request_irq(dev->pci->irq, saa7134_alsa_irq, |
Thomas Gleixner | 8076fe3 | 2006-07-01 19:29:37 -0700 | [diff] [blame] | 1097 | IRQF_SHARED | IRQF_DISABLED, dev->name, |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1098 | (void*) &dev->dmasound); |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1099 | |
| 1100 | if (err < 0) { |
| 1101 | printk(KERN_ERR "%s: can't get IRQ %d for ALSA\n", |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1102 | dev->name, dev->pci->irq); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 1103 | goto __nodev; |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Ricardo Cerqueira | d5ee43a | 2005-11-13 16:08:10 -0800 | [diff] [blame] | 1106 | chip->irq = dev->pci->irq; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1107 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 1108 | mutex_init(&dev->dmasound.lock); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1109 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1110 | if ((err = snd_card_saa7134_new_mixer(chip)) < 0) |
| 1111 | goto __nodev; |
| 1112 | |
| 1113 | if ((err = snd_card_saa7134_pcm(chip, 0)) < 0) |
| 1114 | goto __nodev; |
Ricardo Cerqueira | b2c15ea | 2005-11-08 21:37:14 -0800 | [diff] [blame] | 1115 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1116 | snd_card_set_dev(card, &chip->pci->dev); |
| 1117 | |
| 1118 | /* End of "creation" */ |
| 1119 | |
| 1120 | strcpy(card->shortname, "SAA7134"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1121 | sprintf(card->longname, "%s at 0x%lx irq %d", |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1122 | chip->dev->name, chip->iobase, chip->irq); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1123 | |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 1124 | printk(KERN_INFO "%s/alsa: %s registered as card %d\n",dev->name,card->longname,index[devnum]); |
| 1125 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1126 | if ((err = snd_card_register(card)) == 0) { |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1127 | snd_saa7134_cards[devnum] = card; |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1128 | return 0; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1129 | } |
| 1130 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1131 | __nodev: |
| 1132 | snd_card_free(card); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1133 | return err; |
| 1134 | } |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1135 | |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 1136 | |
| 1137 | static int alsa_device_init(struct saa7134_dev *dev) |
| 1138 | { |
| 1139 | dev->dmasound.priv_data = dev; |
| 1140 | alsa_card_saa7134_create(dev,dev->nr); |
| 1141 | return 1; |
| 1142 | } |
| 1143 | |
| 1144 | static int alsa_device_exit(struct saa7134_dev *dev) |
| 1145 | { |
| 1146 | |
| 1147 | snd_card_free(snd_saa7134_cards[dev->nr]); |
| 1148 | snd_saa7134_cards[dev->nr] = NULL; |
| 1149 | return 1; |
| 1150 | } |
| 1151 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1152 | /* |
| 1153 | * Module initializer |
| 1154 | * |
| 1155 | * Loops through present saa7134 cards, and assigns an ALSA device |
| 1156 | * to each one |
| 1157 | * |
| 1158 | */ |
| 1159 | |
| 1160 | static int saa7134_alsa_init(void) |
| 1161 | { |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1162 | struct saa7134_dev *dev = NULL; |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 1163 | struct list_head *list; |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1164 | |
Adrian Bunk | 166fb6b | 2007-11-21 19:55:52 -0300 | [diff] [blame] | 1165 | saa7134_dmasound_init = alsa_device_init; |
| 1166 | saa7134_dmasound_exit = alsa_device_exit; |
Ricardo Cerqueira | 7bb9529 | 2005-12-20 18:26:26 -0200 | [diff] [blame] | 1167 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1168 | printk(KERN_INFO "saa7134 ALSA driver for DMA sound loaded\n"); |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 1169 | |
| 1170 | list_for_each(list,&saa7134_devlist) { |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1171 | dev = list_entry(list, struct saa7134_dev, devlist); |
Mauro Carvalho Chehab | 40c41c8 | 2009-01-31 08:09:33 -0300 | [diff] [blame] | 1172 | if (dev->pci->device == PCI_DEVICE_ID_PHILIPS_SAA7130) |
| 1173 | printk(KERN_INFO "%s/alsa: %s doesn't support digital audio\n", |
| 1174 | dev->name, saa7134_boards[dev->board].name); |
| 1175 | else |
| 1176 | alsa_device_init(dev); |
Ricardo Cerqueira | c817e76 | 2005-11-13 16:07:47 -0800 | [diff] [blame] | 1177 | } |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1178 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1179 | if (dev == NULL) |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1180 | printk(KERN_INFO "saa7134 ALSA: no saa7134 cards found\n"); |
| 1181 | |
| 1182 | return 0; |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 1183 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | /* |
| 1187 | * Module destructor |
| 1188 | */ |
| 1189 | |
Adrian Bunk | 943a490 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 1190 | static void saa7134_alsa_exit(void) |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 1191 | { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1192 | int idx; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 1193 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1194 | for (idx = 0; idx < SNDRV_CARDS; idx++) { |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 1195 | snd_card_free(snd_saa7134_cards[idx]); |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1196 | } |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 1197 | |
Adrian Bunk | 7845701 | 2006-07-15 15:19:56 -0300 | [diff] [blame] | 1198 | saa7134_dmasound_init = NULL; |
| 1199 | saa7134_dmasound_exit = NULL; |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1200 | printk(KERN_INFO "saa7134 ALSA driver for DMA sound unloaded\n"); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 1201 | |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1202 | return; |
Nickolay V. Shmyrev | 5f7591c | 2005-11-08 21:37:04 -0800 | [diff] [blame] | 1203 | } |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1204 | |
Linus Torvalds | c7ac6b4 | 2005-12-21 14:52:32 -0800 | [diff] [blame] | 1205 | /* We initialize this late, to make sure the sound system is up and running */ |
| 1206 | late_initcall(saa7134_alsa_init); |
Ricardo Cerqueira | 79dd0c69 | 2005-11-08 21:38:53 -0800 | [diff] [blame] | 1207 | module_exit(saa7134_alsa_exit); |
| 1208 | MODULE_LICENSE("GPL"); |
| 1209 | MODULE_AUTHOR("Ricardo Cerqueira"); |