Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * device driver for philips saa7134 based TV cards |
| 4 | * oss dsp interface |
| 5 | * |
| 6 | * (c) 2001,02 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 7 | * 2005 conversion to standalone module: |
| 8 | * Ricardo Cerqueira <v4l@cerqueira.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
| 24 | |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/moduleparam.h> |
| 29 | #include <linux/kernel.h> |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 30 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/slab.h> |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 32 | #include <linux/sound.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/soundcard.h> |
| 34 | |
| 35 | #include "saa7134-reg.h" |
| 36 | #include "saa7134.h" |
| 37 | |
| 38 | /* ------------------------------------------------------------------ */ |
| 39 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 40 | static unsigned int debug = 0; |
| 41 | module_param(debug, int, 0644); |
| 42 | MODULE_PARM_DESC(debug,"enable debug messages [oss]"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 44 | static unsigned int rate = 0; |
| 45 | module_param(rate, int, 0444); |
| 46 | MODULE_PARM_DESC(rate,"sample rate (valid are: 32000,48000)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 48 | static unsigned int dsp_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; |
| 49 | MODULE_PARM_DESC(dsp_nr, "device numbers for SAA7134 capture interface(s)."); |
| 50 | module_param_array(dsp_nr, int, NULL, 0444); |
| 51 | |
| 52 | static unsigned int mixer_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET }; |
| 53 | MODULE_PARM_DESC(mixer_nr, "mixer numbers for SAA7134 capture interface(s)."); |
| 54 | module_param_array(mixer_nr, int, NULL, 0444); |
| 55 | |
| 56 | #define dprintk(fmt, arg...) if (debug) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | printk(KERN_DEBUG "%s/oss: " fmt, dev->name , ## arg) |
| 58 | |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* ------------------------------------------------------------------ */ |
| 61 | |
| 62 | static int dsp_buffer_conf(struct saa7134_dev *dev, int blksize, int blocks) |
| 63 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | if (blksize < 0x100) |
| 65 | blksize = 0x100; |
| 66 | if (blksize > 0x10000) |
| 67 | blksize = 0x10000; |
| 68 | |
| 69 | if (blocks < 2) |
| 70 | blocks = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | if ((blksize * blocks) > 1024*1024) |
| 72 | blocks = 1024*1024 / blksize; |
| 73 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 74 | dev->dmasound.blocks = blocks; |
| 75 | dev->dmasound.blksize = blksize; |
| 76 | dev->dmasound.bufsize = blksize * blocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | dprintk("buffer config: %d blocks / %d bytes, %d kB total\n", |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 79 | blocks,blksize,blksize * blocks / 1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int dsp_buffer_init(struct saa7134_dev *dev) |
| 84 | { |
| 85 | int err; |
| 86 | |
Eric Sesterhenn | ae24601 | 2006-03-13 13:17:11 -0300 | [diff] [blame] | 87 | BUG_ON(!dev->dmasound.bufsize); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 88 | videobuf_dma_init(&dev->dmasound.dma); |
| 89 | err = videobuf_dma_init_kernel(&dev->dmasound.dma, PCI_DMA_FROMDEVICE, |
| 90 | (dev->dmasound.bufsize + PAGE_SIZE) >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | if (0 != err) |
| 92 | return err; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static int dsp_buffer_free(struct saa7134_dev *dev) |
| 97 | { |
Eric Sesterhenn | ae24601 | 2006-03-13 13:17:11 -0300 | [diff] [blame] | 98 | BUG_ON(!dev->dmasound.blksize); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 99 | videobuf_dma_free(&dev->dmasound.dma); |
| 100 | dev->dmasound.blocks = 0; |
| 101 | dev->dmasound.blksize = 0; |
| 102 | dev->dmasound.bufsize = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static void dsp_dma_start(struct saa7134_dev *dev) |
| 107 | { |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 108 | dev->dmasound.dma_blk = 0; |
| 109 | dev->dmasound.dma_running = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | saa7134_set_dmabits(dev); |
| 111 | } |
| 112 | |
| 113 | static void dsp_dma_stop(struct saa7134_dev *dev) |
| 114 | { |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 115 | dev->dmasound.dma_blk = -1; |
| 116 | dev->dmasound.dma_running = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | saa7134_set_dmabits(dev); |
| 118 | } |
| 119 | |
| 120 | static int dsp_rec_start(struct saa7134_dev *dev) |
| 121 | { |
| 122 | int err, bswap, sign; |
| 123 | u32 fmt, control; |
| 124 | unsigned long flags; |
| 125 | |
| 126 | /* prepare buffer */ |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 127 | if (0 != (err = videobuf_pci_dma_map(dev->pci,&dev->dmasound.dma))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | return err; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 129 | if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | goto fail1; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 131 | if (0 != (err = saa7134_pgtable_build(dev->pci,&dev->dmasound.pt, |
| 132 | dev->dmasound.dma.sglist, |
| 133 | dev->dmasound.dma.sglen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | 0))) |
| 135 | goto fail2; |
| 136 | |
| 137 | /* sample format */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 138 | switch (dev->dmasound.afmt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | case AFMT_U8: |
| 140 | case AFMT_S8: fmt = 0x00; break; |
| 141 | case AFMT_U16_LE: |
| 142 | case AFMT_U16_BE: |
| 143 | case AFMT_S16_LE: |
| 144 | case AFMT_S16_BE: fmt = 0x01; break; |
| 145 | default: |
| 146 | err = -EINVAL; |
| 147 | goto fail2; |
| 148 | } |
| 149 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 150 | switch (dev->dmasound.afmt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | case AFMT_S8: |
| 152 | case AFMT_S16_LE: |
| 153 | case AFMT_S16_BE: sign = 1; break; |
| 154 | default: sign = 0; break; |
| 155 | } |
| 156 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 157 | switch (dev->dmasound.afmt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | case AFMT_U16_BE: |
| 159 | case AFMT_S16_BE: bswap = 1; break; |
| 160 | default: bswap = 0; break; |
| 161 | } |
| 162 | |
| 163 | switch (dev->pci->device) { |
| 164 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 165 | if (1 == dev->dmasound.channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | fmt |= (1 << 3); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 167 | if (2 == dev->dmasound.channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | fmt |= (3 << 3); |
| 169 | if (sign) |
| 170 | fmt |= 0x04; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 171 | fmt |= (TV == dev->dmasound.input) ? 0xc0 : 0x80; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 173 | saa_writeb(SAA7134_NUM_SAMPLES0, ((dev->dmasound.blksize - 1) & 0x0000ff)); |
| 174 | saa_writeb(SAA7134_NUM_SAMPLES1, ((dev->dmasound.blksize - 1) & 0x00ff00) >> 8); |
| 175 | saa_writeb(SAA7134_NUM_SAMPLES2, ((dev->dmasound.blksize - 1) & 0xff0000) >> 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | saa_writeb(SAA7134_AUDIO_FORMAT_CTRL, fmt); |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | break; |
| 179 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 180 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 181 | if (1 == dev->dmasound.channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | fmt |= (1 << 4); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 183 | if (2 == dev->dmasound.channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | fmt |= (2 << 4); |
| 185 | if (!sign) |
| 186 | fmt |= 0x04; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 187 | saa_writel(SAA7133_NUM_SAMPLES, dev->dmasound.blksize -4); |
Ricardo Cerqueira | bd15eba | 2005-11-08 21:37:11 -0800 | [diff] [blame] | 188 | saa_writel(SAA7133_AUDIO_CHANNEL, 0x543210 | (fmt << 24)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | break; |
| 190 | } |
| 191 | dprintk("rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n", |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 192 | dev->dmasound.afmt, dev->dmasound.channels, fmt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | bswap ? 'b' : '-'); |
| 194 | |
| 195 | /* dma: setup channel 6 (= AUDIO) */ |
| 196 | control = SAA7134_RS_CONTROL_BURST_16 | |
| 197 | SAA7134_RS_CONTROL_ME | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 198 | (dev->dmasound.pt.dma >> 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (bswap) |
| 200 | control |= SAA7134_RS_CONTROL_BSWAP; |
| 201 | saa_writel(SAA7134_RS_BA1(6),0); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 202 | saa_writel(SAA7134_RS_BA2(6),dev->dmasound.blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | saa_writel(SAA7134_RS_PITCH(6),0); |
| 204 | saa_writel(SAA7134_RS_CONTROL(6),control); |
| 205 | |
| 206 | /* start dma */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 207 | dev->dmasound.recording_on = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | spin_lock_irqsave(&dev->slock,flags); |
| 209 | dsp_dma_start(dev); |
| 210 | spin_unlock_irqrestore(&dev->slock,flags); |
| 211 | return 0; |
| 212 | |
| 213 | fail2: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 214 | saa7134_pgtable_free(dev->pci,&dev->dmasound.pt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | fail1: |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 216 | videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return err; |
| 218 | } |
| 219 | |
| 220 | static int dsp_rec_stop(struct saa7134_dev *dev) |
| 221 | { |
| 222 | unsigned long flags; |
| 223 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 224 | dprintk("rec_stop dma_blk=%d\n",dev->dmasound.dma_blk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* stop dma */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 227 | dev->dmasound.recording_on = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | spin_lock_irqsave(&dev->slock,flags); |
| 229 | dsp_dma_stop(dev); |
| 230 | spin_unlock_irqrestore(&dev->slock,flags); |
| 231 | |
| 232 | /* unlock buffer */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 233 | saa7134_pgtable_free(dev->pci,&dev->dmasound.pt); |
Mauro Carvalho Chehab | c7b0ac0 | 2006-03-10 12:29:15 -0300 | [diff] [blame] | 234 | videobuf_pci_dma_unmap(dev->pci,&dev->dmasound.dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | /* ------------------------------------------------------------------ */ |
| 239 | |
| 240 | static int dsp_open(struct inode *inode, struct file *file) |
| 241 | { |
| 242 | int minor = iminor(inode); |
| 243 | struct saa7134_dev *h,*dev = NULL; |
| 244 | struct list_head *list; |
| 245 | int err; |
| 246 | |
| 247 | list_for_each(list,&saa7134_devlist) { |
| 248 | h = list_entry(list, struct saa7134_dev, devlist); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 249 | if (h->dmasound.minor_dsp == minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | dev = h; |
| 251 | } |
| 252 | if (NULL == dev) |
| 253 | return -ENODEV; |
| 254 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 255 | mutex_lock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | err = -EBUSY; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 257 | if (dev->dmasound.users_dsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | goto fail1; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 259 | dev->dmasound.users_dsp++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | file->private_data = dev; |
| 261 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 262 | dev->dmasound.afmt = AFMT_U8; |
| 263 | dev->dmasound.channels = 1; |
| 264 | dev->dmasound.read_count = 0; |
| 265 | dev->dmasound.read_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | dsp_buffer_conf(dev,PAGE_SIZE,64); |
| 267 | err = dsp_buffer_init(dev); |
| 268 | if (0 != err) |
| 269 | goto fail2; |
| 270 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 271 | mutex_unlock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return 0; |
| 273 | |
| 274 | fail2: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 275 | dev->dmasound.users_dsp--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | fail1: |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 277 | mutex_unlock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | return err; |
| 279 | } |
| 280 | |
| 281 | static int dsp_release(struct inode *inode, struct file *file) |
| 282 | { |
| 283 | struct saa7134_dev *dev = file->private_data; |
| 284 | |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 285 | mutex_lock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 286 | if (dev->dmasound.recording_on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | dsp_rec_stop(dev); |
| 288 | dsp_buffer_free(dev); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 289 | dev->dmasound.users_dsp--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | file->private_data = NULL; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 291 | mutex_unlock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | static ssize_t dsp_read(struct file *file, char __user *buffer, |
| 296 | size_t count, loff_t *ppos) |
| 297 | { |
| 298 | struct saa7134_dev *dev = file->private_data; |
| 299 | DECLARE_WAITQUEUE(wait, current); |
| 300 | unsigned int bytes; |
| 301 | unsigned long flags; |
| 302 | int err,ret = 0; |
| 303 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 304 | add_wait_queue(&dev->dmasound.wq, &wait); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 305 | mutex_lock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | while (count > 0) { |
| 307 | /* wait for data if needed */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 308 | if (0 == dev->dmasound.read_count) { |
| 309 | if (!dev->dmasound.recording_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | err = dsp_rec_start(dev); |
| 311 | if (err < 0) { |
| 312 | if (0 == ret) |
| 313 | ret = err; |
| 314 | break; |
| 315 | } |
| 316 | } |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 317 | if (dev->dmasound.recording_on && |
| 318 | !dev->dmasound.dma_running) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* recover from overruns */ |
| 320 | spin_lock_irqsave(&dev->slock,flags); |
| 321 | dsp_dma_start(dev); |
| 322 | spin_unlock_irqrestore(&dev->slock,flags); |
| 323 | } |
| 324 | if (file->f_flags & O_NONBLOCK) { |
| 325 | if (0 == ret) |
| 326 | ret = -EAGAIN; |
| 327 | break; |
| 328 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 329 | mutex_unlock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | set_current_state(TASK_INTERRUPTIBLE); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 331 | if (0 == dev->dmasound.read_count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | schedule(); |
| 333 | set_current_state(TASK_RUNNING); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 334 | mutex_lock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | if (signal_pending(current)) { |
| 336 | if (0 == ret) |
| 337 | ret = -EINTR; |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | /* copy data to userspace */ |
| 343 | bytes = count; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 344 | if (bytes > dev->dmasound.read_count) |
| 345 | bytes = dev->dmasound.read_count; |
| 346 | if (bytes > dev->dmasound.bufsize - dev->dmasound.read_offset) |
| 347 | bytes = dev->dmasound.bufsize - dev->dmasound.read_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | if (copy_to_user(buffer + ret, |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 349 | dev->dmasound.dma.vmalloc + dev->dmasound.read_offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | bytes)) { |
| 351 | if (0 == ret) |
| 352 | ret = -EFAULT; |
| 353 | break; |
| 354 | } |
| 355 | |
| 356 | ret += bytes; |
| 357 | count -= bytes; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 358 | dev->dmasound.read_count -= bytes; |
| 359 | dev->dmasound.read_offset += bytes; |
| 360 | if (dev->dmasound.read_offset == dev->dmasound.bufsize) |
| 361 | dev->dmasound.read_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 363 | mutex_unlock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 364 | remove_wait_queue(&dev->dmasound.wq, &wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | return ret; |
| 366 | } |
| 367 | |
| 368 | static ssize_t dsp_write(struct file *file, const char __user *buffer, |
| 369 | size_t count, loff_t *ppos) |
| 370 | { |
| 371 | return -EINVAL; |
| 372 | } |
| 373 | |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 374 | static const char *osspcm_ioctls[] = { |
| 375 | "RESET", "SYNC", "SPEED", "STEREO", "GETBLKSIZE", "SETFMT", |
| 376 | "CHANNELS", "?", "POST", "SUBDIVIDE", "SETFRAGMENT", "GETFMTS", |
| 377 | "GETOSPACE", "GETISPACE", "NONBLOCK", "GETCAPS", "GET/SETTRIGGER", |
| 378 | "GETIPTR", "GETOPTR", "MAPINBUF", "MAPOUTBUF", "SETSYNCRO", |
| 379 | "SETDUPLEX", "GETODELAY" |
| 380 | }; |
| 381 | #define OSSPCM_IOCTLS ARRAY_SIZE(osspcm_ioctls) |
| 382 | |
| 383 | static void saa7134_oss_print_ioctl(char *name, unsigned int cmd) |
| 384 | { |
| 385 | char *dir; |
| 386 | |
| 387 | switch (_IOC_DIR(cmd)) { |
| 388 | case _IOC_NONE: dir = "--"; break; |
| 389 | case _IOC_READ: dir = "r-"; break; |
| 390 | case _IOC_WRITE: dir = "-w"; break; |
| 391 | case _IOC_READ | _IOC_WRITE: dir = "rw"; break; |
| 392 | default: dir = "??"; break; |
| 393 | } |
| 394 | switch (_IOC_TYPE(cmd)) { |
| 395 | case 'P': |
| 396 | printk(KERN_DEBUG "%s: ioctl 0x%08x (oss dsp, %s, SNDCTL_DSP_%s)\n", |
| 397 | name, cmd, dir, (_IOC_NR(cmd) < OSSPCM_IOCTLS) ? |
| 398 | osspcm_ioctls[_IOC_NR(cmd)] : "???"); |
| 399 | break; |
| 400 | case 'M': |
| 401 | printk(KERN_DEBUG "%s: ioctl 0x%08x (oss mixer, %s, #%d)\n", |
| 402 | name, cmd, dir, _IOC_NR(cmd)); |
| 403 | break; |
| 404 | default: |
| 405 | printk(KERN_DEBUG "%s: ioctl 0x%08x (???, %s, #%d)\n", |
| 406 | name, cmd, dir, _IOC_NR(cmd)); |
| 407 | } |
| 408 | } |
| 409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | static int dsp_ioctl(struct inode *inode, struct file *file, |
| 411 | unsigned int cmd, unsigned long arg) |
| 412 | { |
| 413 | struct saa7134_dev *dev = file->private_data; |
| 414 | void __user *argp = (void __user *) arg; |
| 415 | int __user *p = argp; |
| 416 | int val = 0; |
| 417 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 418 | if (debug > 1) |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 419 | saa7134_oss_print_ioctl(dev->name,cmd); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 420 | switch (cmd) { |
| 421 | case OSS_GETVERSION: |
| 422 | return put_user(SOUND_VERSION, p); |
| 423 | case SNDCTL_DSP_GETCAPS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | return 0; |
| 425 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 426 | case SNDCTL_DSP_SPEED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | if (get_user(val, p)) |
| 428 | return -EFAULT; |
| 429 | /* fall through */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 430 | case SOUND_PCM_READ_RATE: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 431 | return put_user(dev->dmasound.rate, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 433 | case SNDCTL_DSP_STEREO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (get_user(val, p)) |
| 435 | return -EFAULT; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 436 | mutex_lock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 437 | dev->dmasound.channels = val ? 2 : 1; |
| 438 | if (dev->dmasound.recording_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | dsp_rec_stop(dev); |
| 440 | dsp_rec_start(dev); |
| 441 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 442 | mutex_unlock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 443 | return put_user(dev->dmasound.channels-1, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 445 | case SNDCTL_DSP_CHANNELS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | if (get_user(val, p)) |
| 447 | return -EFAULT; |
| 448 | if (val != 1 && val != 2) |
| 449 | return -EINVAL; |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 450 | mutex_lock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 451 | dev->dmasound.channels = val; |
| 452 | if (dev->dmasound.recording_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | dsp_rec_stop(dev); |
| 454 | dsp_rec_start(dev); |
| 455 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 456 | mutex_unlock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | /* fall through */ |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 458 | case SOUND_PCM_READ_CHANNELS: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 459 | return put_user(dev->dmasound.channels, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 461 | case SNDCTL_DSP_GETFMTS: /* Returns a mask */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | return put_user(AFMT_U8 | AFMT_S8 | |
| 463 | AFMT_U16_LE | AFMT_U16_BE | |
| 464 | AFMT_S16_LE | AFMT_S16_BE, p); |
| 465 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 466 | case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | if (get_user(val, p)) |
| 468 | return -EFAULT; |
| 469 | switch (val) { |
| 470 | case AFMT_QUERY: |
| 471 | /* nothing to do */ |
| 472 | break; |
| 473 | case AFMT_U8: |
| 474 | case AFMT_S8: |
| 475 | case AFMT_U16_LE: |
| 476 | case AFMT_U16_BE: |
| 477 | case AFMT_S16_LE: |
| 478 | case AFMT_S16_BE: |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 479 | mutex_lock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 480 | dev->dmasound.afmt = val; |
| 481 | if (dev->dmasound.recording_on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | dsp_rec_stop(dev); |
| 483 | dsp_rec_start(dev); |
| 484 | } |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 485 | mutex_unlock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 486 | return put_user(dev->dmasound.afmt, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | default: |
| 488 | return -EINVAL; |
| 489 | } |
| 490 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 491 | case SOUND_PCM_READ_BITS: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 492 | switch (dev->dmasound.afmt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | case AFMT_U8: |
| 494 | case AFMT_S8: |
| 495 | return put_user(8, p); |
| 496 | case AFMT_U16_LE: |
| 497 | case AFMT_U16_BE: |
| 498 | case AFMT_S16_LE: |
| 499 | case AFMT_S16_BE: |
| 500 | return put_user(16, p); |
| 501 | default: |
| 502 | return -EINVAL; |
| 503 | } |
| 504 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 505 | case SNDCTL_DSP_NONBLOCK: |
| 506 | file->f_flags |= O_NONBLOCK; |
| 507 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 509 | case SNDCTL_DSP_RESET: |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 510 | mutex_lock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 511 | if (dev->dmasound.recording_on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | dsp_rec_stop(dev); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 513 | mutex_unlock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | return 0; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 515 | case SNDCTL_DSP_GETBLKSIZE: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 516 | return put_user(dev->dmasound.blksize, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 518 | case SNDCTL_DSP_SETFRAGMENT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | if (get_user(val, p)) |
| 520 | return -EFAULT; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 521 | if (dev->dmasound.recording_on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | return -EBUSY; |
| 523 | dsp_buffer_free(dev); |
| 524 | /* used to be arg >> 16 instead of val >> 16; fixed */ |
| 525 | dsp_buffer_conf(dev,1 << (val & 0xffff), (val >> 16) & 0xffff); |
| 526 | dsp_buffer_init(dev); |
| 527 | return 0; |
| 528 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 529 | case SNDCTL_DSP_SYNC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* NOP */ |
| 531 | return 0; |
| 532 | |
| 533 | case SNDCTL_DSP_GETISPACE: |
| 534 | { |
| 535 | audio_buf_info info; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 536 | info.fragsize = dev->dmasound.blksize; |
| 537 | info.fragstotal = dev->dmasound.blocks; |
| 538 | info.bytes = dev->dmasound.read_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | info.fragments = info.bytes / info.fragsize; |
| 540 | if (copy_to_user(argp, &info, sizeof(info))) |
| 541 | return -EFAULT; |
| 542 | return 0; |
| 543 | } |
| 544 | default: |
| 545 | return -EINVAL; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait) |
| 550 | { |
| 551 | struct saa7134_dev *dev = file->private_data; |
| 552 | unsigned int mask = 0; |
| 553 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 554 | poll_wait(file, &dev->dmasound.wq, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 556 | if (0 == dev->dmasound.read_count) { |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 557 | mutex_lock(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 558 | if (!dev->dmasound.recording_on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | dsp_rec_start(dev); |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 560 | mutex_unlock(&dev->dmasound.lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } else |
| 562 | mask |= (POLLIN | POLLRDNORM); |
| 563 | return mask; |
| 564 | } |
| 565 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 566 | const struct file_operations saa7134_dsp_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | .owner = THIS_MODULE, |
| 568 | .open = dsp_open, |
| 569 | .release = dsp_release, |
| 570 | .read = dsp_read, |
| 571 | .write = dsp_write, |
| 572 | .ioctl = dsp_ioctl, |
| 573 | .poll = dsp_poll, |
| 574 | .llseek = no_llseek, |
| 575 | }; |
| 576 | |
| 577 | /* ------------------------------------------------------------------ */ |
| 578 | |
| 579 | static int |
| 580 | mixer_recsrc_7134(struct saa7134_dev *dev) |
| 581 | { |
| 582 | int analog_io,rate; |
| 583 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 584 | switch (dev->dmasound.input) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | case TV: |
| 586 | saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0xc0); |
| 587 | saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, 0x00); |
| 588 | break; |
| 589 | case LINE1: |
| 590 | case LINE2: |
| 591 | case LINE2_LEFT: |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 592 | analog_io = (LINE1 == dev->dmasound.input) ? 0x00 : 0x08; |
| 593 | rate = (32000 == dev->dmasound.rate) ? 0x01 : 0x03; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x08, analog_io); |
| 595 | saa_andorb(SAA7134_AUDIO_FORMAT_CTRL, 0xc0, 0x80); |
| 596 | saa_andorb(SAA7134_SIF_SAMPLE_FREQ, 0x03, rate); |
| 597 | break; |
| 598 | } |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static int |
| 603 | mixer_recsrc_7133(struct saa7134_dev *dev) |
| 604 | { |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 605 | u32 anabar, xbarin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 607 | xbarin = 0x03; // adc |
| 608 | anabar = 0; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 609 | switch (dev->dmasound.input) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | case TV: |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 611 | xbarin = 0; // Demodulator |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 612 | anabar = 2; // DACs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | break; |
| 614 | case LINE1: |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 615 | anabar = 0; // aux1, aux1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | break; |
| 617 | case LINE2: |
| 618 | case LINE2_LEFT: |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 619 | anabar = 9; // aux2, aux2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | break; |
| 621 | } |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 622 | /* output xbar always main channel */ |
| 623 | saa_dsp_writel(dev, 0x46c >> 2, 0xbbbb10); |
| 624 | saa_dsp_writel(dev, 0x464 >> 2, xbarin); |
| 625 | saa_writel(0x594 >> 2, anabar); |
| 626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | static int |
| 631 | mixer_recsrc(struct saa7134_dev *dev, enum saa7134_audio_in src) |
| 632 | { |
| 633 | static const char *iname[] = { "Oops", "TV", "LINE1", "LINE2" }; |
| 634 | |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 635 | dev->dmasound.count++; |
| 636 | dev->dmasound.input = src; |
| 637 | dprintk("mixer input = %s\n",iname[dev->dmasound.input]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
| 639 | switch (dev->pci->device) { |
| 640 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
| 641 | mixer_recsrc_7134(dev); |
| 642 | break; |
| 643 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 644 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
| 645 | mixer_recsrc_7133(dev); |
| 646 | break; |
| 647 | } |
| 648 | return 0; |
| 649 | } |
| 650 | |
| 651 | static int |
| 652 | mixer_level(struct saa7134_dev *dev, enum saa7134_audio_in src, int level) |
| 653 | { |
| 654 | switch (dev->pci->device) { |
| 655 | case PCI_DEVICE_ID_PHILIPS_SAA7134: |
| 656 | switch (src) { |
| 657 | case TV: |
| 658 | /* nothing */ |
| 659 | break; |
| 660 | case LINE1: |
| 661 | saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x10, |
| 662 | (100 == level) ? 0x00 : 0x10); |
| 663 | break; |
| 664 | case LINE2: |
| 665 | case LINE2_LEFT: |
| 666 | saa_andorb(SAA7134_ANALOG_IO_SELECT, 0x20, |
| 667 | (100 == level) ? 0x00 : 0x20); |
| 668 | break; |
| 669 | } |
| 670 | break; |
| 671 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 672 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
| 673 | /* nothing */ |
| 674 | break; |
| 675 | } |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | /* ------------------------------------------------------------------ */ |
| 680 | |
| 681 | static int mixer_open(struct inode *inode, struct file *file) |
| 682 | { |
| 683 | int minor = iminor(inode); |
| 684 | struct saa7134_dev *h,*dev = NULL; |
| 685 | struct list_head *list; |
| 686 | |
| 687 | list_for_each(list,&saa7134_devlist) { |
| 688 | h = list_entry(list, struct saa7134_dev, devlist); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 689 | if (h->dmasound.minor_mixer == minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | dev = h; |
| 691 | } |
| 692 | if (NULL == dev) |
| 693 | return -ENODEV; |
| 694 | |
| 695 | file->private_data = dev; |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | static int mixer_release(struct inode *inode, struct file *file) |
| 700 | { |
| 701 | file->private_data = NULL; |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int mixer_ioctl(struct inode *inode, struct file *file, |
| 706 | unsigned int cmd, unsigned long arg) |
| 707 | { |
| 708 | struct saa7134_dev *dev = file->private_data; |
| 709 | enum saa7134_audio_in input; |
| 710 | int val,ret; |
| 711 | void __user *argp = (void __user *) arg; |
| 712 | int __user *p = argp; |
| 713 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 714 | if (debug > 1) |
Michael Krufky | 5e453dc | 2006-01-09 15:32:31 -0200 | [diff] [blame] | 715 | saa7134_oss_print_ioctl(dev->name,cmd); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 716 | switch (cmd) { |
| 717 | case OSS_GETVERSION: |
| 718 | return put_user(SOUND_VERSION, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | case SOUND_MIXER_INFO: |
| 720 | { |
| 721 | mixer_info info; |
| 722 | memset(&info,0,sizeof(info)); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 723 | strlcpy(info.id, "TV audio", sizeof(info.id)); |
| 724 | strlcpy(info.name, dev->name, sizeof(info.name)); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 725 | info.modify_counter = dev->dmasound.count; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 726 | if (copy_to_user(argp, &info, sizeof(info))) |
| 727 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | return 0; |
| 729 | } |
| 730 | case SOUND_OLD_MIXER_INFO: |
| 731 | { |
| 732 | _old_mixer_info info; |
| 733 | memset(&info,0,sizeof(info)); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 734 | strlcpy(info.id, "TV audio", sizeof(info.id)); |
| 735 | strlcpy(info.name, dev->name, sizeof(info.name)); |
| 736 | if (copy_to_user(argp, &info, sizeof(info))) |
| 737 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | return 0; |
| 739 | } |
| 740 | case MIXER_READ(SOUND_MIXER_CAPS): |
| 741 | return put_user(SOUND_CAP_EXCL_INPUT, p); |
| 742 | case MIXER_READ(SOUND_MIXER_STEREODEVS): |
| 743 | return put_user(0, p); |
| 744 | case MIXER_READ(SOUND_MIXER_RECMASK): |
| 745 | case MIXER_READ(SOUND_MIXER_DEVMASK): |
| 746 | val = SOUND_MASK_LINE1 | SOUND_MASK_LINE2; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 747 | if (32000 == dev->dmasound.rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | val |= SOUND_MASK_VIDEO; |
| 749 | return put_user(val, p); |
| 750 | |
| 751 | case MIXER_WRITE(SOUND_MIXER_RECSRC): |
| 752 | if (get_user(val, p)) |
| 753 | return -EFAULT; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 754 | input = dev->dmasound.input; |
| 755 | if (32000 == dev->dmasound.rate && |
| 756 | val & SOUND_MASK_VIDEO && dev->dmasound.input != TV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | input = TV; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 758 | if (val & SOUND_MASK_LINE1 && dev->dmasound.input != LINE1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | input = LINE1; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 760 | if (val & SOUND_MASK_LINE2 && dev->dmasound.input != LINE2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | input = LINE2; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 762 | if (input != dev->dmasound.input) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | mixer_recsrc(dev,input); |
| 764 | /* fall throuth */ |
| 765 | case MIXER_READ(SOUND_MIXER_RECSRC): |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 766 | switch (dev->dmasound.input) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | case TV: ret = SOUND_MASK_VIDEO; break; |
| 768 | case LINE1: ret = SOUND_MASK_LINE1; break; |
| 769 | case LINE2: ret = SOUND_MASK_LINE2; break; |
| 770 | default: ret = 0; |
| 771 | } |
| 772 | return put_user(ret, p); |
| 773 | |
| 774 | case MIXER_WRITE(SOUND_MIXER_VIDEO): |
| 775 | case MIXER_READ(SOUND_MIXER_VIDEO): |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 776 | if (32000 != dev->dmasound.rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | return -EINVAL; |
| 778 | return put_user(100 | 100 << 8, p); |
| 779 | |
| 780 | case MIXER_WRITE(SOUND_MIXER_LINE1): |
| 781 | if (get_user(val, p)) |
| 782 | return -EFAULT; |
| 783 | val &= 0xff; |
| 784 | val = (val <= 50) ? 50 : 100; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 785 | dev->dmasound.line1 = val; |
| 786 | mixer_level(dev,LINE1,dev->dmasound.line1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | /* fall throuth */ |
| 788 | case MIXER_READ(SOUND_MIXER_LINE1): |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 789 | return put_user(dev->dmasound.line1 | dev->dmasound.line1 << 8, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | case MIXER_WRITE(SOUND_MIXER_LINE2): |
| 792 | if (get_user(val, p)) |
| 793 | return -EFAULT; |
| 794 | val &= 0xff; |
| 795 | val = (val <= 50) ? 50 : 100; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 796 | dev->dmasound.line2 = val; |
| 797 | mixer_level(dev,LINE2,dev->dmasound.line2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | /* fall throuth */ |
| 799 | case MIXER_READ(SOUND_MIXER_LINE2): |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 800 | return put_user(dev->dmasound.line2 | dev->dmasound.line2 << 8, p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | default: |
| 803 | return -EINVAL; |
| 804 | } |
| 805 | } |
| 806 | |
Arjan van de Ven | fa027c2 | 2007-02-12 00:55:33 -0800 | [diff] [blame] | 807 | const struct file_operations saa7134_mixer_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | .owner = THIS_MODULE, |
| 809 | .open = mixer_open, |
| 810 | .release = mixer_release, |
| 811 | .ioctl = mixer_ioctl, |
| 812 | .llseek = no_llseek, |
| 813 | }; |
| 814 | |
| 815 | /* ------------------------------------------------------------------ */ |
| 816 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 817 | static irqreturn_t saa7134_oss_irq(int irq, void *dev_id) |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 818 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 819 | struct saa7134_dmasound *dmasound = dev_id; |
| 820 | struct saa7134_dev *dev = dmasound->priv_data; |
| 821 | unsigned long report, status; |
| 822 | int loop, handled = 0; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 823 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 824 | for (loop = 0; loop < 10; loop++) { |
| 825 | report = saa_readl(SAA7134_IRQ_REPORT); |
| 826 | status = saa_readl(SAA7134_IRQ_STATUS); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 827 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 828 | if (report & SAA7134_IRQ_REPORT_DONE_RA3) { |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 829 | handled = 1; |
| 830 | saa_writel(SAA7134_IRQ_REPORT,report); |
| 831 | saa7134_irq_oss_done(dev, status); |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 832 | } else { |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 833 | goto out; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 834 | } |
| 835 | } |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 836 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 837 | if (loop == 10) { |
| 838 | dprintk("error! looping IRQ!"); |
| 839 | } |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 840 | out: |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 841 | return IRQ_RETVAL(handled); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | int saa7134_oss_init1(struct saa7134_dev *dev) |
| 845 | { |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 846 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 847 | if ((request_irq(dev->pci->irq, saa7134_oss_irq, |
Thomas Gleixner | 8076fe3 | 2006-07-01 19:29:37 -0700 | [diff] [blame] | 848 | IRQF_SHARED | IRQF_DISABLED, dev->name, |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 849 | (void*) &dev->dmasound)) < 0) |
| 850 | return -1; |
| 851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | /* general */ |
Ingo Molnar | 3593cab | 2006-02-07 06:49:14 -0200 | [diff] [blame] | 853 | mutex_init(&dev->dmasound.lock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 854 | init_waitqueue_head(&dev->dmasound.wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
| 856 | switch (dev->pci->device) { |
| 857 | case PCI_DEVICE_ID_PHILIPS_SAA7133: |
| 858 | case PCI_DEVICE_ID_PHILIPS_SAA7135: |
| 859 | saa_writel(0x588 >> 2, 0x00000fff); |
| 860 | saa_writel(0x58c >> 2, 0x00543210); |
| 861 | saa_dsp_writel(dev, 0x46c >> 2, 0xbbbbbb); |
| 862 | break; |
| 863 | } |
| 864 | |
| 865 | /* dsp */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 866 | dev->dmasound.rate = 32000; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 867 | if (rate) |
| 868 | dev->dmasound.rate = rate; |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 869 | dev->dmasound.rate = (dev->dmasound.rate > 40000) ? 48000 : 32000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | /* mixer */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 872 | dev->dmasound.line1 = 50; |
| 873 | dev->dmasound.line2 = 50; |
| 874 | mixer_level(dev,LINE1,dev->dmasound.line1); |
| 875 | mixer_level(dev,LINE2,dev->dmasound.line2); |
| 876 | mixer_recsrc(dev, (dev->dmasound.rate == 32000) ? TV : LINE2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | return 0; |
| 879 | } |
| 880 | |
| 881 | int saa7134_oss_fini(struct saa7134_dev *dev) |
| 882 | { |
| 883 | /* nothing */ |
| 884 | return 0; |
| 885 | } |
| 886 | |
| 887 | void saa7134_irq_oss_done(struct saa7134_dev *dev, unsigned long status) |
| 888 | { |
| 889 | int next_blk, reg = 0; |
| 890 | |
| 891 | spin_lock(&dev->slock); |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 892 | if (UNSET == dev->dmasound.dma_blk) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | dprintk("irq: recording stopped\n"); |
| 894 | goto done; |
| 895 | } |
| 896 | if (0 != (status & 0x0f000000)) |
| 897 | dprintk("irq: lost %ld\n", (status >> 24) & 0x0f); |
| 898 | if (0 == (status & 0x10000000)) { |
| 899 | /* odd */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 900 | if (0 == (dev->dmasound.dma_blk & 0x01)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | reg = SAA7134_RS_BA1(6); |
| 902 | } else { |
| 903 | /* even */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 904 | if (1 == (dev->dmasound.dma_blk & 0x01)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | reg = SAA7134_RS_BA2(6); |
| 906 | } |
| 907 | if (0 == reg) { |
| 908 | dprintk("irq: field oops [%s]\n", |
| 909 | (status & 0x10000000) ? "even" : "odd"); |
| 910 | goto done; |
| 911 | } |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 912 | if (dev->dmasound.read_count >= dev->dmasound.blksize * (dev->dmasound.blocks-2)) { |
| 913 | dprintk("irq: overrun [full=%d/%d]\n",dev->dmasound.read_count, |
| 914 | dev->dmasound.bufsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | dsp_dma_stop(dev); |
| 916 | goto done; |
| 917 | } |
| 918 | |
| 919 | /* next block addr */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 920 | next_blk = (dev->dmasound.dma_blk + 2) % dev->dmasound.blocks; |
| 921 | saa_writel(reg,next_blk * dev->dmasound.blksize); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 922 | if (debug > 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | dprintk("irq: ok, %s, next_blk=%d, addr=%x\n", |
| 924 | (status & 0x10000000) ? "even" : "odd ", next_blk, |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 925 | next_blk * dev->dmasound.blksize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | |
| 927 | /* update status & wake waiting readers */ |
Ricardo Cerqueira | b54134b | 2005-11-08 21:38:54 -0800 | [diff] [blame] | 928 | dev->dmasound.dma_blk = (dev->dmasound.dma_blk + 1) % dev->dmasound.blocks; |
| 929 | dev->dmasound.read_count += dev->dmasound.blksize; |
| 930 | wake_up(&dev->dmasound.wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
| 932 | done: |
| 933 | spin_unlock(&dev->slock); |
| 934 | } |
| 935 | |
Adrian Bunk | 943a490 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 936 | static int saa7134_dsp_create(struct saa7134_dev *dev) |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 937 | { |
| 938 | int err; |
| 939 | |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 940 | err = dev->dmasound.minor_dsp = |
| 941 | register_sound_dsp(&saa7134_dsp_fops, |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 942 | dsp_nr[dev->nr]); |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 943 | if (err < 0) { |
| 944 | goto fail; |
| 945 | } |
| 946 | printk(KERN_INFO "%s: registered device dsp%d\n", |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 947 | dev->name,dev->dmasound.minor_dsp >> 4); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 948 | |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 949 | err = dev->dmasound.minor_mixer = |
| 950 | register_sound_mixer(&saa7134_mixer_fops, |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 951 | mixer_nr[dev->nr]); |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 952 | if (err < 0) |
| 953 | goto fail; |
| 954 | printk(KERN_INFO "%s: registered device mixer%d\n", |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 955 | dev->name,dev->dmasound.minor_mixer >> 4); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 956 | |
| 957 | return 0; |
| 958 | |
| 959 | fail: |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 960 | unregister_sound_dsp(dev->dmasound.minor_dsp); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 961 | return 0; |
| 962 | |
| 963 | |
| 964 | } |
| 965 | |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 966 | static int oss_device_init(struct saa7134_dev *dev) |
| 967 | { |
| 968 | dev->dmasound.priv_data = dev; |
| 969 | saa7134_oss_init1(dev); |
| 970 | saa7134_dsp_create(dev); |
| 971 | return 1; |
| 972 | } |
| 973 | |
| 974 | static int oss_device_exit(struct saa7134_dev *dev) |
| 975 | { |
| 976 | |
| 977 | unregister_sound_mixer(dev->dmasound.minor_mixer); |
| 978 | unregister_sound_dsp(dev->dmasound.minor_dsp); |
| 979 | |
| 980 | saa7134_oss_fini(dev); |
| 981 | |
| 982 | if (dev->pci->irq > 0) { |
| 983 | synchronize_irq(dev->pci->irq); |
| 984 | free_irq(dev->pci->irq,&dev->dmasound); |
| 985 | } |
| 986 | |
| 987 | dev->dmasound.priv_data = NULL; |
| 988 | return 1; |
| 989 | } |
| 990 | |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 991 | static int saa7134_oss_init(void) |
| 992 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 993 | struct saa7134_dev *dev = NULL; |
| 994 | struct list_head *list; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 995 | |
Adrian Bunk | 7845701 | 2006-07-15 15:19:56 -0300 | [diff] [blame] | 996 | if (!saa7134_dmasound_init && !saa7134_dmasound_exit) { |
| 997 | saa7134_dmasound_init = oss_device_init; |
| 998 | saa7134_dmasound_exit = oss_device_exit; |
Ricardo Cerqueira | 7bb9529 | 2005-12-20 18:26:26 -0200 | [diff] [blame] | 999 | } else { |
| 1000 | printk(KERN_WARNING "saa7134 OSS: can't load, DMA sound handler already assigned (probably to ALSA)\n"); |
| 1001 | return -EBUSY; |
| 1002 | } |
| 1003 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1004 | printk(KERN_INFO "saa7134 OSS driver for DMA sound loaded\n"); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1005 | |
Ricardo Cerqueira | 7bb9529 | 2005-12-20 18:26:26 -0200 | [diff] [blame] | 1006 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1007 | list_for_each(list,&saa7134_devlist) { |
| 1008 | dev = list_entry(list, struct saa7134_dev, devlist); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1009 | if (dev->dmasound.priv_data == NULL) { |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 1010 | oss_device_init(dev); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1011 | } else { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1012 | printk(KERN_ERR "saa7134 OSS: DMA sound is being handled by ALSA, ignoring %s\n",dev->name); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1013 | return -EBUSY; |
| 1014 | } |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1015 | } |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1016 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1017 | if (dev == NULL) |
| 1018 | printk(KERN_INFO "saa7134 OSS: no saa7134 cards found\n"); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1019 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1020 | return 0; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1021 | |
| 1022 | } |
| 1023 | |
Adrian Bunk | 943a490 | 2005-12-01 00:51:35 -0800 | [diff] [blame] | 1024 | static void saa7134_oss_exit(void) |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1025 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1026 | struct saa7134_dev *dev = NULL; |
| 1027 | struct list_head *list; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1028 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1029 | list_for_each(list,&saa7134_devlist) { |
| 1030 | dev = list_entry(list, struct saa7134_dev, devlist); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1031 | |
| 1032 | /* Device isn't registered by OSS, probably ALSA's */ |
| 1033 | if (!dev->dmasound.minor_dsp) |
| 1034 | continue; |
| 1035 | |
Ricardo Cerqueira | f5b974c | 2005-12-01 00:51:20 -0800 | [diff] [blame] | 1036 | oss_device_exit(dev); |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 1037 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1038 | } |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1039 | |
Adrian Bunk | 7845701 | 2006-07-15 15:19:56 -0300 | [diff] [blame] | 1040 | saa7134_dmasound_init = NULL; |
| 1041 | saa7134_dmasound_exit = NULL; |
Ricardo Cerqueira | 7bb9529 | 2005-12-20 18:26:26 -0200 | [diff] [blame] | 1042 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1043 | printk(KERN_INFO "saa7134 OSS driver for DMA sound unloaded\n"); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1044 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1045 | return; |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
Linus Torvalds | c7ac6b4 | 2005-12-21 14:52:32 -0800 | [diff] [blame] | 1048 | /* We initialize this late, to make sure the sound system is up and running */ |
| 1049 | late_initcall(saa7134_oss_init); |
Ricardo Cerqueira | 4aabf63 | 2005-11-13 16:08:00 -0800 | [diff] [blame] | 1050 | module_exit(saa7134_oss_exit); |
| 1051 | MODULE_LICENSE("GPL"); |
| 1052 | MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); |
| 1053 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | /* ----------------------------------------------------------- */ |
| 1055 | /* |
| 1056 | * Local variables: |
| 1057 | * c-basic-offset: 8 |
| 1058 | * End: |
| 1059 | */ |