20 #include <linux/slab.h>
21 #include <linux/time.h>
22 #include <linux/wait.h>
23 #include <linux/module.h>
34 static unsigned int debug;
43 #define MIXER_ADDR_UNSELECTED -1
44 #define MIXER_ADDR_TVTUNER 0
45 #define MIXER_ADDR_LINE1 1
46 #define MIXER_ADDR_LINE2 2
47 #define MIXER_ADDR_LAST 2
59 #define dprintk(fmt, arg...) if (debug) \
60 printk(KERN_DEBUG "%s/alsa: " fmt, dev->name , ##arg)
147 int next_blk,
reg = 0;
149 spin_lock(&dev->
slock);
151 dprintk(
"irq: recording stopped\n");
154 if (0 != (status & 0x0f000000))
155 dprintk(
"irq: lost %ld\n", (status >> 24) & 0x0f);
156 if (0 == (status & 0x10000000)) {
158 if (0 == (dev->
dmasound.dma_blk & 0x01))
162 if (1 == (dev->
dmasound.dma_blk & 0x01))
166 dprintk(
"irq: field oops [%s]\n",
167 (status & 0x10000000) ?
"even" :
"odd");
172 dprintk(
"irq: overrun [full=%d/%d] - Blocks in %d\n",dev->
dmasound.read_count,
174 spin_unlock(&dev->
slock);
183 dprintk(
"irq: ok, %s, next_blk=%d, addr=%x, blocks=%u, size=%u, read=%u\n",
184 (status & 0x10000000) ?
"even" :
"odd ", next_blk,
194 spin_unlock(&dev->
slock);
196 spin_lock(&dev->
slock);
200 spin_unlock(&dev->
slock);
218 int loop, handled = 0;
220 for (loop = 0; loop < 10; loop++) {
227 SAA7134_IRQ_REPORT_DONE_RA3);
228 saa7134_irq_alsa_done(dev, status);
235 dprintk(
"error! looping IRQ!");
252 static int snd_card_saa7134_capture_trigger(
struct snd_pcm_substream * substream,
260 spin_lock(&dev->
slock);
263 saa7134_dma_start(dev);
266 saa7134_dma_stop(dev);
270 spin_unlock(&dev->
slock);
286 static int dsp_buffer_init(
struct saa7134_dev *dev)
307 static int dsp_buffer_free(
struct saa7134_dev *dev)
323 static int snd_saa7134_capsrc_set(
struct snd_kcontrol *kcontrol,
337 active = left != 0 || right != 0;
342 change = old_addr !=
addr ||
354 switch (dev->
pci->device) {
368 rate = (32000 == dev->
dmasound.rate) ?
442 static int snd_card_saa7134_capture_prepare(
struct snd_pcm_substream * substream)
451 pcm->
dev->dmasound.substream = substream;
470 switch (dev->
pci->device) {
499 dprintk(
"rec_start: afmt=%d ch=%d => fmt=0x%x swap=%c\n",
543 dev->
dmasound.read_count -= snd_pcm_lib_period_bytes(substream);
544 dev->
dmasound.read_offset += snd_pcm_lib_period_bytes(substream);
549 return bytes_to_frames(runtime, dev->
dmasound.read_offset);
583 .period_bytes_min = 64,
584 .period_bytes_max = (256*1024),
589 static void snd_card_saa7134_runtime_free(
struct snd_pcm_runtime *runtime)
611 unsigned int period_size, periods;
614 period_size = params_period_bytes(hw_params);
617 if (period_size < 0x100 || period_size > 0x10000)
621 if (period_size * periods > 1024 * 1024)
626 if (dev->
dmasound.blocks == periods &&
627 dev->
dmasound.blksize == period_size)
631 if (substream->
runtime->dma_area) {
634 dsp_buffer_free(dev);
638 dev->
dmasound.blksize = period_size;
639 dev->
dmasound.bufsize = period_size * periods;
641 err = dsp_buffer_init(dev);
650 dsp_buffer_free(dev);
655 dsp_buffer_free(dev);
664 dsp_buffer_free(dev);
674 substream->
runtime->dma_addr = 0;
697 if (substream->
runtime->dma_area) {
700 dsp_buffer_free(dev);
748 " Can't proceed with open\n");
757 amux = dev->
input->amux;
758 if ((amux < 1) || (amux > 3))
775 runtime->
hw = snd_card_saa7134_capture;
811 static struct snd_pcm_ops snd_card_saa7134_capture_ops = {
812 .open = snd_card_saa7134_capture_open,
813 .close = snd_card_saa7134_capture_close,
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,
820 .page = snd_card_saa7134_page,
836 if ((err =
snd_pcm_new(saa7134->
card,
"SAA7134 PCM", device, 0, 1, &pcm)) < 0)
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 }
851 static int snd_saa7134_volume_info(
struct snd_kcontrol * kcontrol,
861 static int snd_saa7134_volume_get(
struct snd_kcontrol * kcontrol,
872 static int snd_saa7134_volume_put(
struct snd_kcontrol * kcontrol,
881 left = ucontrol->
value.integer.value[0];
886 right = ucontrol->
value.integer.value[1];
902 switch (dev->
pci->device) {
910 (left > 10) ? 0x00 : 0x10);
914 (left > 10) ? 0x00 : 0x20);
926 (left > 10) ? 0x00 : 0x10);
930 (left > 10) ? 0x00 : 0x20);
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 }
948 static int snd_saa7134_capsrc_info(
struct snd_kcontrol * kcontrol,
958 static int snd_saa7134_capsrc_get(
struct snd_kcontrol * kcontrol,
969 ucontrol->
value.integer.value[0] = 0;
970 ucontrol->
value.integer.value[1] = 0;
977 static int snd_saa7134_capsrc_put(
struct snd_kcontrol * kcontrol,
981 left = ucontrol->
value.integer.value[0] & 1;
982 right = ucontrol->
value.integer.value[1] & 1;
984 return snd_saa7134_capsrc_set(kcontrol, left, right,
false);
1016 for (idx = 0; idx <
ARRAY_SIZE(snd_saa7134_volume_controls); idx++) {
1017 kcontrol =
snd_ctl_new1(&snd_saa7134_volume_controls[idx],
1024 for (idx = 0; idx <
ARRAY_SIZE(snd_saa7134_capture_controls); idx++) {
1025 kcontrol =
snd_ctl_new1(&snd_saa7134_capture_controls[idx],
1038 static void snd_saa7134_free(
struct snd_card * card)
1042 if (chip->
dev->dmasound.priv_data ==
NULL)
1048 chip->
dev->dmasound.priv_data =
NULL;
1106 chip->
irq = dev->
pci->irq;
1110 if ((err = snd_card_saa7134_new_mixer(chip)) < 0)
1137 static int alsa_device_init(
struct saa7134_dev *dev)
1140 alsa_card_saa7134_create(dev,dev->
nr);
1144 static int alsa_device_exit(
struct saa7134_dev *dev)
1148 snd_saa7134_cards[dev->
nr] =
NULL;
1160 static int saa7134_alsa_init(
void)
1176 alsa_device_init(dev);
1190 static void saa7134_alsa_exit(
void)