aboutsummaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-11-16 05:33:41 -0500
committerTakashi Iwai <tiwai@suse.de>2009-11-16 05:33:41 -0500
commitfe705ab1526bc2c8b7756f3a855f040ab2060af2 (patch)
treec4444d19983c5578f9ef2bddc1fa01b6e42f91a3 /sound
parent7d1794e81b5f202c73d7e3e65f0ee7aae4928038 (diff)
parentad1cd745060ae2f24026b3b3d09da3426df6ab36 (diff)
Merge branch 'topic/beep-rename' into topic/hda
Diffstat (limited to 'sound')
-rw-r--r--sound/aoa/codecs/tas.c9
-rw-r--r--sound/arm/aaci.c1
-rw-r--r--sound/core/isadma.c10
-rw-r--r--sound/core/oss/mixer_oss.c4
-rw-r--r--sound/core/pcm.c5
-rw-r--r--sound/drivers/dummy.c2
-rw-r--r--sound/drivers/opl3/opl3_midi.c28
-rw-r--r--sound/drivers/pcsp/pcsp.c32
-rw-r--r--sound/drivers/pcsp/pcsp.h2
-rw-r--r--sound/drivers/pcsp/pcsp_lib.c65
-rw-r--r--sound/drivers/pcsp/pcsp_mixer.c37
-rw-r--r--sound/isa/Kconfig12
-rw-r--r--sound/isa/cmi8330.c4
-rw-r--r--sound/isa/es1688/es1688_lib.c2
-rw-r--r--sound/isa/es18xx.c132
-rw-r--r--sound/isa/sb/sb_mixer.c4
-rw-r--r--sound/isa/sscape.c727
-rw-r--r--sound/isa/wss/wss_lib.c98
-rw-r--r--sound/mips/hal2.c2
-rw-r--r--sound/mips/sgio2audio.c2
-rw-r--r--sound/oss/Kconfig12
-rw-r--r--sound/oss/Makefile1
-rw-r--r--sound/oss/sh_dac_audio.c3
-rw-r--r--sound/oss/sscape.c1480
-rw-r--r--sound/parisc/harmony.c6
-rw-r--r--sound/pci/Kconfig1
-rw-r--r--sound/pci/ac97/ac97_codec.c6
-rw-r--r--sound/pci/ac97/ac97_patch.c12
-rw-r--r--sound/pci/ali5451/ali5451.c2
-rw-r--r--sound/pci/azt3328.c4
-rw-r--r--sound/pci/bt87x.c2
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c4
-rw-r--r--sound/pci/ca0106/ca0106_proc.c4
-rw-r--r--sound/pci/cmipci.c4
-rw-r--r--sound/pci/ctxfi/ctatc.c6
-rw-r--r--sound/pci/echoaudio/echoaudio.c30
-rw-r--r--sound/pci/echoaudio/mia.c1
-rw-r--r--sound/pci/emu10k1/emu10k1x.c3
-rw-r--r--sound/pci/emu10k1/emumixer.c4
-rw-r--r--sound/pci/emu10k1/emuproc.c4
-rw-r--r--sound/pci/emu10k1/io.c2
-rw-r--r--sound/pci/es1938.c2
-rw-r--r--sound/pci/hda/patch_cmedia.c4
-rw-r--r--sound/pci/hda/patch_realtek.c4
-rw-r--r--sound/pci/hda/patch_sigmatel.c6
-rw-r--r--sound/pci/ice1712/amp.c8
-rw-r--r--sound/pci/ice1712/ice1712.c2
-rw-r--r--sound/pci/ice1712/ice1724.c8
-rw-r--r--sound/pci/intel8x0.c12
-rw-r--r--sound/pci/via82xx.c86
-rw-r--r--sound/ppc/awacs.c12
-rw-r--r--sound/ppc/burgundy.c8
-rw-r--r--sound/ppc/keywest.c14
-rw-r--r--sound/ppc/tumbler.c2
-rw-r--r--sound/sh/Kconfig8
-rw-r--r--sound/sh/Makefile2
-rw-r--r--sound/sh/sh_dac_audio.c453
-rw-r--r--sound/soc/blackfin/Kconfig98
-rw-r--r--sound/soc/blackfin/bf5xx-i2s.c8
-rw-r--r--sound/soc/blackfin/bf5xx-tdm.c8
-rw-r--r--sound/soc/codecs/tlv320aic23.c2
-rw-r--r--sound/soc/codecs/wm8350.c4
-rw-r--r--sound/soc/codecs/wm8940.c2
-rw-r--r--sound/soc/codecs/wm9713.c22
-rw-r--r--sound/soc/davinci/davinci-i2s.c37
-rw-r--r--sound/soc/davinci/davinci-mcasp.c80
-rw-r--r--sound/soc/davinci/davinci-mcasp.h7
-rw-r--r--sound/soc/davinci/davinci-pcm.c13
-rw-r--r--sound/soc/davinci/davinci-pcm.h1
-rw-r--r--sound/soc/imx/mxc-ssi.c8
-rw-r--r--sound/soc/pxa/Kconfig2
-rw-r--r--sound/soc/soc-dapm.c5
-rw-r--r--sound/usb/caiaq/audio.c16
-rw-r--r--sound/usb/caiaq/device.c2
-rw-r--r--sound/usb/usbmixer.c23
-rw-r--r--sound/usb/usx2y/us122l.c75
76 files changed, 1433 insertions, 2380 deletions
diff --git a/sound/aoa/codecs/tas.c b/sound/aoa/codecs/tas.c
index f0ebc971c686..1dd66ddffcaf 100644
--- a/sound/aoa/codecs/tas.c
+++ b/sound/aoa/codecs/tas.c
@@ -897,6 +897,15 @@ static int tas_create(struct i2c_adapter *adapter,
897 client = i2c_new_device(adapter, &info); 897 client = i2c_new_device(adapter, &info);
898 if (!client) 898 if (!client)
899 return -ENODEV; 899 return -ENODEV;
900 /*
901 * We know the driver is already loaded, so the device should be
902 * already bound. If not it means binding failed, and then there
903 * is no point in keeping the device instantiated.
904 */
905 if (!client->driver) {
906 i2c_unregister_device(client);
907 return -ENODEV;
908 }
900 909
901 /* 910 /*
902 * Let i2c-core delete that device on driver removal. 911 * Let i2c-core delete that device on driver removal.
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index dc78272fc39f..1f0f8213e2d5 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -937,6 +937,7 @@ static int __devinit aaci_probe_ac97(struct aaci *aaci)
937 struct snd_ac97 *ac97; 937 struct snd_ac97 *ac97;
938 int ret; 938 int ret;
939 939
940 writel(0, aaci->base + AC97_POWERDOWN);
940 /* 941 /*
941 * Assert AACIRESET for 2us 942 * Assert AACIRESET for 2us
942 */ 943 */
diff --git a/sound/core/isadma.c b/sound/core/isadma.c
index 79f0f16af339..950e19ba91fc 100644
--- a/sound/core/isadma.c
+++ b/sound/core/isadma.c
@@ -85,16 +85,24 @@ EXPORT_SYMBOL(snd_dma_disable);
85unsigned int snd_dma_pointer(unsigned long dma, unsigned int size) 85unsigned int snd_dma_pointer(unsigned long dma, unsigned int size)
86{ 86{
87 unsigned long flags; 87 unsigned long flags;
88 unsigned int result; 88 unsigned int result, result1;
89 89
90 flags = claim_dma_lock(); 90 flags = claim_dma_lock();
91 clear_dma_ff(dma); 91 clear_dma_ff(dma);
92 if (!isa_dma_bridge_buggy) 92 if (!isa_dma_bridge_buggy)
93 disable_dma(dma); 93 disable_dma(dma);
94 result = get_dma_residue(dma); 94 result = get_dma_residue(dma);
95 /*
96 * HACK - read the counter again and choose higher value in order to
97 * avoid reading during counter lower byte roll over if the
98 * isa_dma_bridge_buggy is set.
99 */
100 result1 = get_dma_residue(dma);
95 if (!isa_dma_bridge_buggy) 101 if (!isa_dma_bridge_buggy)
96 enable_dma(dma); 102 enable_dma(dma);
97 release_dma_lock(flags); 103 release_dma_lock(flags);
104 if (unlikely(result < result1))
105 result = result1;
98#ifdef CONFIG_SND_DEBUG 106#ifdef CONFIG_SND_DEBUG
99 if (result > size) 107 if (result > size)
100 snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size); 108 snd_printk(KERN_ERR "pointer (0x%x) for DMA #%ld is greater than transfer size (0x%x)\n", result, dma, size);
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 772423889eb3..54e2eb56e4c2 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1251,7 +1251,9 @@ static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
1251 { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */ 1251 { SOUND_MIXER_SYNTH, "FM", 0 }, /* fallback */
1252 { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */ 1252 { SOUND_MIXER_SYNTH, "Music", 0 }, /* fallback */
1253 { SOUND_MIXER_PCM, "PCM", 0 }, 1253 { SOUND_MIXER_PCM, "PCM", 0 },
1254 { SOUND_MIXER_SPEAKER, "PC Speaker", 0 }, 1254 { SOUND_MIXER_SPEAKER, "Beep", 0 },
1255 { SOUND_MIXER_SPEAKER, "PC Speaker", 0 }, /* fallback */
1256 { SOUND_MIXER_SPEAKER, "Speaker", 0 }, /* fallback */
1255 { SOUND_MIXER_LINE, "Line", 0 }, 1257 { SOUND_MIXER_LINE, "Line", 0 },
1256 { SOUND_MIXER_MIC, "Mic", 0 }, 1258 { SOUND_MIXER_MIC, "Mic", 0 },
1257 { SOUND_MIXER_CD, "CD", 0 }, 1259 { SOUND_MIXER_CD, "CD", 0 },
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 0c1440121c22..c69c60b2a48a 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -953,11 +953,12 @@ static int snd_pcm_dev_register(struct snd_device *device)
953 struct snd_pcm_substream *substream; 953 struct snd_pcm_substream *substream;
954 struct snd_pcm_notify *notify; 954 struct snd_pcm_notify *notify;
955 char str[16]; 955 char str[16];
956 struct snd_pcm *pcm = device->device_data; 956 struct snd_pcm *pcm;
957 struct device *dev; 957 struct device *dev;
958 958
959 if (snd_BUG_ON(!pcm || !device)) 959 if (snd_BUG_ON(!device || !device->device_data))
960 return -ENXIO; 960 return -ENXIO;
961 pcm = device->device_data;
961 mutex_lock(&register_mutex); 962 mutex_lock(&register_mutex);
962 err = snd_pcm_add(pcm); 963 err = snd_pcm_add(pcm);
963 if (err) { 964 if (err) {
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 6ba066c41d2e..146ef00f94a3 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -808,8 +808,6 @@ static int __devinit snd_card_dummy_new_mixer(struct snd_dummy *dummy)
808 unsigned int idx; 808 unsigned int idx;
809 int err; 809 int err;
810 810
811 if (snd_BUG_ON(!dummy))
812 return -EINVAL;
813 spin_lock_init(&dummy->mixer_lock); 811 spin_lock_init(&dummy->mixer_lock);
814 strcpy(card->mixername, "Dummy Mixer"); 812 strcpy(card->mixername, "Dummy Mixer");
815 813
diff --git a/sound/drivers/opl3/opl3_midi.c b/sound/drivers/opl3/opl3_midi.c
index 6e7d09ae0e82..7d722a025d0d 100644
--- a/sound/drivers/opl3/opl3_midi.c
+++ b/sound/drivers/opl3/opl3_midi.c
@@ -29,6 +29,8 @@ extern char snd_opl3_regmap[MAX_OPL2_VOICES][4];
29 29
30extern int use_internal_drums; 30extern int use_internal_drums;
31 31
32static void snd_opl3_note_off_unsafe(void *p, int note, int vel,
33 struct snd_midi_channel *chan);
32/* 34/*
33 * The next table looks magical, but it certainly is not. Its values have 35 * The next table looks magical, but it certainly is not. Its values have
34 * been calculated as table[i]=8*log(i/64)/log(2) with an obvious exception 36 * been calculated as table[i]=8*log(i/64)/log(2) with an obvious exception
@@ -242,16 +244,20 @@ void snd_opl3_timer_func(unsigned long data)
242 int again = 0; 244 int again = 0;
243 int i; 245 int i;
244 246
245 spin_lock_irqsave(&opl3->sys_timer_lock, flags); 247 spin_lock_irqsave(&opl3->voice_lock, flags);
246 for (i = 0; i < opl3->max_voices; i++) { 248 for (i = 0; i < opl3->max_voices; i++) {
247 struct snd_opl3_voice *vp = &opl3->voices[i]; 249 struct snd_opl3_voice *vp = &opl3->voices[i];
248 if (vp->state > 0 && vp->note_off_check) { 250 if (vp->state > 0 && vp->note_off_check) {
249 if (vp->note_off == jiffies) 251 if (vp->note_off == jiffies)
250 snd_opl3_note_off(opl3, vp->note, 0, vp->chan); 252 snd_opl3_note_off_unsafe(opl3, vp->note, 0,
253 vp->chan);
251 else 254 else
252 again++; 255 again++;
253 } 256 }
254 } 257 }
258 spin_unlock_irqrestore(&opl3->voice_lock, flags);
259
260 spin_lock_irqsave(&opl3->sys_timer_lock, flags);
255 if (again) { 261 if (again) {
256 opl3->tlist.expires = jiffies + 1; /* invoke again */ 262 opl3->tlist.expires = jiffies + 1; /* invoke again */
257 add_timer(&opl3->tlist); 263 add_timer(&opl3->tlist);
@@ -658,15 +664,14 @@ static void snd_opl3_kill_voice(struct snd_opl3 *opl3, int voice)
658/* 664/*
659 * Release a note in response to a midi note off. 665 * Release a note in response to a midi note off.
660 */ 666 */
661void snd_opl3_note_off(void *p, int note, int vel, struct snd_midi_channel *chan) 667static void snd_opl3_note_off_unsafe(void *p, int note, int vel,
668 struct snd_midi_channel *chan)
662{ 669{
663 struct snd_opl3 *opl3; 670 struct snd_opl3 *opl3;
664 671
665 int voice; 672 int voice;
666 struct snd_opl3_voice *vp; 673 struct snd_opl3_voice *vp;
667 674
668 unsigned long flags;
669
670 opl3 = p; 675 opl3 = p;
671 676
672#ifdef DEBUG_MIDI 677#ifdef DEBUG_MIDI
@@ -674,12 +679,9 @@ void snd_opl3_note_off(void *p, int note, int vel, struct snd_midi_channel *chan
674 chan->number, chan->midi_program, note); 679 chan->number, chan->midi_program, note);
675#endif 680#endif
676 681
677 spin_lock_irqsave(&opl3->voice_lock, flags);
678
679 if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { 682 if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) {
680 if (chan->drum_channel && use_internal_drums) { 683 if (chan->drum_channel && use_internal_drums) {
681 snd_opl3_drum_switch(opl3, note, vel, 0, chan); 684 snd_opl3_drum_switch(opl3, note, vel, 0, chan);
682 spin_unlock_irqrestore(&opl3->voice_lock, flags);
683 return; 685 return;
684 } 686 }
685 /* this loop will hopefully kill all extra voices, because 687 /* this loop will hopefully kill all extra voices, because
@@ -697,6 +699,16 @@ void snd_opl3_note_off(void *p, int note, int vel, struct snd_midi_channel *chan
697 snd_opl3_kill_voice(opl3, voice); 699 snd_opl3_kill_voice(opl3, voice);
698 } 700 }
699 } 701 }
702}
703
704void snd_opl3_note_off(void *p, int note, int vel,
705 struct snd_midi_channel *chan)
706{
707 struct snd_opl3 *opl3 = p;
708 unsigned long flags;
709
710 spin_lock_irqsave(&opl3->voice_lock, flags);
711 snd_opl3_note_off_unsafe(p, note, vel, chan);
700 spin_unlock_irqrestore(&opl3->voice_lock, flags); 712 spin_unlock_irqrestore(&opl3->voice_lock, flags);
701} 713}
702 714
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index b60cef257b58..f165c77d6273 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -26,6 +26,7 @@ MODULE_ALIAS("platform:pcspkr");
26static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */ 26static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
27static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ 27static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
28static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */ 28static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
29static int nopcm; /* Disable PCM capability of the driver */
29 30
30module_param(index, int, 0444); 31module_param(index, int, 0444);
31MODULE_PARM_DESC(index, "Index value for pcsp soundcard."); 32MODULE_PARM_DESC(index, "Index value for pcsp soundcard.");
@@ -33,6 +34,8 @@ module_param(id, charp, 0444);
33MODULE_PARM_DESC(id, "ID string for pcsp soundcard."); 34MODULE_PARM_DESC(id, "ID string for pcsp soundcard.");
34module_param(enable, bool, 0444); 35module_param(enable, bool, 0444);
35MODULE_PARM_DESC(enable, "Enable PC-Speaker sound."); 36MODULE_PARM_DESC(enable, "Enable PC-Speaker sound.");
37module_param(nopcm, bool, 0444);
38MODULE_PARM_DESC(nopcm, "Disable PC-Speaker PCM sound. Only beeps remain.");
36 39
37struct snd_pcsp pcsp_chip; 40struct snd_pcsp pcsp_chip;
38 41
@@ -43,13 +46,16 @@ static int __devinit snd_pcsp_create(struct snd_card *card)
43 int err; 46 int err;
44 int div, min_div, order; 47 int div, min_div, order;
45 48
46 hrtimer_get_res(CLOCK_MONOTONIC, &tp); 49 if (!nopcm) {
47 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) { 50 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
48 printk(KERN_ERR "PCSP: Timer resolution is not sufficient " 51 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) {
49 "(%linS)\n", tp.tv_nsec); 52 printk(KERN_ERR "PCSP: Timer resolution is not sufficient "
50 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI " 53 "(%linS)\n", tp.tv_nsec);
51 "enabled.\n"); 54 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI "
52 return -EIO; 55 "enabled.\n");
56 printk(KERN_ERR "PCSP: Turned into nopcm mode.\n");
57 nopcm = 1;
58 }
53 } 59 }
54 60
55 if (loops_per_jiffy >= PCSP_MIN_LPJ && tp.tv_nsec <= PCSP_MIN_PERIOD_NS) 61 if (loops_per_jiffy >= PCSP_MIN_LPJ && tp.tv_nsec <= PCSP_MIN_PERIOD_NS)
@@ -107,12 +113,14 @@ static int __devinit snd_card_pcsp_probe(int devnum, struct device *dev)
107 snd_card_free(card); 113 snd_card_free(card);
108 return err; 114 return err;
109 } 115 }
110 err = snd_pcsp_new_pcm(&pcsp_chip); 116 if (!nopcm) {
111 if (err < 0) { 117 err = snd_pcsp_new_pcm(&pcsp_chip);
112 snd_card_free(card); 118 if (err < 0) {
113 return err; 119 snd_card_free(card);
120 return err;
121 }
114 } 122 }
115 err = snd_pcsp_new_mixer(&pcsp_chip); 123 err = snd_pcsp_new_mixer(&pcsp_chip, nopcm);
116 if (err < 0) { 124 if (err < 0) {
117 snd_card_free(card); 125 snd_card_free(card);
118 return err; 126 return err;
diff --git a/sound/drivers/pcsp/pcsp.h b/sound/drivers/pcsp/pcsp.h
index 174dd2ff0f22..1e123077923d 100644
--- a/sound/drivers/pcsp/pcsp.h
+++ b/sound/drivers/pcsp/pcsp.h
@@ -83,6 +83,6 @@ extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
83extern void pcsp_sync_stop(struct snd_pcsp *chip); 83extern void pcsp_sync_stop(struct snd_pcsp *chip);
84 84
85extern int snd_pcsp_new_pcm(struct snd_pcsp *chip); 85extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
86extern int snd_pcsp_new_mixer(struct snd_pcsp *chip); 86extern int snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm);
87 87
88#endif 88#endif
diff --git a/sound/drivers/pcsp/pcsp_lib.c b/sound/drivers/pcsp/pcsp_lib.c
index 84cc2658c05b..e1145ac6e908 100644
--- a/sound/drivers/pcsp/pcsp_lib.c
+++ b/sound/drivers/pcsp/pcsp_lib.c
@@ -39,25 +39,20 @@ static DECLARE_TASKLET(pcsp_pcm_tasklet, pcsp_call_pcm_elapsed, 0);
39/* write the port and returns the next expire time in ns; 39/* write the port and returns the next expire time in ns;
40 * called at the trigger-start and in hrtimer callback 40 * called at the trigger-start and in hrtimer callback
41 */ 41 */
42static unsigned long pcsp_timer_update(struct hrtimer *handle) 42static u64 pcsp_timer_update(struct snd_pcsp *chip)
43{ 43{
44 unsigned char timer_cnt, val; 44 unsigned char timer_cnt, val;
45 u64 ns; 45 u64 ns;
46 struct snd_pcm_substream *substream; 46 struct snd_pcm_substream *substream;
47 struct snd_pcm_runtime *runtime; 47 struct snd_pcm_runtime *runtime;
48 struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
49 unsigned long flags; 48 unsigned long flags;
50 49
51 if (chip->thalf) { 50 if (chip->thalf) {
52 outb(chip->val61, 0x61); 51 outb(chip->val61, 0x61);
53 chip->thalf = 0; 52 chip->thalf = 0;
54 if (!atomic_read(&chip->timer_active))
55 return 0;
56 return chip->ns_rem; 53 return chip->ns_rem;
57 } 54 }
58 55
59 if (!atomic_read(&chip->timer_active))
60 return 0;
61 substream = chip->playback_substream; 56 substream = chip->playback_substream;
62 if (!substream) 57 if (!substream)
63 return 0; 58 return 0;
@@ -88,24 +83,17 @@ static unsigned long pcsp_timer_update(struct hrtimer *handle)
88 return ns; 83 return ns;
89} 84}
90 85
91enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle) 86static void pcsp_pointer_update(struct snd_pcsp *chip)
92{ 87{
93 struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
94 struct snd_pcm_substream *substream; 88 struct snd_pcm_substream *substream;
95 int periods_elapsed, pointer_update;
96 size_t period_bytes, buffer_bytes; 89 size_t period_bytes, buffer_bytes;
97 unsigned long ns; 90 int periods_elapsed;
98 unsigned long flags; 91 unsigned long flags;
99 92
100 pointer_update = !chip->thalf;
101 ns = pcsp_timer_update(handle);
102 if (!ns)
103 return HRTIMER_NORESTART;
104
105 /* update the playback position */ 93 /* update the playback position */
106 substream = chip->playback_substream; 94 substream = chip->playback_substream;
107 if (!substream) 95 if (!substream)
108 return HRTIMER_NORESTART; 96 return;
109 97
110 period_bytes = snd_pcm_lib_period_bytes(substream); 98 period_bytes = snd_pcm_lib_period_bytes(substream);
111 buffer_bytes = snd_pcm_lib_buffer_bytes(substream); 99 buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
@@ -134,6 +122,26 @@ enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
134 122
135 if (periods_elapsed) 123 if (periods_elapsed)
136 tasklet_schedule(&pcsp_pcm_tasklet); 124 tasklet_schedule(&pcsp_pcm_tasklet);
125}
126
127enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
128{
129 struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
130 int pointer_update;
131 u64 ns;
132
133 if (!atomic_read(&chip->timer_active) || !chip->playback_substream)
134 return HRTIMER_NORESTART;
135
136 pointer_update = !chip->thalf;
137 ns = pcsp_timer_update(chip);
138 if (!ns) {
139 printk(KERN_WARNING "PCSP: unexpected stop\n");
140 return HRTIMER_NORESTART;
141 }
142
143 if (pointer_update)
144 pcsp_pointer_update(chip);
137 145
138 hrtimer_forward(handle, hrtimer_get_expires(handle), ns_to_ktime(ns)); 146 hrtimer_forward(handle, hrtimer_get_expires(handle), ns_to_ktime(ns));
139 147
@@ -142,8 +150,6 @@ enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
142 150
143static int pcsp_start_playing(struct snd_pcsp *chip) 151static int pcsp_start_playing(struct snd_pcsp *chip)
144{ 152{
145 unsigned long ns;
146
147#if PCSP_DEBUG 153#if PCSP_DEBUG
148 printk(KERN_INFO "PCSP: start_playing called\n"); 154 printk(KERN_INFO "PCSP: start_playing called\n");
149#endif 155#endif
@@ -159,11 +165,7 @@ static int pcsp_start_playing(struct snd_pcsp *chip)
159 atomic_set(&chip->timer_active, 1); 165 atomic_set(&chip->timer_active, 1);
160 chip->thalf = 0; 166 chip->thalf = 0;
161 167
162 ns = pcsp_timer_update(&pcsp_chip.timer); 168 hrtimer_start(&pcsp_chip.timer, ktime_set(0, 0), HRTIMER_MODE_REL);
163 if (!ns)
164 return -EIO;
165
166 hrtimer_start(&pcsp_chip.timer, ktime_set(0, ns), HRTIMER_MODE_REL);
167 return 0; 169 return 0;
168} 170}
169 171
@@ -232,21 +234,22 @@ static int snd_pcsp_playback_hw_free(struct snd_pcm_substream *substream)
232static int snd_pcsp_playback_prepare(struct snd_pcm_substream *substream) 234static int snd_pcsp_playback_prepare(struct snd_pcm_substream *substream)
233{ 235{
234 struct snd_pcsp *chip = snd_pcm_substream_chip(substream); 236 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
237 pcsp_sync_stop(chip);
238 chip->playback_ptr = 0;
239 chip->period_ptr = 0;
240 chip->fmt_size =
241 snd_pcm_format_physical_width(substream->runtime->format) >> 3;
242 chip->is_signed = snd_pcm_format_signed(substream->runtime->format);
235#if PCSP_DEBUG 243#if PCSP_DEBUG
236 printk(KERN_INFO "PCSP: prepare called, " 244 printk(KERN_INFO "PCSP: prepare called, "
237 "size=%zi psize=%zi f=%zi f1=%i\n", 245 "size=%zi psize=%zi f=%zi f1=%i fsize=%i\n",
238 snd_pcm_lib_buffer_bytes(substream), 246 snd_pcm_lib_buffer_bytes(substream),
239 snd_pcm_lib_period_bytes(substream), 247 snd_pcm_lib_period_bytes(substream),
240 snd_pcm_lib_buffer_bytes(substream) / 248 snd_pcm_lib_buffer_bytes(substream) /
241 snd_pcm_lib_period_bytes(substream), 249 snd_pcm_lib_period_bytes(substream),
242 substream->runtime->periods); 250 substream->runtime->periods,
251 chip->fmt_size);
243#endif 252#endif
244 pcsp_sync_stop(chip);
245 chip->playback_ptr = 0;
246 chip->period_ptr = 0;
247 chip->fmt_size =
248 snd_pcm_format_physical_width(substream->runtime->format) >> 3;
249 chip->is_signed = snd_pcm_format_signed(substream->runtime->format);
250 return 0; 253 return 0;
251} 254}
252 255
diff --git a/sound/drivers/pcsp/pcsp_mixer.c b/sound/drivers/pcsp/pcsp_mixer.c
index 199b03377142..6f633f4f3b96 100644
--- a/sound/drivers/pcsp/pcsp_mixer.c
+++ b/sound/drivers/pcsp/pcsp_mixer.c
@@ -72,7 +72,7 @@ static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
72 if (treble != chip->treble) { 72 if (treble != chip->treble) {
73 chip->treble = treble; 73 chip->treble = treble;
74#if PCSP_DEBUG 74#if PCSP_DEBUG
75 printk(KERN_INFO "PCSP: rate set to %i\n", PCSP_RATE()); 75 printk(KERN_INFO "PCSP: rate set to %li\n", PCSP_RATE());
76#endif 76#endif
77 changed = 1; 77 changed = 1;
78 } 78 }
@@ -119,24 +119,43 @@ static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
119 .put = pcsp_##ctl_type##_put, \ 119 .put = pcsp_##ctl_type##_put, \
120} 120}
121 121
122static struct snd_kcontrol_new __devinitdata snd_pcsp_controls[] = { 122static struct snd_kcontrol_new __devinitdata snd_pcsp_controls_pcm[] = {
123 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"), 123 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
124 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"), 124 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
125 PCSP_MIXER_CONTROL(pcspkr, "PC Speaker Playback Switch"),
126}; 125};
127 126
128int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip) 127static struct snd_kcontrol_new __devinitdata snd_pcsp_controls_spkr[] = {
128 PCSP_MIXER_CONTROL(pcspkr, "Beep Playback Switch"),
129};
130
131static int __devinit snd_pcsp_ctls_add(struct snd_pcsp *chip,
132 struct snd_kcontrol_new *ctls, int num)
129{ 133{
130 struct snd_card *card = chip->card;
131 int i, err; 134 int i, err;
135 struct snd_card *card = chip->card;
136 for (i = 0; i < num; i++) {
137 err = snd_ctl_add(card, snd_ctl_new1(ctls + i, chip));
138 if (err < 0)
139 return err;
140 }
141 return 0;
142}
143
144int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip, int nopcm)
145{
146 int err;
147 struct snd_card *card = chip->card;
132 148
133 for (i = 0; i < ARRAY_SIZE(snd_pcsp_controls); i++) { 149 if (!nopcm) {
134 err = snd_ctl_add(card, 150 err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_pcm,
135 snd_ctl_new1(snd_pcsp_controls + i, 151 ARRAY_SIZE(snd_pcsp_controls_pcm));
136 chip));
137 if (err < 0) 152 if (err < 0)
138 return err; 153 return err;
139 } 154 }
155 err = snd_pcsp_ctls_add(chip, snd_pcsp_controls_spkr,
156 ARRAY_SIZE(snd_pcsp_controls_spkr));
157 if (err < 0)
158 return err;
140 159
141 strcpy(card->mixername, "PC-Speaker"); 160 strcpy(card->mixername, "PC-Speaker");
142 161
diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig
index 51a7e3777e17..02fe81ca88fd 100644
--- a/sound/isa/Kconfig
+++ b/sound/isa/Kconfig
@@ -372,15 +372,21 @@ config SND_SGALAXY
372 372
373config SND_SSCAPE 373config SND_SSCAPE
374 tristate "Ensoniq SoundScape driver" 374 tristate "Ensoniq SoundScape driver"
375 select SND_HWDEP
376 select SND_MPU401_UART 375 select SND_MPU401_UART
377 select SND_WSS_LIB 376 select SND_WSS_LIB
377 select FW_LOADER
378 help 378 help
379 Say Y here to include support for Ensoniq SoundScape 379 Say Y here to include support for Ensoniq SoundScape
380 soundcards. 380 and Ensoniq OEM soundcards.
381 381
382 The PCM audio is supported on SoundScape Classic, Elite, PnP 382 The PCM audio is supported on SoundScape Classic, Elite, PnP
383 and VIVO cards. The MIDI support is very experimental. 383 and VIVO cards. The supported OEM cards are SPEA Media FX and
384 Reveal SC-600.
385 The MIDI support is very experimental and requires binary
386 firmware files called "scope.cod" and "sndscape.co?" where the
387 ? is digit 0, 1, 2, 3 or 4. The firmware files can be found
388 in DOS or Windows driver packages. One has to put the firmware
389 files into the /lib/firmware directory.
384 390
385 To compile this driver as a module, choose M here: the module 391 To compile this driver as a module, choose M here: the module
386 will be called snd-sscape. 392 will be called snd-sscape.
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
index 02f79d252718..8246aae32ab4 100644
--- a/sound/isa/cmi8330.c
+++ b/sound/isa/cmi8330.c
@@ -237,7 +237,7 @@ WSS_DOUBLE("Wavetable Capture Volume", 0,
237 CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0), 237 CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0),
238WSS_SINGLE("3D Control - Switch", 0, 238WSS_SINGLE("3D Control - Switch", 0,
239 CMI8330_RMUX3D, 5, 1, 1), 239 CMI8330_RMUX3D, 5, 1, 1),
240WSS_SINGLE("PC Speaker Playback Volume", 0, 240WSS_SINGLE("Beep Playback Volume", 0,
241 CMI8330_OUTPUTVOL, 3, 3, 0), 241 CMI8330_OUTPUTVOL, 3, 3, 0),
242WSS_DOUBLE("FM Playback Switch", 0, 242WSS_DOUBLE("FM Playback Switch", 0,
243 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 243 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
@@ -262,7 +262,7 @@ SB_DOUBLE("SB Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3,
262SB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31), 262SB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
263SB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1), 263SB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
264SB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31), 264SB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
265SB_SINGLE("SB PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3), 265SB_SINGLE("SB Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
266SB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3), 266SB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
267SB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3), 267SB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
268SB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1), 268SB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c
index 4c6e14f87f2d..c76bb00c9d15 100644
--- a/sound/isa/es1688/es1688_lib.c
+++ b/sound/isa/es1688/es1688_lib.c
@@ -982,7 +982,7 @@ ES1688_DOUBLE("CD Playback Volume", 0, ES1688_CD_DEV, ES1688_CD_DEV, 4, 0, 15, 0
982ES1688_DOUBLE("FM Playback Volume", 0, ES1688_FM_DEV, ES1688_FM_DEV, 4, 0, 15, 0), 982ES1688_DOUBLE("FM Playback Volume", 0, ES1688_FM_DEV, ES1688_FM_DEV, 4, 0, 15, 0),
983ES1688_DOUBLE("Mic Playback Volume", 0, ES1688_MIC_DEV, ES1688_MIC_DEV, 4, 0, 15, 0), 983ES1688_DOUBLE("Mic Playback Volume", 0, ES1688_MIC_DEV, ES1688_MIC_DEV, 4, 0, 15, 0),
984ES1688_DOUBLE("Aux Playback Volume", 0, ES1688_AUX_DEV, ES1688_AUX_DEV, 4, 0, 15, 0), 984ES1688_DOUBLE("Aux Playback Volume", 0, ES1688_AUX_DEV, ES1688_AUX_DEV, 4, 0, 15, 0),
985ES1688_SINGLE("PC Speaker Playback Volume", 0, ES1688_SPEAKER_DEV, 0, 7, 0), 985ES1688_SINGLE("Beep Playback Volume", 0, ES1688_SPEAKER_DEV, 0, 7, 0),
986ES1688_DOUBLE("Capture Volume", 0, ES1688_RECLEV_DEV, ES1688_RECLEV_DEV, 4, 0, 15, 0), 986ES1688_DOUBLE("Capture Volume", 0, ES1688_RECLEV_DEV, ES1688_RECLEV_DEV, 4, 0, 15, 0),
987ES1688_SINGLE("Capture Switch", 0, ES1688_REC_DEV, 4, 1, 1), 987ES1688_SINGLE("Capture Switch", 0, ES1688_REC_DEV, 4, 1, 1),
988{ 988{
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index 8cfbff73a835..e5bf3355d2ca 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -121,7 +121,6 @@ struct snd_es18xx {
121 unsigned int dma1_shift; 121 unsigned int dma1_shift;
122 unsigned int dma2_shift; 122 unsigned int dma2_shift;
123 123
124 struct snd_card *card;
125 struct snd_pcm *pcm; 124 struct snd_pcm *pcm;
126 struct snd_pcm_substream *playback_a_substream; 125 struct snd_pcm_substream *playback_a_substream;
127 struct snd_pcm_substream *capture_a_substream; 126 struct snd_pcm_substream *capture_a_substream;
@@ -140,10 +139,6 @@ struct snd_es18xx {
140#ifdef CONFIG_PM 139#ifdef CONFIG_PM
141 unsigned char pm_reg; 140 unsigned char pm_reg;
142#endif 141#endif
143};
144
145struct snd_audiodrive {
146 struct snd_es18xx *chip;
147#ifdef CONFIG_PNP 142#ifdef CONFIG_PNP
148 struct pnp_dev *dev; 143 struct pnp_dev *dev;
149 struct pnp_dev *devc; 144 struct pnp_dev *devc;
@@ -755,7 +750,8 @@ static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream,
755 750
756static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id) 751static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
757{ 752{
758 struct snd_es18xx *chip = dev_id; 753 struct snd_card *card = dev_id;
754 struct snd_es18xx *chip = card->private_data;
759 unsigned char status; 755 unsigned char status;
760 756
761 if (chip->caps & ES18XX_CONTROL) { 757 if (chip->caps & ES18XX_CONTROL) {
@@ -805,12 +801,16 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
805 int split = 0; 801 int split = 0;
806 if (chip->caps & ES18XX_HWV) { 802 if (chip->caps & ES18XX_HWV) {
807 split = snd_es18xx_mixer_read(chip, 0x64) & 0x80; 803 split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
808 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id); 804 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
809 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id); 805 &chip->hw_switch->id);
806 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
807 &chip->hw_volume->id);
810 } 808 }
811 if (!split) { 809 if (!split) {
812 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_switch->id); 810 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
813 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->master_volume->id); 811 &chip->master_switch->id);
812 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE,
813 &chip->master_volume->id);
814 } 814 }
815 /* ack interrupt */ 815 /* ack interrupt */
816 snd_es18xx_mixer_write(chip, 0x66, 0x00); 816 snd_es18xx_mixer_write(chip, 0x66, 0x00);
@@ -1313,7 +1313,7 @@ ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
1313 * The chipset specific mixer controls 1313 * The chipset specific mixer controls
1314 */ 1314 */
1315static struct snd_kcontrol_new snd_es18xx_opt_speaker = 1315static struct snd_kcontrol_new snd_es18xx_opt_speaker =
1316 ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0); 1316 ES18XX_SINGLE("Beep Playback Volume", 0, 0x3c, 0, 7, 0);
1317 1317
1318static struct snd_kcontrol_new snd_es18xx_opt_1869[] = { 1318static struct snd_kcontrol_new snd_es18xx_opt_1869[] = {
1319ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), 1319ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
@@ -1691,8 +1691,10 @@ static struct snd_pcm_ops snd_es18xx_capture_ops = {
1691 .pointer = snd_es18xx_capture_pointer, 1691 .pointer = snd_es18xx_capture_pointer,
1692}; 1692};
1693 1693
1694static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct snd_pcm ** rpcm) 1694static int __devinit snd_es18xx_pcm(struct snd_card *card, int device,
1695 struct snd_pcm **rpcm)
1695{ 1696{
1697 struct snd_es18xx *chip = card->private_data;
1696 struct snd_pcm *pcm; 1698 struct snd_pcm *pcm;
1697 char str[16]; 1699 char str[16];
1698 int err; 1700 int err;
@@ -1701,9 +1703,9 @@ static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct
1701 *rpcm = NULL; 1703 *rpcm = NULL;
1702 sprintf(str, "ES%x", chip->version); 1704 sprintf(str, "ES%x", chip->version);
1703 if (chip->caps & ES18XX_PCM2) 1705 if (chip->caps & ES18XX_PCM2)
1704 err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm); 1706 err = snd_pcm_new(card, str, device, 2, 1, &pcm);
1705 else 1707 else
1706 err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm); 1708 err = snd_pcm_new(card, str, device, 1, 1, &pcm);
1707 if (err < 0) 1709 if (err < 0)
1708 return err; 1710 return err;
1709 1711
@@ -1734,10 +1736,9 @@ static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct
1734#ifdef CONFIG_PM 1736#ifdef CONFIG_PM
1735static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state) 1737static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1736{ 1738{
1737 struct snd_audiodrive *acard = card->private_data; 1739 struct snd_es18xx *chip = card->private_data;
1738 struct snd_es18xx *chip = acard->chip;
1739 1740
1740 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot); 1741 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1741 1742
1742 snd_pcm_suspend_all(chip->pcm); 1743 snd_pcm_suspend_all(chip->pcm);
1743 1744
@@ -1752,24 +1753,25 @@ static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
1752 1753
1753static int snd_es18xx_resume(struct snd_card *card) 1754static int snd_es18xx_resume(struct snd_card *card)
1754{ 1755{
1755 struct snd_audiodrive *acard = card->private_data; 1756 struct snd_es18xx *chip = card->private_data;
1756 struct snd_es18xx *chip = acard->chip;
1757 1757
1758 /* restore PM register, we won't wake till (not 0x07) i/o activity though */ 1758 /* restore PM register, we won't wake till (not 0x07) i/o activity though */
1759 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM); 1759 snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
1760 1760
1761 snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); 1761 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1762 return 0; 1762 return 0;
1763} 1763}
1764#endif /* CONFIG_PM */ 1764#endif /* CONFIG_PM */
1765 1765
1766static int snd_es18xx_free(struct snd_es18xx *chip) 1766static int snd_es18xx_free(struct snd_card *card)
1767{ 1767{
1768 struct snd_es18xx *chip = card->private_data;
1769
1768 release_and_free_resource(chip->res_port); 1770 release_and_free_resource(chip->res_port);
1769 release_and_free_resource(chip->res_ctrl_port); 1771 release_and_free_resource(chip->res_ctrl_port);
1770 release_and_free_resource(chip->res_mpu_port); 1772 release_and_free_resource(chip->res_mpu_port);
1771 if (chip->irq >= 0) 1773 if (chip->irq >= 0)
1772 free_irq(chip->irq, (void *) chip); 1774 free_irq(chip->irq, (void *) card);
1773 if (chip->dma1 >= 0) { 1775 if (chip->dma1 >= 0) {
1774 disable_dma(chip->dma1); 1776 disable_dma(chip->dma1);
1775 free_dma(chip->dma1); 1777 free_dma(chip->dma1);
@@ -1778,37 +1780,29 @@ static int snd_es18xx_free(struct snd_es18xx *chip)
1778 disable_dma(chip->dma2); 1780 disable_dma(chip->dma2);
1779 free_dma(chip->dma2); 1781 free_dma(chip->dma2);
1780 } 1782 }
1781 kfree(chip);
1782 return 0; 1783 return 0;
1783} 1784}
1784 1785
1785static int snd_es18xx_dev_free(struct snd_device *device) 1786static int snd_es18xx_dev_free(struct snd_device *device)
1786{ 1787{
1787 struct snd_es18xx *chip = device->device_data; 1788 return snd_es18xx_free(device->card);
1788 return snd_es18xx_free(chip);
1789} 1789}
1790 1790
1791static int __devinit snd_es18xx_new_device(struct snd_card *card, 1791static int __devinit snd_es18xx_new_device(struct snd_card *card,
1792 unsigned long port, 1792 unsigned long port,
1793 unsigned long mpu_port, 1793 unsigned long mpu_port,
1794 unsigned long fm_port, 1794 unsigned long fm_port,
1795 int irq, int dma1, int dma2, 1795 int irq, int dma1, int dma2)
1796 struct snd_es18xx ** rchip)
1797{ 1796{
1798 struct snd_es18xx *chip; 1797 struct snd_es18xx *chip = card->private_data;
1799 static struct snd_device_ops ops = { 1798 static struct snd_device_ops ops = {
1800 .dev_free = snd_es18xx_dev_free, 1799 .dev_free = snd_es18xx_dev_free,
1801 }; 1800 };
1802 int err; 1801 int err;
1803 1802
1804 *rchip = NULL;
1805 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1806 if (chip == NULL)
1807 return -ENOMEM;
1808 spin_lock_init(&chip->reg_lock); 1803 spin_lock_init(&chip->reg_lock);
1809 spin_lock_init(&chip->mixer_lock); 1804 spin_lock_init(&chip->mixer_lock);
1810 spin_lock_init(&chip->ctrl_lock); 1805 spin_lock_init(&chip->ctrl_lock);
1811 chip->card = card;
1812 chip->port = port; 1806 chip->port = port;
1813 chip->mpu_port = mpu_port; 1807 chip->mpu_port = mpu_port;
1814 chip->fm_port = fm_port; 1808 chip->fm_port = fm_port;
@@ -1818,53 +1812,53 @@ static int __devinit snd_es18xx_new_device(struct snd_card *card,
1818 chip->audio2_vol = 0x00; 1812 chip->audio2_vol = 0x00;
1819 chip->active = 0; 1813 chip->active = 0;
1820 1814
1821 if ((chip->res_port = request_region(port, 16, "ES18xx")) == NULL) { 1815 chip->res_port = request_region(port, 16, "ES18xx");
1822 snd_es18xx_free(chip); 1816 if (chip->res_port == NULL) {
1817 snd_es18xx_free(card);
1823 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1); 1818 snd_printk(KERN_ERR PFX "unable to grap ports 0x%lx-0x%lx\n", port, port + 16 - 1);
1824 return -EBUSY; 1819 return -EBUSY;
1825 } 1820 }
1826 1821
1827 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx", (void *) chip)) { 1822 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx",
1828 snd_es18xx_free(chip); 1823 (void *) card)) {
1824 snd_es18xx_free(card);
1829 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq); 1825 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
1830 return -EBUSY; 1826 return -EBUSY;
1831 } 1827 }
1832 chip->irq = irq; 1828 chip->irq = irq;
1833 1829
1834 if (request_dma(dma1, "ES18xx DMA 1")) { 1830 if (request_dma(dma1, "ES18xx DMA 1")) {
1835 snd_es18xx_free(chip); 1831 snd_es18xx_free(card);
1836 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1); 1832 snd_printk(KERN_ERR PFX "unable to grap DMA1 %d\n", dma1);
1837 return -EBUSY; 1833 return -EBUSY;
1838 } 1834 }
1839 chip->dma1 = dma1; 1835 chip->dma1 = dma1;
1840 1836
1841 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) { 1837 if (dma2 != dma1 && request_dma(dma2, "ES18xx DMA 2")) {
1842 snd_es18xx_free(chip); 1838 snd_es18xx_free(card);
1843 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2); 1839 snd_printk(KERN_ERR PFX "unable to grap DMA2 %d\n", dma2);
1844 return -EBUSY; 1840 return -EBUSY;
1845 } 1841 }
1846 chip->dma2 = dma2; 1842 chip->dma2 = dma2;
1847 1843
1848 if (snd_es18xx_probe(chip) < 0) { 1844 if (snd_es18xx_probe(chip) < 0) {
1849 snd_es18xx_free(chip); 1845 snd_es18xx_free(card);
1850 return -ENODEV; 1846 return -ENODEV;
1851 } 1847 }
1852 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1848 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, NULL, &ops);
1853 snd_es18xx_free(chip); 1849 if (err < 0) {
1850 snd_es18xx_free(card);
1854 return err; 1851 return err;
1855 } 1852 }
1856 *rchip = chip;
1857 return 0; 1853 return 0;
1858} 1854}
1859 1855
1860static int __devinit snd_es18xx_mixer(struct snd_es18xx *chip) 1856static int __devinit snd_es18xx_mixer(struct snd_card *card)
1861{ 1857{
1862 struct snd_card *card; 1858 struct snd_es18xx *chip = card->private_data;
1863 int err; 1859 int err;
1864 unsigned int idx; 1860 unsigned int idx;
1865 1861
1866 card = chip->card;
1867
1868 strcpy(card->mixername, chip->pcm->name); 1862 strcpy(card->mixername, chip->pcm->name);
1869 1863
1870 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) { 1864 for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
@@ -2063,11 +2057,11 @@ static int __devinit snd_audiodrive_pnp_init_main(int dev, struct pnp_dev *pdev)
2063 return 0; 2057 return 0;
2064} 2058}
2065 2059
2066static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard, 2060static int __devinit snd_audiodrive_pnp(int dev, struct snd_es18xx *chip,
2067 struct pnp_dev *pdev) 2061 struct pnp_dev *pdev)
2068{ 2062{
2069 acard->dev = pdev; 2063 chip->dev = pdev;
2070 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) 2064 if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0)
2071 return -EBUSY; 2065 return -EBUSY;
2072 return 0; 2066 return 0;
2073} 2067}
@@ -2093,26 +2087,26 @@ static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
2093 2087
2094MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids); 2088MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
2095 2089
2096static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard, 2090static int __devinit snd_audiodrive_pnpc(int dev, struct snd_es18xx *chip,
2097 struct pnp_card_link *card, 2091 struct pnp_card_link *card,
2098 const struct pnp_card_device_id *id) 2092 const struct pnp_card_device_id *id)
2099{ 2093{
2100 acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL); 2094 chip->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
2101 if (acard->dev == NULL) 2095 if (chip->dev == NULL)
2102 return -EBUSY; 2096 return -EBUSY;
2103 2097
2104 acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL); 2098 chip->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
2105 if (acard->devc == NULL) 2099 if (chip->devc == NULL)
2106 return -EBUSY; 2100 return -EBUSY;
2107 2101
2108 /* Control port initialization */ 2102 /* Control port initialization */
2109 if (pnp_activate_dev(acard->devc) < 0) { 2103 if (pnp_activate_dev(chip->devc) < 0) {
2110 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n"); 2104 snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
2111 return -EAGAIN; 2105 return -EAGAIN;
2112 } 2106 }
2113 snd_printdd("pnp: port=0x%llx\n", 2107 snd_printdd("pnp: port=0x%llx\n",
2114 (unsigned long long)pnp_port_start(acard->devc, 0)); 2108 (unsigned long long)pnp_port_start(chip->devc, 0));
2115 if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0) 2109 if (snd_audiodrive_pnp_init_main(dev, chip->dev) < 0)
2116 return -EBUSY; 2110 return -EBUSY;
2117 2111
2118 return 0; 2112 return 0;
@@ -2128,24 +2122,20 @@ static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard,
2128static int snd_es18xx_card_new(int dev, struct snd_card **cardp) 2122static int snd_es18xx_card_new(int dev, struct snd_card **cardp)
2129{ 2123{
2130 return snd_card_create(index[dev], id[dev], THIS_MODULE, 2124 return snd_card_create(index[dev], id[dev], THIS_MODULE,
2131 sizeof(struct snd_audiodrive), cardp); 2125 sizeof(struct snd_es18xx), cardp);
2132} 2126}
2133 2127
2134static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev) 2128static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2135{ 2129{
2136 struct snd_audiodrive *acard = card->private_data; 2130 struct snd_es18xx *chip = card->private_data;
2137 struct snd_es18xx *chip;
2138 struct snd_opl3 *opl3; 2131 struct snd_opl3 *opl3;
2139 int err; 2132 int err;
2140 2133
2141 if ((err = snd_es18xx_new_device(card, 2134 err = snd_es18xx_new_device(card,
2142 port[dev], 2135 port[dev], mpu_port[dev], fm_port[dev],
2143 mpu_port[dev], 2136 irq[dev], dma1[dev], dma2[dev]);
2144 fm_port[dev], 2137 if (err < 0)
2145 irq[dev], dma1[dev], dma2[dev],
2146 &chip)) < 0)
2147 return err; 2138 return err;
2148 acard->chip = chip;
2149 2139
2150 sprintf(card->driver, "ES%x", chip->version); 2140 sprintf(card->driver, "ES%x", chip->version);
2151 2141
@@ -2161,10 +2151,12 @@ static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2161 chip->port, 2151 chip->port,
2162 irq[dev], dma1[dev]); 2152 irq[dev], dma1[dev]);
2163 2153
2164 if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0) 2154 err = snd_es18xx_pcm(card, 0, NULL);
2155 if (err < 0)
2165 return err; 2156 return err;
2166 2157
2167 if ((err = snd_es18xx_mixer(chip)) < 0) 2158 err = snd_es18xx_mixer(card);
2159 if (err < 0)
2168 return err; 2160 return err;
2169 2161
2170 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) { 2162 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
diff --git a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c
index 475220bbcc96..318ff0c823e7 100644
--- a/sound/isa/sb/sb_mixer.c
+++ b/sound/isa/sb/sb_mixer.c
@@ -631,7 +631,7 @@ static struct sbmix_elem snd_sb16_ctl_mic_play_switch =
631static struct sbmix_elem snd_sb16_ctl_mic_play_vol = 631static struct sbmix_elem snd_sb16_ctl_mic_play_vol =
632 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31); 632 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31);
633static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol = 633static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol =
634 SB_SINGLE("PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3); 634 SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3);
635static struct sbmix_elem snd_sb16_ctl_capture_vol = 635static struct sbmix_elem snd_sb16_ctl_capture_vol =
636 SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3); 636 SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3);
637static struct sbmix_elem snd_sb16_ctl_play_vol = 637static struct sbmix_elem snd_sb16_ctl_play_vol =
@@ -689,7 +689,7 @@ static struct sbmix_elem snd_dt019x_ctl_cd_play_vol =
689static struct sbmix_elem snd_dt019x_ctl_mic_play_vol = 689static struct sbmix_elem snd_dt019x_ctl_mic_play_vol =
690 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7); 690 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7);
691static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol = 691static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol =
692 SB_SINGLE("PC Speaker Volume", SB_DT019X_SPKR_DEV, 0, 7); 692 SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV, 0, 7);
693static struct sbmix_elem snd_dt019x_ctl_line_play_vol = 693static struct sbmix_elem snd_dt019x_ctl_line_play_vol =
694 SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15); 694 SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15);
695static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch = 695static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch =
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c
index 66187122377c..e2d5d2d3ed96 100644
--- a/sound/isa/sscape.c
+++ b/sound/isa/sscape.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Low-level ALSA driver for the ENSONIQ SoundScape PnP 2 * Low-level ALSA driver for the ENSONIQ SoundScape
3 * Copyright (c) by Chris Rankin 3 * Copyright (c) by Chris Rankin
4 * 4 *
5 * This driver was written in part using information obtained from 5 * This driver was written in part using information obtained from
@@ -25,31 +25,36 @@
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/isa.h> 26#include <linux/isa.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/firmware.h>
28#include <linux/pnp.h> 29#include <linux/pnp.h>
29#include <linux/spinlock.h> 30#include <linux/spinlock.h>
30#include <linux/moduleparam.h> 31#include <linux/moduleparam.h>
31#include <asm/dma.h> 32#include <asm/dma.h>
32#include <sound/core.h> 33#include <sound/core.h>
33#include <sound/hwdep.h>
34#include <sound/wss.h> 34#include <sound/wss.h>
35#include <sound/mpu401.h> 35#include <sound/mpu401.h>
36#include <sound/initval.h> 36#include <sound/initval.h>
37 37
38#include <sound/sscape_ioctl.h>
39
40 38
41MODULE_AUTHOR("Chris Rankin"); 39MODULE_AUTHOR("Chris Rankin");
42MODULE_DESCRIPTION("ENSONIQ SoundScape PnP driver"); 40MODULE_DESCRIPTION("ENSONIQ SoundScape driver");
43MODULE_LICENSE("GPL"); 41MODULE_LICENSE("GPL");
44 42MODULE_FIRMWARE("sndscape.co0");
45static int index[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IDX; 43MODULE_FIRMWARE("sndscape.co1");
46static char* id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_STR; 44MODULE_FIRMWARE("sndscape.co2");
47static long port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 45MODULE_FIRMWARE("sndscape.co3");
48static long wss_port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT; 46MODULE_FIRMWARE("sndscape.co4");
49static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 47MODULE_FIRMWARE("scope.cod");
50static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ; 48
51static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA; 49static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
52static int dma2[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA; 50static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
51static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
52static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
53static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
54static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
55static int dma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
56static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
57static bool joystick[SNDRV_CARDS];
53 58
54module_param_array(index, int, NULL, 0444); 59module_param_array(index, int, NULL, 0444);
55MODULE_PARM_DESC(index, "Index number for SoundScape soundcard"); 60MODULE_PARM_DESC(index, "Index number for SoundScape soundcard");
@@ -75,6 +80,9 @@ MODULE_PARM_DESC(dma, "DMA # for SoundScape driver.");
75module_param_array(dma2, int, NULL, 0444); 80module_param_array(dma2, int, NULL, 0444);
76MODULE_PARM_DESC(dma2, "DMA2 # for SoundScape driver."); 81MODULE_PARM_DESC(dma2, "DMA2 # for SoundScape driver.");
77 82
83module_param_array(joystick, bool, NULL, 0444);
84MODULE_PARM_DESC(joystick, "Enable gameport.");
85
78#ifdef CONFIG_PNP 86#ifdef CONFIG_PNP
79static int isa_registered; 87static int isa_registered;
80static int pnp_registered; 88static int pnp_registered;
@@ -101,14 +109,14 @@ MODULE_DEVICE_TABLE(pnp_card, sscape_pnpids);
101#define RX_READY 0x01 109#define RX_READY 0x01
102#define TX_READY 0x02 110#define TX_READY 0x02
103 111
104#define CMD_ACK 0x80 112#define CMD_ACK 0x80
105#define CMD_SET_MIDI_VOL 0x84 113#define CMD_SET_MIDI_VOL 0x84
106#define CMD_GET_MIDI_VOL 0x85 114#define CMD_GET_MIDI_VOL 0x85
107#define CMD_XXX_MIDI_VOL 0x86 115#define CMD_XXX_MIDI_VOL 0x86
108#define CMD_SET_EXTMIDI 0x8a 116#define CMD_SET_EXTMIDI 0x8a
109#define CMD_GET_EXTMIDI 0x8b 117#define CMD_GET_EXTMIDI 0x8b
110#define CMD_SET_MT32 0x8c 118#define CMD_SET_MT32 0x8c
111#define CMD_GET_MT32 0x8d 119#define CMD_GET_MT32 0x8d
112 120
113enum GA_REG { 121enum GA_REG {
114 GA_INTSTAT_REG = 0, 122 GA_INTSTAT_REG = 0,
@@ -127,7 +135,8 @@ enum GA_REG {
127 135
128 136
129enum card_type { 137enum card_type {
130 SSCAPE, 138 MEDIA_FX, /* Sequoia S-1000 */
139 SSCAPE, /* Sequoia S-2000 */
131 SSCAPE_PNP, 140 SSCAPE_PNP,
132 SSCAPE_VIVO, 141 SSCAPE_VIVO,
133}; 142};
@@ -140,16 +149,7 @@ struct soundscape {
140 struct resource *io_res; 149 struct resource *io_res;
141 struct resource *wss_res; 150 struct resource *wss_res;
142 struct snd_wss *chip; 151 struct snd_wss *chip;
143 struct snd_mpu401 *mpu;
144 struct snd_hwdep *hw;
145 152
146 /*
147 * The MIDI device won't work until we've loaded
148 * its firmware via a hardware-dependent device IOCTL
149 */
150 spinlock_t fwlock;
151 int hw_in_use;
152 unsigned long midi_usage;
153 unsigned char midi_vol; 153 unsigned char midi_vol;
154}; 154};
155 155
@@ -161,28 +161,21 @@ static inline struct soundscape *get_card_soundscape(struct snd_card *c)
161 return (struct soundscape *) (c->private_data); 161 return (struct soundscape *) (c->private_data);
162} 162}
163 163
164static inline struct soundscape *get_mpu401_soundscape(struct snd_mpu401 * mpu)
165{
166 return (struct soundscape *) (mpu->private_data);
167}
168
169static inline struct soundscape *get_hwdep_soundscape(struct snd_hwdep * hw)
170{
171 return (struct soundscape *) (hw->private_data);
172}
173
174
175/* 164/*
176 * Allocates some kernel memory that we can use for DMA. 165 * Allocates some kernel memory that we can use for DMA.
177 * I think this means that the memory has to map to 166 * I think this means that the memory has to map to
178 * contiguous pages of physical memory. 167 * contiguous pages of physical memory.
179 */ 168 */
180static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned long size) 169static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf,
170 unsigned long size)
181{ 171{
182 if (buf) { 172 if (buf) {
183 if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(), 173 if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV,
174 snd_dma_isa_data(),
184 size, buf) < 0) { 175 size, buf) < 0) {
185 snd_printk(KERN_ERR "sscape: Failed to allocate %lu bytes for DMA\n", size); 176 snd_printk(KERN_ERR "sscape: Failed to allocate "
177 "%lu bytes for DMA\n",
178 size);
186 return NULL; 179 return NULL;
187 } 180 }
188 } 181 }
@@ -199,13 +192,13 @@ static void free_dmabuf(struct snd_dma_buffer *buf)
199 snd_dma_free_pages(buf); 192 snd_dma_free_pages(buf);
200} 193}
201 194
202
203/* 195/*
204 * This function writes to the SoundScape's control registers, 196 * This function writes to the SoundScape's control registers,
205 * but doesn't do any locking. It's up to the caller to do that. 197 * but doesn't do any locking. It's up to the caller to do that.
206 * This is why this function is "unsafe" ... 198 * This is why this function is "unsafe" ...
207 */ 199 */
208static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg, unsigned char val) 200static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg,
201 unsigned char val)
209{ 202{
210 outb(reg, ODIE_ADDR_IO(io_base)); 203 outb(reg, ODIE_ADDR_IO(io_base));
211 outb(val, ODIE_DATA_IO(io_base)); 204 outb(val, ODIE_DATA_IO(io_base));
@@ -215,7 +208,8 @@ static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg, unsign
215 * Write to the SoundScape's control registers, and do the 208 * Write to the SoundScape's control registers, and do the
216 * necessary locking ... 209 * necessary locking ...
217 */ 210 */
218static void sscape_write(struct soundscape *s, enum GA_REG reg, unsigned char val) 211static void sscape_write(struct soundscape *s, enum GA_REG reg,
212 unsigned char val)
219{ 213{
220 unsigned long flags; 214 unsigned long flags;
221 215
@@ -228,7 +222,8 @@ static void sscape_write(struct soundscape *s, enum GA_REG reg, unsigned char va
228 * Read from the SoundScape's control registers, but leave any 222 * Read from the SoundScape's control registers, but leave any
229 * locking to the caller. This is why the function is "unsafe" ... 223 * locking to the caller. This is why the function is "unsafe" ...
230 */ 224 */
231static inline unsigned char sscape_read_unsafe(unsigned io_base, enum GA_REG reg) 225static inline unsigned char sscape_read_unsafe(unsigned io_base,
226 enum GA_REG reg)
232{ 227{
233 outb(reg, ODIE_ADDR_IO(io_base)); 228 outb(reg, ODIE_ADDR_IO(io_base));
234 return inb(ODIE_DATA_IO(io_base)); 229 return inb(ODIE_DATA_IO(io_base));
@@ -257,9 +252,8 @@ static inline void set_midi_mode_unsafe(unsigned io_base)
257static inline int host_read_unsafe(unsigned io_base) 252static inline int host_read_unsafe(unsigned io_base)
258{ 253{
259 int data = -1; 254 int data = -1;
260 if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0) { 255 if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0)
261 data = inb(HOST_DATA_IO(io_base)); 256 data = inb(HOST_DATA_IO(io_base));
262 }
263 257
264 return data; 258 return data;
265} 259}
@@ -301,7 +295,7 @@ static inline int host_write_unsafe(unsigned io_base, unsigned char data)
301 * Also leaves all locking-issues to the caller ... 295 * Also leaves all locking-issues to the caller ...
302 */ 296 */
303static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data, 297static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
304 unsigned timeout) 298 unsigned timeout)
305{ 299{
306 int err; 300 int err;
307 301
@@ -320,7 +314,7 @@ static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
320 * 314 *
321 * NOTE: This check is based upon observation, not documentation. 315 * NOTE: This check is based upon observation, not documentation.
322 */ 316 */
323static inline int verify_mpu401(const struct snd_mpu401 * mpu) 317static inline int verify_mpu401(const struct snd_mpu401 *mpu)
324{ 318{
325 return ((inb(MPU401C(mpu)) & 0xc0) == 0x80); 319 return ((inb(MPU401C(mpu)) & 0xc0) == 0x80);
326} 320}
@@ -328,7 +322,7 @@ static inline int verify_mpu401(const struct snd_mpu401 * mpu)
328/* 322/*
329 * This is apparently the standard way to initailise an MPU-401 323 * This is apparently the standard way to initailise an MPU-401
330 */ 324 */
331static inline void initialise_mpu401(const struct snd_mpu401 * mpu) 325static inline void initialise_mpu401(const struct snd_mpu401 *mpu)
332{ 326{
333 outb(0, MPU401D(mpu)); 327 outb(0, MPU401D(mpu));
334} 328}
@@ -338,9 +332,10 @@ static inline void initialise_mpu401(const struct snd_mpu401 * mpu)
338 * The AD1845 detection fails if we *don't* do this, so I 332 * The AD1845 detection fails if we *don't* do this, so I
339 * think that this is a good idea ... 333 * think that this is a good idea ...
340 */ 334 */
341static inline void activate_ad1845_unsafe(unsigned io_base) 335static void activate_ad1845_unsafe(unsigned io_base)
342{ 336{
343 sscape_write_unsafe(io_base, GA_HMCTL_REG, (sscape_read_unsafe(io_base, GA_HMCTL_REG) & 0xcf) | 0x10); 337 unsigned char val = sscape_read_unsafe(io_base, GA_HMCTL_REG);
338 sscape_write_unsafe(io_base, GA_HMCTL_REG, (val & 0xcf) | 0x10);
344 sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80); 339 sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80);
345} 340}
346 341
@@ -359,24 +354,27 @@ static void soundscape_free(struct snd_card *c)
359 * Tell the SoundScape to begin a DMA tranfer using the given channel. 354 * Tell the SoundScape to begin a DMA tranfer using the given channel.
360 * All locking issues are left to the caller. 355 * All locking issues are left to the caller.
361 */ 356 */
362static inline void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg) 357static void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg)
363{ 358{
364 sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) | 0x01); 359 sscape_write_unsafe(io_base, reg,
365 sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) & 0xfe); 360 sscape_read_unsafe(io_base, reg) | 0x01);
361 sscape_write_unsafe(io_base, reg,
362 sscape_read_unsafe(io_base, reg) & 0xfe);
366} 363}
367 364
368/* 365/*
369 * Wait for a DMA transfer to complete. This is a "limited busy-wait", 366 * Wait for a DMA transfer to complete. This is a "limited busy-wait",
370 * and all locking issues are left to the caller. 367 * and all locking issues are left to the caller.
371 */ 368 */
372static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg, unsigned timeout) 369static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg,
370 unsigned timeout)
373{ 371{
374 while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) { 372 while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) {
375 udelay(100); 373 udelay(100);
376 --timeout; 374 --timeout;
377 } /* while */ 375 } /* while */
378 376
379 return (sscape_read_unsafe(io_base, reg) & 0x01); 377 return sscape_read_unsafe(io_base, reg) & 0x01;
380} 378}
381 379
382/* 380/*
@@ -392,12 +390,12 @@ static int obp_startup_ack(struct soundscape *s, unsigned timeout)
392 390
393 do { 391 do {
394 unsigned long flags; 392 unsigned long flags;
395 unsigned char x; 393 int x;
396 394
397 spin_lock_irqsave(&s->lock, flags); 395 spin_lock_irqsave(&s->lock, flags);
398 x = inb(HOST_DATA_IO(s->io_base)); 396 x = host_read_unsafe(s->io_base);
399 spin_unlock_irqrestore(&s->lock, flags); 397 spin_unlock_irqrestore(&s->lock, flags);
400 if ((x & 0xfe) == 0xfe) 398 if (x == 0xfe || x == 0xff)
401 return 1; 399 return 1;
402 400
403 msleep(10); 401 msleep(10);
@@ -419,10 +417,10 @@ static int host_startup_ack(struct soundscape *s, unsigned timeout)
419 417
420 do { 418 do {
421 unsigned long flags; 419 unsigned long flags;
422 unsigned char x; 420 int x;
423 421
424 spin_lock_irqsave(&s->lock, flags); 422 spin_lock_irqsave(&s->lock, flags);
425 x = inb(HOST_DATA_IO(s->io_base)); 423 x = host_read_unsafe(s->io_base);
426 spin_unlock_irqrestore(&s->lock, flags); 424 spin_unlock_irqrestore(&s->lock, flags);
427 if (x == 0xfe) 425 if (x == 0xfe)
428 return 1; 426 return 1;
@@ -436,15 +434,15 @@ static int host_startup_ack(struct soundscape *s, unsigned timeout)
436/* 434/*
437 * Upload a byte-stream into the SoundScape using DMA channel A. 435 * Upload a byte-stream into the SoundScape using DMA channel A.
438 */ 436 */
439static int upload_dma_data(struct soundscape *s, 437static int upload_dma_data(struct soundscape *s, const unsigned char *data,
440 const unsigned char __user *data, 438 size_t size)
441 size_t size)
442{ 439{
443 unsigned long flags; 440 unsigned long flags;
444 struct snd_dma_buffer dma; 441 struct snd_dma_buffer dma;
445 int ret; 442 int ret;
443 unsigned char val;
446 444
447 if (!get_dmabuf(&dma, PAGE_ALIGN(size))) 445 if (!get_dmabuf(&dma, PAGE_ALIGN(32 * 1024)))
448 return -ENOMEM; 446 return -ENOMEM;
449 447
450 spin_lock_irqsave(&s->lock, flags); 448 spin_lock_irqsave(&s->lock, flags);
@@ -452,70 +450,57 @@ static int upload_dma_data(struct soundscape *s,
452 /* 450 /*
453 * Reset the board ... 451 * Reset the board ...
454 */ 452 */
455 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f); 453 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
454 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val & 0x3f);
456 455
457 /* 456 /*
458 * Enable the DMA channels and configure them ... 457 * Enable the DMA channels and configure them ...
459 */ 458 */
460 sscape_write_unsafe(s->io_base, GA_DMACFG_REG, 0x50); 459 val = (s->chip->dma1 << 4) | DMA_8BIT;
461 sscape_write_unsafe(s->io_base, GA_DMAA_REG, (s->chip->dma1 << 4) | DMA_8BIT); 460 sscape_write_unsafe(s->io_base, GA_DMAA_REG, val);
462 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20); 461 sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20);
463 462
464 /* 463 /*
465 * Take the board out of reset ... 464 * Take the board out of reset ...
466 */ 465 */
467 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x80); 466 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
467 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x80);
468 468
469 /* 469 /*
470 * Upload the user's data (firmware?) to the SoundScape 470 * Upload the firmware to the SoundScape
471 * board through the DMA channel ... 471 * board through the DMA channel ...
472 */ 472 */
473 while (size != 0) { 473 while (size != 0) {
474 unsigned long len; 474 unsigned long len;
475 475
476 /*
477 * Apparently, copying to/from userspace can sleep.
478 * We are therefore forbidden from holding any
479 * spinlocks while we copy ...
480 */
481 spin_unlock_irqrestore(&s->lock, flags);
482
483 /*
484 * Remember that the data that we want to DMA
485 * comes from USERSPACE. We have already verified
486 * the userspace pointer ...
487 */
488 len = min(size, dma.bytes); 476 len = min(size, dma.bytes);
489 len -= __copy_from_user(dma.area, data, len); 477 memcpy(dma.area, data, len);
490 data += len; 478 data += len;
491 size -= len; 479 size -= len;
492 480
493 /*
494 * Grab that spinlock again, now that we've
495 * finished copying!
496 */
497 spin_lock_irqsave(&s->lock, flags);
498
499 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE); 481 snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE);
500 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG); 482 sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG);
501 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) { 483 if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) {
502 /* 484 /*
503 * Don't forget to release this spinlock we're holding ... 485 * Don't forget to release this spinlock we're holding
504 */ 486 */
505 spin_unlock_irqrestore(&s->lock, flags); 487 spin_unlock_irqrestore(&s->lock, flags);
506 488
507 snd_printk(KERN_ERR "sscape: DMA upload has timed out\n"); 489 snd_printk(KERN_ERR
490 "sscape: DMA upload has timed out\n");
508 ret = -EAGAIN; 491 ret = -EAGAIN;
509 goto _release_dma; 492 goto _release_dma;
510 } 493 }
511 } /* while */ 494 } /* while */
512 495
513 set_host_mode_unsafe(s->io_base); 496 set_host_mode_unsafe(s->io_base);
497 outb(0x0, s->io_base);
514 498
515 /* 499 /*
516 * Boot the board ... (I think) 500 * Boot the board ... (I think)
517 */ 501 */
518 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40); 502 val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
503 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x40);
519 spin_unlock_irqrestore(&s->lock, flags); 504 spin_unlock_irqrestore(&s->lock, flags);
520 505
521 /* 506 /*
@@ -525,10 +510,12 @@ static int upload_dma_data(struct soundscape *s,
525 */ 510 */
526 ret = 0; 511 ret = 0;
527 if (!obp_startup_ack(s, 5000)) { 512 if (!obp_startup_ack(s, 5000)) {
528 snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n"); 513 snd_printk(KERN_ERR "sscape: No response "
514 "from on-board processor after upload\n");
529 ret = -EAGAIN; 515 ret = -EAGAIN;
530 } else if (!host_startup_ack(s, 5000)) { 516 } else if (!host_startup_ack(s, 5000)) {
531 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n"); 517 snd_printk(KERN_ERR
518 "sscape: SoundScape failed to initialise\n");
532 ret = -EAGAIN; 519 ret = -EAGAIN;
533 } 520 }
534 521
@@ -536,7 +523,7 @@ _release_dma:
536 /* 523 /*
537 * NOTE!!! We are NOT holding any spinlocks at this point !!! 524 * NOTE!!! We are NOT holding any spinlocks at this point !!!
538 */ 525 */
539 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_ODIE ? 0x70 : 0x40)); 526 sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_OPUS ? 0x40 : 0x70));
540 free_dmabuf(&dma); 527 free_dmabuf(&dma);
541 528
542 return ret; 529 return ret;
@@ -546,167 +533,76 @@ _release_dma:
546 * Upload the bootblock(?) into the SoundScape. The only 533 * Upload the bootblock(?) into the SoundScape. The only
547 * purpose of this block of code seems to be to tell 534 * purpose of this block of code seems to be to tell
548 * us which version of the microcode we should be using. 535 * us which version of the microcode we should be using.
549 *
550 * NOTE: The boot-block data resides in USER-SPACE!!!
551 * However, we have already verified its memory
552 * addresses by the time we get here.
553 */ 536 */
554static int sscape_upload_bootblock(struct soundscape *sscape, struct sscape_bootblock __user *bb) 537static int sscape_upload_bootblock(struct snd_card *card)
555{ 538{
539 struct soundscape *sscape = get_card_soundscape(card);
556 unsigned long flags; 540 unsigned long flags;
541 const struct firmware *init_fw = NULL;
557 int data = 0; 542 int data = 0;
558 int ret; 543 int ret;
559 544
560 ret = upload_dma_data(sscape, bb->code, sizeof(bb->code)); 545 ret = request_firmware(&init_fw, "scope.cod", card->dev);
561 546 if (ret < 0) {
562 spin_lock_irqsave(&sscape->lock, flags); 547 snd_printk(KERN_ERR "sscape: Error loading scope.cod");
563 if (ret == 0) { 548 return ret;
564 data = host_read_ctrl_unsafe(sscape->io_base, 100);
565 }
566 set_midi_mode_unsafe(sscape->io_base);
567 spin_unlock_irqrestore(&sscape->lock, flags);
568
569 if (ret == 0) {
570 if (data < 0) {
571 snd_printk(KERN_ERR "sscape: timeout reading firmware version\n");
572 ret = -EAGAIN;
573 }
574 else if (__copy_to_user(&bb->version, &data, sizeof(bb->version))) {
575 ret = -EFAULT;
576 }
577 } 549 }
550 ret = upload_dma_data(sscape, init_fw->data, init_fw->size);
578 551
579 return ret; 552 release_firmware(init_fw);
580}
581
582/*
583 * Upload the microcode into the SoundScape. The
584 * microcode is 64K of data, and if we try to copy
585 * it into a local variable then we will SMASH THE
586 * KERNEL'S STACK! We therefore leave it in USER
587 * SPACE, and save ourselves from copying it at all.
588 */
589static int sscape_upload_microcode(struct soundscape *sscape,
590 const struct sscape_microcode __user *mc)
591{
592 unsigned long flags;
593 char __user *code;
594 int err;
595 553
596 /* 554 spin_lock_irqsave(&sscape->lock, flags);
597 * We are going to have to copy this data into a special 555 if (ret == 0)
598 * DMA-able buffer before we can upload it. We shall therefore 556 data = host_read_ctrl_unsafe(sscape->io_base, 100);
599 * just check that the data pointer is valid for now.
600 *
601 * NOTE: This buffer is 64K long! That's WAY too big to
602 * copy into a stack-temporary anyway.
603 */
604 if ( get_user(code, &mc->code) ||
605 !access_ok(VERIFY_READ, code, SSCAPE_MICROCODE_SIZE) )
606 return -EFAULT;
607 557
608 if ((err = upload_dma_data(sscape, code, SSCAPE_MICROCODE_SIZE)) == 0) { 558 if (data & 0x10)
609 snd_printk(KERN_INFO "sscape: MIDI firmware loaded\n"); 559 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f);
610 }
611 560
612 spin_lock_irqsave(&sscape->lock, flags);
613 set_midi_mode_unsafe(sscape->io_base);
614 spin_unlock_irqrestore(&sscape->lock, flags); 561 spin_unlock_irqrestore(&sscape->lock, flags);
615 562
616 initialise_mpu401(sscape->mpu); 563 data &= 0xf;
564 if (ret == 0 && data > 7) {
565 snd_printk(KERN_ERR
566 "sscape: timeout reading firmware version\n");
567 ret = -EAGAIN;
568 }
617 569
618 return err; 570 return (ret == 0) ? data : ret;
619} 571}
620 572
621/* 573/*
622 * Hardware-specific device functions, to implement special 574 * Upload the microcode into the SoundScape.
623 * IOCTLs for the SoundScape card. This is how we upload
624 * the microcode into the card, for example, and so we
625 * must ensure that no two processes can open this device
626 * simultaneously, and that we can't open it at all if
627 * someone is using the MIDI device.
628 */ 575 */
629static int sscape_hw_open(struct snd_hwdep * hw, struct file *file) 576static int sscape_upload_microcode(struct snd_card *card, int version)
630{ 577{
631 register struct soundscape *sscape = get_hwdep_soundscape(hw); 578 struct soundscape *sscape = get_card_soundscape(card);
632 unsigned long flags; 579 const struct firmware *init_fw = NULL;
580 char name[14];
633 int err; 581 int err;
634 582
635 spin_lock_irqsave(&sscape->fwlock, flags); 583 snprintf(name, sizeof(name), "sndscape.co%d", version);
636 584
637 if ((sscape->midi_usage != 0) || sscape->hw_in_use) { 585 err = request_firmware(&init_fw, name, card->dev);
638 err = -EBUSY; 586 if (err < 0) {
639 } else { 587 snd_printk(KERN_ERR "sscape: Error loading sndscape.co%d",
640 sscape->hw_in_use = 1; 588 version);
641 err = 0; 589 return err;
642 } 590 }
591 err = upload_dma_data(sscape, init_fw->data, init_fw->size);
592 if (err == 0)
593 snd_printk(KERN_INFO "sscape: MIDI firmware loaded %d KBs\n",
594 init_fw->size >> 10);
643 595
644 spin_unlock_irqrestore(&sscape->fwlock, flags); 596 release_firmware(init_fw);
645 return err;
646}
647
648static int sscape_hw_release(struct snd_hwdep * hw, struct file *file)
649{
650 register struct soundscape *sscape = get_hwdep_soundscape(hw);
651 unsigned long flags;
652
653 spin_lock_irqsave(&sscape->fwlock, flags);
654 sscape->hw_in_use = 0;
655 spin_unlock_irqrestore(&sscape->fwlock, flags);
656 return 0;
657}
658
659static int sscape_hw_ioctl(struct snd_hwdep * hw, struct file *file,
660 unsigned int cmd, unsigned long arg)
661{
662 struct soundscape *sscape = get_hwdep_soundscape(hw);
663 int err = -EBUSY;
664
665 switch (cmd) {
666 case SND_SSCAPE_LOAD_BOOTB:
667 {
668 register struct sscape_bootblock __user *bb = (struct sscape_bootblock __user *) arg;
669
670 /*
671 * We are going to have to copy this data into a special
672 * DMA-able buffer before we can upload it. We shall therefore
673 * just check that the data pointer is valid for now ...
674 */
675 if ( !access_ok(VERIFY_READ, bb->code, sizeof(bb->code)) )
676 return -EFAULT;
677
678 /*
679 * Now check that we can write the firmware version number too...
680 */
681 if ( !access_ok(VERIFY_WRITE, &bb->version, sizeof(bb->version)) )
682 return -EFAULT;
683
684 err = sscape_upload_bootblock(sscape, bb);
685 }
686 break;
687
688 case SND_SSCAPE_LOAD_MCODE:
689 {
690 register const struct sscape_microcode __user *mc = (const struct sscape_microcode __user *) arg;
691
692 err = sscape_upload_microcode(sscape, mc);
693 }
694 break;
695
696 default:
697 err = -EINVAL;
698 break;
699 } /* switch */
700 597
701 return err; 598 return err;
702} 599}
703 600
704
705/* 601/*
706 * Mixer control for the SoundScape's MIDI device. 602 * Mixer control for the SoundScape's MIDI device.
707 */ 603 */
708static int sscape_midi_info(struct snd_kcontrol *ctl, 604static int sscape_midi_info(struct snd_kcontrol *ctl,
709 struct snd_ctl_elem_info *uinfo) 605 struct snd_ctl_elem_info *uinfo)
710{ 606{
711 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 607 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
712 uinfo->count = 1; 608 uinfo->count = 1;
@@ -716,7 +612,7 @@ static int sscape_midi_info(struct snd_kcontrol *ctl,
716} 612}
717 613
718static int sscape_midi_get(struct snd_kcontrol *kctl, 614static int sscape_midi_get(struct snd_kcontrol *kctl,
719 struct snd_ctl_elem_value *uctl) 615 struct snd_ctl_elem_value *uctl)
720{ 616{
721 struct snd_wss *chip = snd_kcontrol_chip(kctl); 617 struct snd_wss *chip = snd_kcontrol_chip(kctl);
722 struct snd_card *card = chip->card; 618 struct snd_card *card = chip->card;
@@ -730,16 +626,18 @@ static int sscape_midi_get(struct snd_kcontrol *kctl,
730} 626}
731 627
732static int sscape_midi_put(struct snd_kcontrol *kctl, 628static int sscape_midi_put(struct snd_kcontrol *kctl,
733 struct snd_ctl_elem_value *uctl) 629 struct snd_ctl_elem_value *uctl)
734{ 630{
735 struct snd_wss *chip = snd_kcontrol_chip(kctl); 631 struct snd_wss *chip = snd_kcontrol_chip(kctl);
736 struct snd_card *card = chip->card; 632 struct snd_card *card = chip->card;
737 register struct soundscape *s = get_card_soundscape(card); 633 struct soundscape *s = get_card_soundscape(card);
738 unsigned long flags; 634 unsigned long flags;
739 int change; 635 int change;
636 unsigned char new_val;
740 637
741 spin_lock_irqsave(&s->lock, flags); 638 spin_lock_irqsave(&s->lock, flags);
742 639
640 new_val = uctl->value.integer.value[0] & 127;
743 /* 641 /*
744 * We need to put the board into HOST mode before we 642 * We need to put the board into HOST mode before we
745 * can send any volume-changing HOST commands ... 643 * can send any volume-changing HOST commands ...
@@ -752,15 +650,16 @@ static int sscape_midi_put(struct snd_kcontrol *kctl,
752 * and then perform another volume-related command. Perhaps the 650 * and then perform another volume-related command. Perhaps the
753 * first command is an "open" and the second command is a "close"? 651 * first command is an "open" and the second command is a "close"?
754 */ 652 */
755 if (s->midi_vol == ((unsigned char) uctl->value.integer. value[0] & 127)) { 653 if (s->midi_vol == new_val) {
756 change = 0; 654 change = 0;
757 goto __skip_change; 655 goto __skip_change;
758 } 656 }
759 change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100) 657 change = host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
760 && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100) 658 && host_write_ctrl_unsafe(s->io_base, new_val, 100)
761 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)); 659 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)
762 s->midi_vol = (unsigned char) uctl->value.integer.value[0] & 127; 660 && host_write_ctrl_unsafe(s->io_base, new_val, 100);
763 __skip_change: 661 s->midi_vol = new_val;
662__skip_change:
764 663
765 /* 664 /*
766 * Take the board out of HOST mode and back into MIDI mode ... 665 * Take the board out of HOST mode and back into MIDI mode ...
@@ -784,20 +683,25 @@ static struct snd_kcontrol_new midi_mixer_ctl = {
784 * These IRQs are encoded as bit patterns so that they can be 683 * These IRQs are encoded as bit patterns so that they can be
785 * written to the control registers. 684 * written to the control registers.
786 */ 685 */
787static unsigned __devinit get_irq_config(int irq) 686static unsigned __devinit get_irq_config(int sscape_type, int irq)
788{ 687{
789 static const int valid_irq[] = { 9, 5, 7, 10 }; 688 static const int valid_irq[] = { 9, 5, 7, 10 };
689 static const int old_irq[] = { 9, 7, 5, 15 };
790 unsigned cfg; 690 unsigned cfg;
791 691
792 for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg) { 692 if (sscape_type == MEDIA_FX) {
793 if (irq == valid_irq[cfg]) 693 for (cfg = 0; cfg < ARRAY_SIZE(old_irq); ++cfg)
794 return cfg; 694 if (irq == old_irq[cfg])
795 } /* for */ 695 return cfg;
696 } else {
697 for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg)
698 if (irq == valid_irq[cfg])
699 return cfg;
700 }
796 701
797 return INVALID_IRQ; 702 return INVALID_IRQ;
798} 703}
799 704
800
801/* 705/*
802 * Perform certain arcane port-checks to see whether there 706 * Perform certain arcane port-checks to see whether there
803 * is a SoundScape board lurking behind the given ports. 707 * is a SoundScape board lurking behind the given ports.
@@ -842,11 +746,38 @@ static int __devinit detect_sscape(struct soundscape *s, long wss_io)
842 if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e) 746 if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e)
843 goto _done; 747 goto _done;
844 748
845 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f; 749 if (s->ic_type == IC_OPUS)
846 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0); 750 activate_ad1845_unsafe(s->io_base);
847 751
848 if (s->type == SSCAPE_VIVO) 752 if (s->type == SSCAPE_VIVO)
849 wss_io += 4; 753 wss_io += 4;
754
755 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
756 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
757
758 /* wait for WSS codec */
759 for (d = 0; d < 500; d++) {
760 if ((inb(wss_io) & 0x80) == 0)
761 break;
762 spin_unlock_irqrestore(&s->lock, flags);
763 msleep(1);
764 spin_lock_irqsave(&s->lock, flags);
765 }
766
767 if ((inb(wss_io) & 0x80) != 0)
768 goto _done;
769
770 if (inb(wss_io + 2) == 0xff)
771 goto _done;
772
773 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
774 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d);
775
776 if ((inb(wss_io) & 0x80) != 0)
777 s->type = MEDIA_FX;
778
779 d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
780 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
850 /* wait for WSS codec */ 781 /* wait for WSS codec */
851 for (d = 0; d < 500; d++) { 782 for (d = 0; d < 500; d++) {
852 if ((inb(wss_io) & 0x80) == 0) 783 if ((inb(wss_io) & 0x80) == 0)
@@ -855,14 +786,13 @@ static int __devinit detect_sscape(struct soundscape *s, long wss_io)
855 msleep(1); 786 msleep(1);
856 spin_lock_irqsave(&s->lock, flags); 787 spin_lock_irqsave(&s->lock, flags);
857 } 788 }
858 snd_printd(KERN_INFO "init delay = %d ms\n", d);
859 789
860 /* 790 /*
861 * SoundScape successfully detected! 791 * SoundScape successfully detected!
862 */ 792 */
863 retval = 1; 793 retval = 1;
864 794
865 _done: 795_done:
866 spin_unlock_irqrestore(&s->lock, flags); 796 spin_unlock_irqrestore(&s->lock, flags);
867 return retval; 797 return retval;
868} 798}
@@ -873,63 +803,35 @@ static int __devinit detect_sscape(struct soundscape *s, long wss_io)
873 * to crash the machine. Also check that someone isn't using the hardware 803 * to crash the machine. Also check that someone isn't using the hardware
874 * IOCTL device. 804 * IOCTL device.
875 */ 805 */
876static int mpu401_open(struct snd_mpu401 * mpu) 806static int mpu401_open(struct snd_mpu401 *mpu)
877{ 807{
878 int err;
879
880 if (!verify_mpu401(mpu)) { 808 if (!verify_mpu401(mpu)) {
881 snd_printk(KERN_ERR "sscape: MIDI disabled, please load firmware\n"); 809 snd_printk(KERN_ERR "sscape: MIDI disabled, "
882 err = -ENODEV; 810 "please load firmware\n");
883 } else { 811 return -ENODEV;
884 register struct soundscape *sscape = get_mpu401_soundscape(mpu);
885 unsigned long flags;
886
887 spin_lock_irqsave(&sscape->fwlock, flags);
888
889 if (sscape->hw_in_use || (sscape->midi_usage == ULONG_MAX)) {
890 err = -EBUSY;
891 } else {
892 ++(sscape->midi_usage);
893 err = 0;
894 }
895
896 spin_unlock_irqrestore(&sscape->fwlock, flags);
897 } 812 }
898 813
899 return err; 814 return 0;
900}
901
902static void mpu401_close(struct snd_mpu401 * mpu)
903{
904 register struct soundscape *sscape = get_mpu401_soundscape(mpu);
905 unsigned long flags;
906
907 spin_lock_irqsave(&sscape->fwlock, flags);
908 --(sscape->midi_usage);
909 spin_unlock_irqrestore(&sscape->fwlock, flags);
910} 815}
911 816
912/* 817/*
913 * Initialse an MPU-401 subdevice for MIDI support on the SoundScape. 818 * Initialse an MPU-401 subdevice for MIDI support on the SoundScape.
914 */ 819 */
915static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned long port, int irq) 820static int __devinit create_mpu401(struct snd_card *card, int devnum,
821 unsigned long port, int irq)
916{ 822{
917 struct soundscape *sscape = get_card_soundscape(card); 823 struct soundscape *sscape = get_card_soundscape(card);
918 struct snd_rawmidi *rawmidi; 824 struct snd_rawmidi *rawmidi;
919 int err; 825 int err;
920 826
921 if ((err = snd_mpu401_uart_new(card, devnum, 827 err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port,
922 MPU401_HW_MPU401, 828 MPU401_INFO_INTEGRATED, irq, IRQF_DISABLED,
923 port, MPU401_INFO_INTEGRATED, 829 &rawmidi);
924 irq, IRQF_DISABLED, 830 if (err == 0) {
925 &rawmidi)) == 0) { 831 struct snd_mpu401 *mpu = rawmidi->private_data;
926 struct snd_mpu401 *mpu = (struct snd_mpu401 *) rawmidi->private_data;
927 mpu->open_input = mpu401_open; 832 mpu->open_input = mpu401_open;
928 mpu->open_output = mpu401_open; 833 mpu->open_output = mpu401_open;
929 mpu->close_input = mpu401_close;
930 mpu->close_output = mpu401_close;
931 mpu->private_data = sscape; 834 mpu->private_data = sscape;
932 sscape->mpu = mpu;
933 835
934 initialise_mpu401(mpu); 836 initialise_mpu401(mpu);
935 } 837 }
@@ -950,32 +852,34 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
950 register struct soundscape *sscape = get_card_soundscape(card); 852 register struct soundscape *sscape = get_card_soundscape(card);
951 struct snd_wss *chip; 853 struct snd_wss *chip;
952 int err; 854 int err;
855 int codec_type = WSS_HW_DETECT;
953 856
954 if (sscape->type == SSCAPE_VIVO) 857 switch (sscape->type) {
955 port += 4; 858 case MEDIA_FX:
859 case SSCAPE:
860 /*
861 * There are some freak examples of early Soundscape cards
862 * with CS4231 instead of AD1848/CS4248. Unfortunately, the
863 * CS4231 works only in CS4248 compatibility mode on
864 * these cards so force it.
865 */
866 if (sscape->ic_type != IC_OPUS)
867 codec_type = WSS_HW_AD1848;
868 break;
956 869
957 if (dma1 == dma2) 870 case SSCAPE_VIVO:
958 dma2 = -1; 871 port += 4;
872 break;
873 default:
874 break;
875 }
959 876
960 err = snd_wss_create(card, port, -1, irq, dma1, dma2, 877 err = snd_wss_create(card, port, -1, irq, dma1, dma2,
961 WSS_HW_DETECT, WSS_HWSHARE_DMA1, &chip); 878 codec_type, WSS_HWSHARE_DMA1, &chip);
962 if (!err) { 879 if (!err) {
963 unsigned long flags; 880 unsigned long flags;
964 struct snd_pcm *pcm; 881 struct snd_pcm *pcm;
965 882
966/*
967 * It turns out that the PLAYBACK_ENABLE bit is set
968 * by the lowlevel driver ...
969 *
970#define AD1845_IFACE_CONFIG \
971 (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE)
972 snd_wss_mce_up(chip);
973 spin_lock_irqsave(&chip->reg_lock, flags);
974 snd_wss_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG);
975 spin_unlock_irqrestore(&chip->reg_lock, flags);
976 snd_wss_mce_down(chip);
977 */
978
979 if (sscape->type != SSCAPE_VIVO) { 883 if (sscape->type != SSCAPE_VIVO) {
980 /* 884 /*
981 * The input clock frequency on the SoundScape must 885 * The input clock frequency on the SoundScape must
@@ -1022,17 +926,10 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1022 } 926 }
1023 } 927 }
1024 928
1025 strcpy(card->driver, "SoundScape");
1026 strcpy(card->shortname, pcm->name);
1027 snprintf(card->longname, sizeof(card->longname),
1028 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
1029 pcm->name, chip->port, chip->irq,
1030 chip->dma1, chip->dma2);
1031
1032 sscape->chip = chip; 929 sscape->chip = chip;
1033 } 930 }
1034 931
1035 _error: 932_error:
1036 return err; 933 return err;
1037} 934}
1038 935
@@ -1051,21 +948,8 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1051 struct resource *wss_res; 948 struct resource *wss_res;
1052 unsigned long flags; 949 unsigned long flags;
1053 int err; 950 int err;
1054 951 int val;
1055 /* 952 const char *name;
1056 * Check that the user didn't pass us garbage data ...
1057 */
1058 irq_cfg = get_irq_config(irq[dev]);
1059 if (irq_cfg == INVALID_IRQ) {
1060 snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
1061 return -ENXIO;
1062 }
1063
1064 mpu_irq_cfg = get_irq_config(mpu_irq[dev]);
1065 if (mpu_irq_cfg == INVALID_IRQ) {
1066 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
1067 return -ENXIO;
1068 }
1069 953
1070 /* 954 /*
1071 * Grab IO ports that we will need to probe so that we 955 * Grab IO ports that we will need to probe so that we
@@ -1098,41 +982,51 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1098 } 982 }
1099 983
1100 spin_lock_init(&sscape->lock); 984 spin_lock_init(&sscape->lock);
1101 spin_lock_init(&sscape->fwlock);
1102 sscape->io_res = io_res; 985 sscape->io_res = io_res;
1103 sscape->wss_res = wss_res; 986 sscape->wss_res = wss_res;
1104 sscape->io_base = port[dev]; 987 sscape->io_base = port[dev];
1105 988
1106 if (!detect_sscape(sscape, wss_port[dev])) { 989 if (!detect_sscape(sscape, wss_port[dev])) {
1107 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base); 990 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n",
991 sscape->io_base);
1108 err = -ENODEV; 992 err = -ENODEV;
1109 goto _release_dma; 993 goto _release_dma;
1110 } 994 }
1111 995
1112 printk(KERN_INFO "sscape: hardware detected at 0x%x, using IRQ %d, DMA %d\n", 996 switch (sscape->type) {
1113 sscape->io_base, irq[dev], dma[dev]); 997 case MEDIA_FX:
998 name = "MediaFX/SoundFX";
999 break;
1000 case SSCAPE:
1001 name = "Soundscape";
1002 break;
1003 case SSCAPE_PNP:
1004 name = "Soundscape PnP";
1005 break;
1006 case SSCAPE_VIVO:
1007 name = "Soundscape VIVO";
1008 break;
1009 default:
1010 name = "unknown Soundscape";
1011 break;
1012 }
1114 1013
1115 if (sscape->type != SSCAPE_VIVO) { 1014 printk(KERN_INFO "sscape: %s card detected at 0x%x, using IRQ %d, DMA %d\n",
1116 /* 1015 name, sscape->io_base, irq[dev], dma[dev]);
1117 * Now create the hardware-specific device so that we can 1016
1118 * load the microcode into the on-board processor. 1017 /*
1119 * We cannot use the MPU-401 MIDI system until this firmware 1018 * Check that the user didn't pass us garbage data ...
1120 * has been loaded into the card. 1019 */
1121 */ 1020 irq_cfg = get_irq_config(sscape->type, irq[dev]);
1122 err = snd_hwdep_new(card, "MC68EC000", 0, &(sscape->hw)); 1021 if (irq_cfg == INVALID_IRQ) {
1123 if (err < 0) { 1022 snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
1124 printk(KERN_ERR "sscape: Failed to create " 1023 return -ENXIO;
1125 "firmware device\n"); 1024 }
1126 goto _release_dma; 1025
1127 } 1026 mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]);
1128 strlcpy(sscape->hw->name, "SoundScape M68K", 1027 if (mpu_irq_cfg == INVALID_IRQ) {
1129 sizeof(sscape->hw->name)); 1028 snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
1130 sscape->hw->name[sizeof(sscape->hw->name) - 1] = '\0'; 1029 return -ENXIO;
1131 sscape->hw->iface = SNDRV_HWDEP_IFACE_SSCAPE;
1132 sscape->hw->ops.open = sscape_hw_open;
1133 sscape->hw->ops.release = sscape_hw_release;
1134 sscape->hw->ops.ioctl = sscape_hw_ioctl;
1135 sscape->hw->private_data = sscape;
1136 } 1030 }
1137 1031
1138 /* 1032 /*
@@ -1141,9 +1035,6 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1141 */ 1035 */
1142 spin_lock_irqsave(&sscape->lock, flags); 1036 spin_lock_irqsave(&sscape->lock, flags);
1143 1037
1144 activate_ad1845_unsafe(sscape->io_base);
1145
1146 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */
1147 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e); 1038 sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e);
1148 sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00); 1039 sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00);
1149 1040
@@ -1151,15 +1042,23 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1151 * Enable and configure the DMA channels ... 1042 * Enable and configure the DMA channels ...
1152 */ 1043 */
1153 sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50); 1044 sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50);
1154 dma_cfg = (sscape->ic_type == IC_ODIE ? 0x70 : 0x40); 1045 dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70);
1155 sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg); 1046 sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg);
1156 sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20); 1047 sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20);
1157 1048
1158 sscape_write_unsafe(sscape->io_base, 1049 mpu_irq_cfg |= mpu_irq_cfg << 2;
1159 GA_INTCFG_REG, 0xf0 | (mpu_irq_cfg << 2) | mpu_irq_cfg); 1050 val = sscape_read_unsafe(sscape->io_base, GA_HMCTL_REG) & 0xF7;
1051 if (joystick[dev])
1052 val |= 8;
1053 sscape_write_unsafe(sscape->io_base, GA_HMCTL_REG, val | 0x10);
1054 sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg);
1160 sscape_write_unsafe(sscape->io_base, 1055 sscape_write_unsafe(sscape->io_base,
1161 GA_CDCFG_REG, 0x09 | DMA_8BIT 1056 GA_CDCFG_REG, 0x09 | DMA_8BIT
1162 | (dma[dev] << 4) | (irq_cfg << 1)); 1057 | (dma[dev] << 4) | (irq_cfg << 1));
1058 /*
1059 * Enable the master IRQ ...
1060 */
1061 sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x80);
1163 1062
1164 spin_unlock_irqrestore(&sscape->lock, flags); 1063 spin_unlock_irqrestore(&sscape->lock, flags);
1165 1064
@@ -1170,32 +1069,56 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1170 err = create_ad1845(card, wss_port[dev], irq[dev], 1069 err = create_ad1845(card, wss_port[dev], irq[dev],
1171 dma[dev], dma2[dev]); 1070 dma[dev], dma2[dev]);
1172 if (err < 0) { 1071 if (err < 0) {
1173 printk(KERN_ERR "sscape: No AD1845 device at 0x%lx, IRQ %d\n", 1072 snd_printk(KERN_ERR
1174 wss_port[dev], irq[dev]); 1073 "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
1074 wss_port[dev], irq[dev]);
1175 goto _release_dma; 1075 goto _release_dma;
1176 } 1076 }
1077 strcpy(card->driver, "SoundScape");
1078 strcpy(card->shortname, name);
1079 snprintf(card->longname, sizeof(card->longname),
1080 "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
1081 name, sscape->chip->port, sscape->chip->irq,
1082 sscape->chip->dma1, sscape->chip->dma2);
1083
1177#define MIDI_DEVNUM 0 1084#define MIDI_DEVNUM 0
1178 if (sscape->type != SSCAPE_VIVO) { 1085 if (sscape->type != SSCAPE_VIVO) {
1179 err = create_mpu401(card, MIDI_DEVNUM, port[dev], mpu_irq[dev]); 1086 err = sscape_upload_bootblock(card);
1180 if (err < 0) { 1087 if (err >= 0)
1181 printk(KERN_ERR "sscape: Failed to create " 1088 err = sscape_upload_microcode(card, err);
1182 "MPU-401 device at 0x%lx\n",
1183 port[dev]);
1184 goto _release_dma;
1185 }
1186 1089
1187 /* 1090 if (err == 0) {
1188 * Enable the master IRQ ... 1091 err = create_mpu401(card, MIDI_DEVNUM, port[dev],
1189 */ 1092 mpu_irq[dev]);
1190 sscape_write(sscape, GA_INTENA_REG, 0x80); 1093 if (err < 0) {
1094 snd_printk(KERN_ERR "sscape: Failed to create "
1095 "MPU-401 device at 0x%lx\n",
1096 port[dev]);
1097 goto _release_dma;
1098 }
1191 1099
1192 /* 1100 /*
1193 * Initialize mixer 1101 * Initialize mixer
1194 */ 1102 */
1195 sscape->midi_vol = 0; 1103 spin_lock_irqsave(&sscape->lock, flags);
1196 host_write_ctrl_unsafe(sscape->io_base, CMD_SET_MIDI_VOL, 100); 1104 sscape->midi_vol = 0;
1197 host_write_ctrl_unsafe(sscape->io_base, 0, 100); 1105 host_write_ctrl_unsafe(sscape->io_base,
1198 host_write_ctrl_unsafe(sscape->io_base, CMD_XXX_MIDI_VOL, 100); 1106 CMD_SET_MIDI_VOL, 100);
1107 host_write_ctrl_unsafe(sscape->io_base,
1108 sscape->midi_vol, 100);
1109 host_write_ctrl_unsafe(sscape->io_base,
1110 CMD_XXX_MIDI_VOL, 100);
1111 host_write_ctrl_unsafe(sscape->io_base,
1112 sscape->midi_vol, 100);
1113 host_write_ctrl_unsafe(sscape->io_base,
1114 CMD_SET_EXTMIDI, 100);
1115 host_write_ctrl_unsafe(sscape->io_base,
1116 0, 100);
1117 host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100);
1118
1119 set_midi_mode_unsafe(sscape->io_base);
1120 spin_unlock_irqrestore(&sscape->lock, flags);
1121 }
1199 } 1122 }
1200 1123
1201 /* 1124 /*
@@ -1231,7 +1154,8 @@ static int __devinit snd_sscape_match(struct device *pdev, unsigned int i)
1231 mpu_irq[i] == SNDRV_AUTO_IRQ || 1154 mpu_irq[i] == SNDRV_AUTO_IRQ ||
1232 dma[i] == SNDRV_AUTO_DMA) { 1155 dma[i] == SNDRV_AUTO_DMA) {
1233 printk(KERN_INFO 1156 printk(KERN_INFO
1234 "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n"); 1157 "sscape: insufficient parameters, "
1158 "need IO, IRQ, MPU-IRQ and DMA\n");
1235 return 0; 1159 return 0;
1236 } 1160 }
1237 1161
@@ -1253,13 +1177,15 @@ static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev)
1253 sscape->type = SSCAPE; 1177 sscape->type = SSCAPE;
1254 1178
1255 dma[dev] &= 0x03; 1179 dma[dev] &= 0x03;
1180 snd_card_set_dev(card, pdev);
1181
1256 ret = create_sscape(dev, card); 1182 ret = create_sscape(dev, card);
1257 if (ret < 0) 1183 if (ret < 0)
1258 goto _release_card; 1184 goto _release_card;
1259 1185
1260 snd_card_set_dev(card, pdev); 1186 ret = snd_card_register(card);
1261 if ((ret = snd_card_register(card)) < 0) { 1187 if (ret < 0) {
1262 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1188 snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
1263 goto _release_card; 1189 goto _release_card;
1264 } 1190 }
1265 dev_set_drvdata(pdev, card); 1191 dev_set_drvdata(pdev, card);
@@ -1311,36 +1237,20 @@ static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
1311 * Allow this function to fail *quietly* if all the ISA PnP 1237 * Allow this function to fail *quietly* if all the ISA PnP
1312 * devices were configured using module parameters instead. 1238 * devices were configured using module parameters instead.
1313 */ 1239 */
1314 if ((idx = get_next_autoindex(idx)) >= SNDRV_CARDS) 1240 idx = get_next_autoindex(idx);
1241 if (idx >= SNDRV_CARDS)
1315 return -ENOSPC; 1242 return -ENOSPC;
1316 1243
1317 /* 1244 /*
1318 * We have found a candidate ISA PnP card. Now we
1319 * have to check that it has the devices that we
1320 * expect it to have.
1321 *
1322 * We will NOT try and autoconfigure all of the resources
1323 * needed and then activate the card as we are assuming that
1324 * has already been done at boot-time using /proc/isapnp.
1325 * We shall simply try to give each active card the resources
1326 * that it wants. This is a sensible strategy for a modular
1327 * system where unused modules are unloaded regularly.
1328 *
1329 * This strategy is utterly useless if we compile the driver
1330 * into the kernel, of course.
1331 */
1332 // printk(KERN_INFO "sscape: %s\n", card->name);
1333
1334 /*
1335 * Check that we still have room for another sound card ... 1245 * Check that we still have room for another sound card ...
1336 */ 1246 */
1337 dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL); 1247 dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
1338 if (! dev) 1248 if (!dev)
1339 return -ENODEV; 1249 return -ENODEV;
1340 1250
1341 if (!pnp_is_active(dev)) { 1251 if (!pnp_is_active(dev)) {
1342 if (pnp_activate_dev(dev) < 0) { 1252 if (pnp_activate_dev(dev) < 0) {
1343 printk(KERN_INFO "sscape: device is inactive\n"); 1253 snd_printk(KERN_INFO "sscape: device is inactive\n");
1344 return -EBUSY; 1254 return -EBUSY;
1345 } 1255 }
1346 } 1256 }
@@ -1378,14 +1288,15 @@ static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
1378 wss_port[idx] = pnp_port_start(dev, 1); 1288 wss_port[idx] = pnp_port_start(dev, 1);
1379 dma2[idx] = pnp_dma(dev, 1); 1289 dma2[idx] = pnp_dma(dev, 1);
1380 } 1290 }
1291 snd_card_set_dev(card, &pcard->card->dev);
1381 1292
1382 ret = create_sscape(idx, card); 1293 ret = create_sscape(idx, card);
1383 if (ret < 0) 1294 if (ret < 0)
1384 goto _release_card; 1295 goto _release_card;
1385 1296
1386 snd_card_set_dev(card, &pcard->card->dev); 1297 ret = snd_card_register(card);
1387 if ((ret = snd_card_register(card)) < 0) { 1298 if (ret < 0) {
1388 printk(KERN_ERR "sscape: Failed to register sound card\n"); 1299 snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
1389 goto _release_card; 1300 goto _release_card;
1390 } 1301 }
1391 1302
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 5d2ba1b749ab..2ba18978b419 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -2198,84 +2198,61 @@ EXPORT_SYMBOL(snd_wss_put_double);
2198static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0); 2198static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
2199static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); 2199static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
2200static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0); 2200static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
2201static const DECLARE_TLV_DB_SCALE(db_scale_4bit, -4500, 300, 0);
2201 2202
2202static struct snd_kcontrol_new snd_ad1848_controls[] = { 2203static struct snd_kcontrol_new snd_wss_controls[] = {
2203WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 2204WSS_DOUBLE("PCM Playback Switch", 0,
2204 7, 7, 1, 1), 2205 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2205WSS_DOUBLE_TLV("PCM Playback Volume", 0, 2206WSS_DOUBLE_TLV("PCM Playback Volume", 0,
2206 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1, 2207 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1,
2207 db_scale_6bit), 2208 db_scale_6bit),
2208WSS_DOUBLE("Aux Playback Switch", 0, 2209WSS_DOUBLE("Aux Playback Switch", 0,
2209 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), 2210 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
2210WSS_DOUBLE_TLV("Aux Playback Volume", 0, 2211WSS_DOUBLE_TLV("Aux Playback Volume", 0,
2211 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1, 2212 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
2212 db_scale_5bit_12db_max), 2213 db_scale_5bit_12db_max),
2213WSS_DOUBLE("Aux Playback Switch", 1, 2214WSS_DOUBLE("Aux Playback Switch", 1,
2214 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), 2215 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2215WSS_DOUBLE_TLV("Aux Playback Volume", 1, 2216WSS_DOUBLE_TLV("Aux Playback Volume", 1,
2216 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1, 2217 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
2217 db_scale_5bit_12db_max), 2218 db_scale_5bit_12db_max),
2218WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 2219WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT,
2219 0, 0, 15, 0, db_scale_rec_gain), 2220 0, 0, 15, 0, db_scale_rec_gain),
2220{ 2221{
2221 .name = "Capture Source",
2222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2223 .name = "Capture Source",
2223 .info = snd_wss_info_mux, 2224 .info = snd_wss_info_mux,
2224 .get = snd_wss_get_mux, 2225 .get = snd_wss_get_mux,
2225 .put = snd_wss_put_mux, 2226 .put = snd_wss_put_mux,
2226}, 2227},
2227WSS_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0), 2228WSS_DOUBLE("Mic Boost", 0,
2228WSS_SINGLE_TLV("Loopback Capture Volume", 0, CS4231_LOOPBACK, 1, 63, 0, 2229 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2229 db_scale_6bit), 2230WSS_SINGLE("Loopback Capture Switch", 0,
2230}; 2231 CS4231_LOOPBACK, 0, 1, 0),
2231 2232WSS_SINGLE_TLV("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1,
2232static struct snd_kcontrol_new snd_wss_controls[] = { 2233 db_scale_6bit),
2233WSS_DOUBLE("PCM Playback Switch", 0,
2234 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2235WSS_DOUBLE("PCM Playback Volume", 0,
2236 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
2237WSS_DOUBLE("Line Playback Switch", 0, 2234WSS_DOUBLE("Line Playback Switch", 0,
2238 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), 2235 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
2239WSS_DOUBLE("Line Playback Volume", 0, 2236WSS_DOUBLE_TLV("Line Playback Volume", 0,
2240 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), 2237 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1,
2241WSS_DOUBLE("Aux Playback Switch", 0, 2238 db_scale_5bit_12db_max),
2242 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
2243WSS_DOUBLE("Aux Playback Volume", 0,
2244 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
2245WSS_DOUBLE("Aux Playback Switch", 1,
2246 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2247WSS_DOUBLE("Aux Playback Volume", 1,
2248 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
2249WSS_SINGLE("Mono Playback Switch", 0, 2239WSS_SINGLE("Mono Playback Switch", 0,
2250 CS4231_MONO_CTRL, 7, 1, 1), 2240 CS4231_MONO_CTRL, 7, 1, 1),
2251WSS_SINGLE("Mono Playback Volume", 0, 2241WSS_SINGLE_TLV("Mono Playback Volume", 0,
2252 CS4231_MONO_CTRL, 0, 15, 1), 2242 CS4231_MONO_CTRL, 0, 15, 1,
2243 db_scale_4bit),
2253WSS_SINGLE("Mono Output Playback Switch", 0, 2244WSS_SINGLE("Mono Output Playback Switch", 0,
2254 CS4231_MONO_CTRL, 6, 1, 1), 2245 CS4231_MONO_CTRL, 6, 1, 1),
2255WSS_SINGLE("Mono Output Playback Bypass", 0, 2246WSS_SINGLE("Mono Output Playback Bypass", 0,
2256 CS4231_MONO_CTRL, 5, 1, 0), 2247 CS4231_MONO_CTRL, 5, 1, 0),
2257WSS_DOUBLE("Capture Volume", 0,
2258 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
2259{
2260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2261 .name = "Capture Source",
2262 .info = snd_wss_info_mux,
2263 .get = snd_wss_get_mux,
2264 .put = snd_wss_put_mux,
2265},
2266WSS_DOUBLE("Mic Boost", 0,
2267 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2268WSS_SINGLE("Loopback Capture Switch", 0,
2269 CS4231_LOOPBACK, 0, 1, 0),
2270WSS_SINGLE("Loopback Capture Volume", 0,
2271 CS4231_LOOPBACK, 2, 63, 1)
2272}; 2248};
2273 2249
2274static struct snd_kcontrol_new snd_opti93x_controls[] = { 2250static struct snd_kcontrol_new snd_opti93x_controls[] = {
2275WSS_DOUBLE("Master Playback Switch", 0, 2251WSS_DOUBLE("Master Playback Switch", 0,
2276 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1), 2252 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
2277WSS_DOUBLE("Master Playback Volume", 0, 2253WSS_DOUBLE_TLV("Master Playback Volume", 0,
2278 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1), 2254 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
2255 db_scale_6bit),
2279WSS_DOUBLE("PCM Playback Switch", 0, 2256WSS_DOUBLE("PCM Playback Switch", 0,
2280 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), 2257 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2281WSS_DOUBLE("PCM Playback Volume", 0, 2258WSS_DOUBLE("PCM Playback Volume", 0,
@@ -2334,22 +2311,21 @@ int snd_wss_mixer(struct snd_wss *chip)
2334 if (err < 0) 2311 if (err < 0)
2335 return err; 2312 return err;
2336 } 2313 }
2337 else if (chip->hardware & WSS_HW_AD1848_MASK) 2314 else {
2338 for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++) { 2315 int count = ARRAY_SIZE(snd_wss_controls);
2339 err = snd_ctl_add(card, 2316
2340 snd_ctl_new1(&snd_ad1848_controls[idx], 2317 /* Use only the first 11 entries on AD1848 */
2341 chip)); 2318 if (chip->hardware & WSS_HW_AD1848_MASK)
2342 if (err < 0) 2319 count = 11;
2343 return err; 2320
2344 } 2321 for (idx = 0; idx < count; idx++) {
2345 else
2346 for (idx = 0; idx < ARRAY_SIZE(snd_wss_controls); idx++) {
2347 err = snd_ctl_add(card, 2322 err = snd_ctl_add(card,
2348 snd_ctl_new1(&snd_wss_controls[idx], 2323 snd_ctl_new1(&snd_wss_controls[idx],
2349 chip)); 2324 chip));
2350 if (err < 0) 2325 if (err < 0)
2351 return err; 2326 return err;
2352 } 2327 }
2328 }
2353 return 0; 2329 return 0;
2354} 2330}
2355EXPORT_SYMBOL(snd_wss_mixer); 2331EXPORT_SYMBOL(snd_wss_mixer);
diff --git a/sound/mips/hal2.c b/sound/mips/hal2.c
index c52691c2fc46..9a88cdfd952a 100644
--- a/sound/mips/hal2.c
+++ b/sound/mips/hal2.c
@@ -915,7 +915,7 @@ static int __devinit hal2_probe(struct platform_device *pdev)
915 return 0; 915 return 0;
916} 916}
917 917
918static int __exit hal2_remove(struct platform_device *pdev) 918static int __devexit hal2_remove(struct platform_device *pdev)
919{ 919{
920 struct snd_card *card = platform_get_drvdata(pdev); 920 struct snd_card *card = platform_get_drvdata(pdev);
921 921
diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index e497525bc11b..8691f4cf6191 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -973,7 +973,7 @@ static int __devinit snd_sgio2audio_probe(struct platform_device *pdev)
973 return 0; 973 return 0;
974} 974}
975 975
976static int __exit snd_sgio2audio_remove(struct platform_device *pdev) 976static int __devexit snd_sgio2audio_remove(struct platform_device *pdev)
977{ 977{
978 struct snd_card *card = platform_get_drvdata(pdev); 978 struct snd_card *card = platform_get_drvdata(pdev);
979 979
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
index bcf2a0698d54..135a2b77cc4a 100644
--- a/sound/oss/Kconfig
+++ b/sound/oss/Kconfig
@@ -287,18 +287,6 @@ config SOUND_DMAP
287 287
288 Say Y unless you have 16MB or more RAM or a PCI sound card. 288 Say Y unless you have 16MB or more RAM or a PCI sound card.
289 289
290config SOUND_SSCAPE
291 tristate "Ensoniq SoundScape support"
292 help
293 Answer Y if you have a sound card based on the Ensoniq SoundScape
294 chipset. Such cards are being manufactured at least by Ensoniq, Spea
295 and Reveal (Reveal makes also other cards).
296
297 If you compile the driver into the kernel, you have to add
298 "sscape=<io>,<irq>,<dma>,<mpuio>,<mpuirq>" to the kernel command
299 line.
300
301
302config SOUND_VMIDI 290config SOUND_VMIDI
303 tristate "Loopback MIDI device support" 291 tristate "Loopback MIDI device support"
304 help 292 help
diff --git a/sound/oss/Makefile b/sound/oss/Makefile
index e0ae4d4d6a5c..567b8a74178a 100644
--- a/sound/oss/Makefile
+++ b/sound/oss/Makefile
@@ -13,7 +13,6 @@ obj-$(CONFIG_SOUND_SH_DAC_AUDIO) += sh_dac_audio.o
13obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o 13obj-$(CONFIG_SOUND_AEDSP16) += aedsp16.o
14obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o 14obj-$(CONFIG_SOUND_PSS) += pss.o ad1848.o mpu401.o
15obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o 15obj-$(CONFIG_SOUND_TRIX) += trix.o ad1848.o sb_lib.o uart401.o
16obj-$(CONFIG_SOUND_SSCAPE) += sscape.o ad1848.o mpu401.o
17obj-$(CONFIG_SOUND_MSS) += ad1848.o 16obj-$(CONFIG_SOUND_MSS) += ad1848.o
18obj-$(CONFIG_SOUND_PAS) += pas2.o sb.o sb_lib.o uart401.o 17obj-$(CONFIG_SOUND_PAS) += pas2.o sb.o sb_lib.o uart401.o
19obj-$(CONFIG_SOUND_SB) += sb.o sb_lib.o uart401.o 18obj-$(CONFIG_SOUND_SB) += sb.o sb_lib.o uart401.o
diff --git a/sound/oss/sh_dac_audio.c b/sound/oss/sh_dac_audio.c
index b2ed8757542a..4153752507e3 100644
--- a/sound/oss/sh_dac_audio.c
+++ b/sound/oss/sh_dac_audio.c
@@ -164,9 +164,6 @@ static ssize_t dac_audio_write(struct file *file, const char *buf, size_t count,
164 int free; 164 int free;
165 int nbytes; 165 int nbytes;
166 166
167 if (count < 0)
168 return -EINVAL;
169
170 if (!count) { 167 if (!count) {
171 dac_audio_sync(); 168 dac_audio_sync();
172 return 0; 169 return 0;
diff --git a/sound/oss/sscape.c b/sound/oss/sscape.c
deleted file mode 100644
index 30c36d1f35d7..000000000000
--- a/sound/oss/sscape.c
+++ /dev/null
@@ -1,1480 +0,0 @@
1/*
2 * sound/oss/sscape.c
3 *
4 * Low level driver for Ensoniq SoundScape
5 *
6 *
7 * Copyright (C) by Hannu Savolainen 1993-1997
8 *
9 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
10 * Version 2 (June 1991). See the "COPYING" file distributed with this software
11 * for more info.
12 *
13 *
14 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
15 * Sergey Smitienko : ensoniq p'n'p support
16 * Christoph Hellwig : adapted to module_init/module_exit
17 * Bartlomiej Zolnierkiewicz : added __init to attach_sscape()
18 * Chris Rankin : Specify that this module owns the coprocessor
19 * Arnaldo C. de Melo : added missing restore_flags in sscape_pnp_upload_file
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24
25#include "sound_config.h"
26#include "sound_firmware.h"
27
28#include <linux/types.h>
29#include <linux/errno.h>
30#include <linux/signal.h>
31#include <linux/fcntl.h>
32#include <linux/ctype.h>
33#include <linux/stddef.h>
34#include <linux/kmod.h>
35#include <asm/dma.h>
36#include <asm/io.h>
37#include <linux/wait.h>
38#include <linux/slab.h>
39#include <linux/ioport.h>
40#include <linux/delay.h>
41#include <linux/proc_fs.h>
42#include <linux/mm.h>
43#include <linux/spinlock.h>
44
45#include "coproc.h"
46
47#include "ad1848.h"
48#include "mpu401.h"
49
50/*
51 * I/O ports
52 */
53#define MIDI_DATA 0
54#define MIDI_CTRL 1
55#define HOST_CTRL 2
56#define TX_READY 0x02
57#define RX_READY 0x01
58#define HOST_DATA 3
59#define ODIE_ADDR 4
60#define ODIE_DATA 5
61
62/*
63 * Indirect registers
64 */
65
66#define GA_INTSTAT_REG 0
67#define GA_INTENA_REG 1
68#define GA_DMAA_REG 2
69#define GA_DMAB_REG 3
70#define GA_INTCFG_REG 4
71#define GA_DMACFG_REG 5
72#define GA_CDCFG_REG 6
73#define GA_SMCFGA_REG 7
74#define GA_SMCFGB_REG 8
75#define GA_HMCTL_REG 9
76
77/*
78 * DMA channel identifiers (A and B)
79 */
80
81#define SSCAPE_DMA_A 0
82#define SSCAPE_DMA_B 1
83
84#define PORT(name) (devc->base+name)
85
86/*
87 * Host commands recognized by the OBP microcode
88 */
89
90#define CMD_GEN_HOST_ACK 0x80
91#define CMD_GEN_MPU_ACK 0x81
92#define CMD_GET_BOARD_TYPE 0x82
93#define CMD_SET_CONTROL 0x88 /* Old firmware only */
94#define CMD_GET_CONTROL 0x89 /* Old firmware only */
95#define CTL_MASTER_VOL 0
96#define CTL_MIC_MODE 2
97#define CTL_SYNTH_VOL 4
98#define CTL_WAVE_VOL 7
99#define CMD_SET_EXTMIDI 0x8a
100#define CMD_GET_EXTMIDI 0x8b
101#define CMD_SET_MT32 0x8c
102#define CMD_GET_MT32 0x8d
103
104#define CMD_ACK 0x80
105
106#define IC_ODIE 1
107#define IC_OPUS 2
108
109typedef struct sscape_info
110{
111 int base, irq, dma;
112
113 int codec, codec_irq; /* required to setup pnp cards*/
114 int codec_type;
115 int ic_type;
116 char* raw_buf;
117 unsigned long raw_buf_phys;
118 int buffsize; /* -------------------------- */
119 spinlock_t lock;
120 int ok; /* Properly detected */
121 int failed;
122 int dma_allocated;
123 int codec_audiodev;
124 int opened;
125 int *osp;
126 int my_audiodev;
127} sscape_info;
128
129static struct sscape_info adev_info = {
130 0
131};
132
133static struct sscape_info *devc = &adev_info;
134static int sscape_mididev = -1;
135
136/* Some older cards have assigned interrupt bits differently than new ones */
137static char valid_interrupts_old[] = {
138 9, 7, 5, 15
139};
140
141static char valid_interrupts_new[] = {
142 9, 5, 7, 10
143};
144
145static char *valid_interrupts = valid_interrupts_new;
146
147/*
148 * See the bottom of the driver. This can be set by spea =0/1.
149 */
150
151#ifdef REVEAL_SPEA
152static char old_hardware = 1;
153#else
154static char old_hardware;
155#endif
156
157static void sleep(unsigned howlong)
158{
159 current->state = TASK_INTERRUPTIBLE;
160 schedule_timeout(howlong);
161}
162
163static unsigned char sscape_read(struct sscape_info *devc, int reg)
164{
165 unsigned long flags;
166 unsigned char val;
167
168 spin_lock_irqsave(&devc->lock,flags);
169 outb(reg, PORT(ODIE_ADDR));
170 val = inb(PORT(ODIE_DATA));
171 spin_unlock_irqrestore(&devc->lock,flags);
172 return val;
173}
174
175static void __sscape_write(int reg, int data)
176{
177 outb(reg, PORT(ODIE_ADDR));
178 outb(data, PORT(ODIE_DATA));
179}
180
181static void sscape_write(struct sscape_info *devc, int reg, int data)
182{
183 unsigned long flags;
184
185 spin_lock_irqsave(&devc->lock,flags);
186 __sscape_write(reg, data);
187 spin_unlock_irqrestore(&devc->lock,flags);
188}
189
190static unsigned char sscape_pnp_read_codec(sscape_info* devc, unsigned char reg)
191{
192 unsigned char res;
193 unsigned long flags;
194
195 spin_lock_irqsave(&devc->lock,flags);
196 outb( reg, devc -> codec);
197 res = inb (devc -> codec + 1);
198 spin_unlock_irqrestore(&devc->lock,flags);
199 return res;
200
201}
202
203static void sscape_pnp_write_codec(sscape_info* devc, unsigned char reg, unsigned char data)
204{
205 unsigned long flags;
206
207 spin_lock_irqsave(&devc->lock,flags);
208 outb( reg, devc -> codec);
209 outb( data, devc -> codec + 1);
210 spin_unlock_irqrestore(&devc->lock,flags);
211}
212
213static void host_open(struct sscape_info *devc)
214{
215 outb((0x00), PORT(HOST_CTRL)); /* Put the board to the host mode */
216}
217
218static void host_close(struct sscape_info *devc)
219{
220 outb((0x03), PORT(HOST_CTRL)); /* Put the board to the MIDI mode */
221}
222
223static int host_write(struct sscape_info *devc, unsigned char *data, int count)
224{
225 unsigned long flags;
226 int i, timeout_val;
227
228 spin_lock_irqsave(&devc->lock,flags);
229 /*
230 * Send the command and data bytes
231 */
232
233 for (i = 0; i < count; i++)
234 {
235 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
236 if (inb(PORT(HOST_CTRL)) & TX_READY)
237 break;
238
239 if (timeout_val <= 0)
240 {
241 spin_unlock_irqrestore(&devc->lock,flags);
242 return 0;
243 }
244 outb(data[i], PORT(HOST_DATA));
245 }
246 spin_unlock_irqrestore(&devc->lock,flags);
247 return 1;
248}
249
250static int host_read(struct sscape_info *devc)
251{
252 unsigned long flags;
253 int timeout_val;
254 unsigned char data;
255
256 spin_lock_irqsave(&devc->lock,flags);
257 /*
258 * Read a byte
259 */
260
261 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
262 if (inb(PORT(HOST_CTRL)) & RX_READY)
263 break;
264
265 if (timeout_val <= 0)
266 {
267 spin_unlock_irqrestore(&devc->lock,flags);
268 return -1;
269 }
270 data = inb(PORT(HOST_DATA));
271 spin_unlock_irqrestore(&devc->lock,flags);
272 return data;
273}
274
275#if 0 /* unused */
276static int host_command1(struct sscape_info *devc, int cmd)
277{
278 unsigned char buf[10];
279 buf[0] = (unsigned char) (cmd & 0xff);
280 return host_write(devc, buf, 1);
281}
282#endif /* unused */
283
284
285static int host_command2(struct sscape_info *devc, int cmd, int parm1)
286{
287 unsigned char buf[10];
288
289 buf[0] = (unsigned char) (cmd & 0xff);
290 buf[1] = (unsigned char) (parm1 & 0xff);
291
292 return host_write(devc, buf, 2);
293}
294
295static int host_command3(struct sscape_info *devc, int cmd, int parm1, int parm2)
296{
297 unsigned char buf[10];
298
299 buf[0] = (unsigned char) (cmd & 0xff);
300 buf[1] = (unsigned char) (parm1 & 0xff);
301 buf[2] = (unsigned char) (parm2 & 0xff);
302 return host_write(devc, buf, 3);
303}
304
305static void set_mt32(struct sscape_info *devc, int value)
306{
307 host_open(devc);
308 host_command2(devc, CMD_SET_MT32, value ? 1 : 0);
309 if (host_read(devc) != CMD_ACK)
310 {
311 /* printk( "SNDSCAPE: Setting MT32 mode failed\n"); */
312 }
313 host_close(devc);
314}
315
316static void set_control(struct sscape_info *devc, int ctrl, int value)
317{
318 host_open(devc);
319 host_command3(devc, CMD_SET_CONTROL, ctrl, value);
320 if (host_read(devc) != CMD_ACK)
321 {
322 /* printk( "SNDSCAPE: Setting control (%d) failed\n", ctrl); */
323 }
324 host_close(devc);
325}
326
327static void do_dma(struct sscape_info *devc, int dma_chan, unsigned long buf, int blk_size, int mode)
328{
329 unsigned char temp;
330
331 if (dma_chan != SSCAPE_DMA_A)
332 {
333 printk(KERN_WARNING "soundscape: Tried to use DMA channel != A. Why?\n");
334 return;
335 }
336 audio_devs[devc->codec_audiodev]->flags &= ~DMA_AUTOMODE;
337 DMAbuf_start_dma(devc->codec_audiodev, buf, blk_size, mode);
338 audio_devs[devc->codec_audiodev]->flags |= DMA_AUTOMODE;
339
340 temp = devc->dma << 4; /* Setup DMA channel select bits */
341 if (devc->dma <= 3)
342 temp |= 0x80; /* 8 bit DMA channel */
343
344 temp |= 1; /* Trigger DMA */
345 sscape_write(devc, GA_DMAA_REG, temp);
346 temp &= 0xfe; /* Clear DMA trigger */
347 sscape_write(devc, GA_DMAA_REG, temp);
348}
349
350static int verify_mpu(struct sscape_info *devc)
351{
352 /*
353 * The SoundScape board could be in three modes (MPU, 8250 and host).
354 * If the card is not in the MPU mode, enabling the MPU driver will
355 * cause infinite loop (the driver believes that there is always some
356 * received data in the buffer.
357 *
358 * Detect this by looking if there are more than 10 received MIDI bytes
359 * (0x00) in the buffer.
360 */
361
362 int i;
363
364 for (i = 0; i < 10; i++)
365 {
366 if (inb(devc->base + HOST_CTRL) & 0x80)
367 return 1;
368
369 if (inb(devc->base) != 0x00)
370 return 1;
371 }
372 printk(KERN_WARNING "SoundScape: The device is not in the MPU-401 mode\n");
373 return 0;
374}
375
376static int sscape_coproc_open(void *dev_info, int sub_device)
377{
378 if (sub_device == COPR_MIDI)
379 {
380 set_mt32(devc, 0);
381 if (!verify_mpu(devc))
382 return -EIO;
383 }
384 return 0;
385}
386
387static void sscape_coproc_close(void *dev_info, int sub_device)
388{
389 struct sscape_info *devc = dev_info;
390 unsigned long flags;
391
392 spin_lock_irqsave(&devc->lock,flags);
393 if (devc->dma_allocated)
394 {
395 __sscape_write(GA_DMAA_REG, 0x20); /* DMA channel disabled */
396 devc->dma_allocated = 0;
397 }
398 spin_unlock_irqrestore(&devc->lock,flags);
399 return;
400}
401
402static void sscape_coproc_reset(void *dev_info)
403{
404}
405
406static int sscape_download_boot(struct sscape_info *devc, unsigned char *block, int size, int flag)
407{
408 unsigned long flags;
409 unsigned char temp;
410 volatile int done, timeout_val;
411 static unsigned char codec_dma_bits;
412
413 if (flag & CPF_FIRST)
414 {
415 /*
416 * First block. Have to allocate DMA and to reset the board
417 * before continuing.
418 */
419
420 spin_lock_irqsave(&devc->lock,flags);
421 codec_dma_bits = sscape_read(devc, GA_CDCFG_REG);
422
423 if (devc->dma_allocated == 0)
424 devc->dma_allocated = 1;
425
426 spin_unlock_irqrestore(&devc->lock,flags);
427
428 sscape_write(devc, GA_HMCTL_REG,
429 (temp = sscape_read(devc, GA_HMCTL_REG)) & 0x3f); /*Reset */
430
431 for (timeout_val = 10000; timeout_val > 0; timeout_val--)
432 sscape_read(devc, GA_HMCTL_REG); /* Delay */
433
434 /* Take board out of reset */
435 sscape_write(devc, GA_HMCTL_REG,
436 (temp = sscape_read(devc, GA_HMCTL_REG)) | 0x80);
437 }
438 /*
439 * Transfer one code block using DMA
440 */
441 if (audio_devs[devc->codec_audiodev]->dmap_out->raw_buf == NULL)
442 {
443 printk(KERN_WARNING "soundscape: DMA buffer not available\n");
444 return 0;
445 }
446 memcpy(audio_devs[devc->codec_audiodev]->dmap_out->raw_buf, block, size);
447
448 spin_lock_irqsave(&devc->lock,flags);
449
450 /******** INTERRUPTS DISABLED NOW ********/
451
452 do_dma(devc, SSCAPE_DMA_A,
453 audio_devs[devc->codec_audiodev]->dmap_out->raw_buf_phys,
454 size, DMA_MODE_WRITE);
455
456 /*
457 * Wait until transfer completes.
458 */
459
460 done = 0;
461 timeout_val = 30;
462 while (!done && timeout_val-- > 0)
463 {
464 int resid;
465
466 if (HZ / 50)
467 sleep(HZ / 50);
468 clear_dma_ff(devc->dma);
469 if ((resid = get_dma_residue(devc->dma)) == 0)
470 done = 1;
471 }
472
473 spin_unlock_irqrestore(&devc->lock,flags);
474 if (!done)
475 return 0;
476
477 if (flag & CPF_LAST)
478 {
479 /*
480 * Take the board out of reset
481 */
482 outb((0x00), PORT(HOST_CTRL));
483 outb((0x00), PORT(MIDI_CTRL));
484
485 temp = sscape_read(devc, GA_HMCTL_REG);
486 temp |= 0x40;
487 sscape_write(devc, GA_HMCTL_REG, temp); /* Kickstart the board */
488
489 /*
490 * Wait until the ODB wakes up
491 */
492 spin_lock_irqsave(&devc->lock,flags);
493 done = 0;
494 timeout_val = 5 * HZ;
495 while (!done && timeout_val-- > 0)
496 {
497 unsigned char x;
498
499 sleep(1);
500 x = inb(PORT(HOST_DATA));
501 if (x == 0xff || x == 0xfe) /* OBP startup acknowledge */
502 {
503 DDB(printk("Soundscape: Acknowledge = %x\n", x));
504 done = 1;
505 }
506 }
507 sscape_write(devc, GA_CDCFG_REG, codec_dma_bits);
508
509 spin_unlock_irqrestore(&devc->lock,flags);
510 if (!done)
511 {
512 printk(KERN_ERR "soundscape: The OBP didn't respond after code download\n");
513 return 0;
514 }
515 spin_lock_irqsave(&devc->lock,flags);
516 done = 0;
517 timeout_val = 5 * HZ;
518 while (!done && timeout_val-- > 0)
519 {
520 sleep(1);
521 if (inb(PORT(HOST_DATA)) == 0xfe) /* Host startup acknowledge */
522 done = 1;
523 }
524 spin_unlock_irqrestore(&devc->lock,flags);
525 if (!done)
526 {
527 printk(KERN_ERR "soundscape: OBP Initialization failed.\n");
528 return 0;
529 }
530 printk(KERN_INFO "SoundScape board initialized OK\n");
531 set_control(devc, CTL_MASTER_VOL, 100);
532 set_control(devc, CTL_SYNTH_VOL, 100);
533
534#ifdef SSCAPE_DEBUG3
535 /*
536 * Temporary debugging aid. Print contents of the registers after
537 * downloading the code.
538 */
539 {
540 int i;
541
542 for (i = 0; i < 13; i++)
543 printk("I%d = %02x (new value)\n", i, sscape_read(devc, i));
544 }
545#endif
546
547 }
548 return 1;
549}
550
551static int download_boot_block(void *dev_info, copr_buffer * buf)
552{
553 if (buf->len <= 0 || buf->len > sizeof(buf->data))
554 return -EINVAL;
555
556 if (!sscape_download_boot(devc, buf->data, buf->len, buf->flags))
557 {
558 printk(KERN_ERR "soundscape: Unable to load microcode block to the OBP.\n");
559 return -EIO;
560 }
561 return 0;
562}
563
564static int sscape_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
565{
566 copr_buffer *buf;
567 int err;
568
569 switch (cmd)
570 {
571 case SNDCTL_COPR_RESET:
572 sscape_coproc_reset(dev_info);
573 return 0;
574
575 case SNDCTL_COPR_LOAD:
576 buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
577 if (buf == NULL)
578 return -ENOSPC;
579 if (copy_from_user(buf, arg, sizeof(copr_buffer)))
580 {
581 vfree(buf);
582 return -EFAULT;
583 }
584 err = download_boot_block(dev_info, buf);
585 vfree(buf);
586 return err;
587
588 default:
589 return -EINVAL;
590 }
591}
592
593static coproc_operations sscape_coproc_operations =
594{
595 "SoundScape M68K",
596 THIS_MODULE,
597 sscape_coproc_open,
598 sscape_coproc_close,
599 sscape_coproc_ioctl,
600 sscape_coproc_reset,
601 &adev_info
602};
603
604static struct resource *sscape_ports;
605static int sscape_is_pnp;
606
607static void __init attach_sscape(struct address_info *hw_config)
608{
609#ifndef SSCAPE_REGS
610 /*
611 * Config register values for Spea/V7 Media FX and Ensoniq S-2000.
612 * These values are card
613 * dependent. If you have another SoundScape based card, you have to
614 * find the correct values. Do the following:
615 * - Compile this driver with SSCAPE_DEBUG1 defined.
616 * - Shut down and power off your machine.
617 * - Boot with DOS so that the SSINIT.EXE program is run.
618 * - Warm boot to {Linux|SYSV|BSD} and write down the lines displayed
619 * when detecting the SoundScape.
620 * - Modify the following list to use the values printed during boot.
621 * Undefine the SSCAPE_DEBUG1
622 */
623#define SSCAPE_REGS { \
624/* I0 */ 0x00, \
625/* I1 */ 0xf0, /* Note! Ignored. Set always to 0xf0 */ \
626/* I2 */ 0x20, /* Note! Ignored. Set always to 0x20 */ \
627/* I3 */ 0x20, /* Note! Ignored. Set always to 0x20 */ \
628/* I4 */ 0xf5, /* Ignored */ \
629/* I5 */ 0x10, \
630/* I6 */ 0x00, \
631/* I7 */ 0x2e, /* I7 MEM config A. Likely to vary between models */ \
632/* I8 */ 0x00, /* I8 MEM config B. Likely to vary between models */ \
633/* I9 */ 0x40 /* Ignored */ \
634 }
635#endif
636
637 unsigned long flags;
638 static unsigned char regs[10] = SSCAPE_REGS;
639
640 int i, irq_bits = 0xff;
641
642 if (old_hardware)
643 {
644 valid_interrupts = valid_interrupts_old;
645 conf_printf("Ensoniq SoundScape (old)", hw_config);
646 }
647 else
648 conf_printf("Ensoniq SoundScape", hw_config);
649
650 for (i = 0; i < 4; i++)
651 {
652 if (hw_config->irq == valid_interrupts[i])
653 {
654 irq_bits = i;
655 break;
656 }
657 }
658 if (hw_config->irq > 15 || (regs[4] = irq_bits == 0xff))
659 {
660 printk(KERN_ERR "Invalid IRQ%d\n", hw_config->irq);
661 release_region(devc->base, 2);
662 release_region(devc->base + 2, 6);
663 if (sscape_is_pnp)
664 release_region(devc->codec, 2);
665 return;
666 }
667
668 if (!sscape_is_pnp) {
669
670 spin_lock_irqsave(&devc->lock,flags);
671 /* Host interrupt enable */
672 sscape_write(devc, 1, 0xf0); /* All interrupts enabled */
673 /* DMA A status/trigger register */
674 sscape_write(devc, 2, 0x20); /* DMA channel disabled */
675 /* DMA B status/trigger register */
676 sscape_write(devc, 3, 0x20); /* DMA channel disabled */
677 /* Host interrupt config reg */
678 sscape_write(devc, 4, 0xf0 | (irq_bits << 2) | irq_bits);
679 /* Don't destroy CD-ROM DMA config bits (0xc0) */
680 sscape_write(devc, 5, (regs[5] & 0x3f) | (sscape_read(devc, 5) & 0xc0));
681 /* CD-ROM config (WSS codec actually) */
682 sscape_write(devc, 6, regs[6]);
683 sscape_write(devc, 7, regs[7]);
684 sscape_write(devc, 8, regs[8]);
685 /* Master control reg. Don't modify CR-ROM bits. Disable SB emul */
686 sscape_write(devc, 9, (sscape_read(devc, 9) & 0xf0) | 0x08);
687 spin_unlock_irqrestore(&devc->lock,flags);
688 }
689#ifdef SSCAPE_DEBUG2
690 /*
691 * Temporary debugging aid. Print contents of the registers after
692 * changing them.
693 */
694 {
695 int i;
696
697 for (i = 0; i < 13; i++)
698 printk("I%d = %02x (new value)\n", i, sscape_read(devc, i));
699 }
700#endif
701
702 if (probe_mpu401(hw_config, sscape_ports))
703 hw_config->always_detect = 1;
704 hw_config->name = "SoundScape";
705
706 hw_config->irq *= -1; /* Negative value signals IRQ sharing */
707 attach_mpu401(hw_config, THIS_MODULE);
708 hw_config->irq *= -1; /* Restore it */
709
710 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
711 {
712 sscape_mididev = hw_config->slots[1];
713 midi_devs[hw_config->slots[1]]->coproc = &sscape_coproc_operations;
714 }
715 sscape_write(devc, GA_INTENA_REG, 0x80); /* Master IRQ enable */
716 devc->ok = 1;
717 devc->failed = 0;
718}
719
720static int detect_ga(sscape_info * devc)
721{
722 unsigned char save;
723
724 DDB(printk("Entered Soundscape detect_ga(%x)\n", devc->base));
725
726 /*
727 * First check that the address register of "ODIE" is
728 * there and that it has exactly 4 writable bits.
729 * First 4 bits
730 */
731
732 if ((save = inb(PORT(ODIE_ADDR))) & 0xf0)
733 {
734 DDB(printk("soundscape: Detect error A\n"));
735 return 0;
736 }
737 outb((0x00), PORT(ODIE_ADDR));
738 if (inb(PORT(ODIE_ADDR)) != 0x00)
739 {
740 DDB(printk("soundscape: Detect error B\n"));
741 return 0;
742 }
743 outb((0xff), PORT(ODIE_ADDR));
744 if (inb(PORT(ODIE_ADDR)) != 0x0f)
745 {
746 DDB(printk("soundscape: Detect error C\n"));
747 return 0;
748 }
749 outb((save), PORT(ODIE_ADDR));
750
751 /*
752 * Now verify that some indirect registers return zero on some bits.
753 * This may break the driver with some future revisions of "ODIE" but...
754 */
755
756 if (sscape_read(devc, 0) & 0x0c)
757 {
758 DDB(printk("soundscape: Detect error D (%x)\n", sscape_read(devc, 0)));
759 return 0;
760 }
761 if (sscape_read(devc, 1) & 0x0f)
762 {
763 DDB(printk("soundscape: Detect error E\n"));
764 return 0;
765 }
766 if (sscape_read(devc, 5) & 0x0f)
767 {
768 DDB(printk("soundscape: Detect error F\n"));
769 return 0;
770 }
771 return 1;
772}
773
774static int sscape_read_host_ctrl(sscape_info* devc)
775{
776 return host_read(devc);
777}
778
779static void sscape_write_host_ctrl2(sscape_info *devc, int a, int b)
780{
781 host_command2(devc, a, b);
782}
783
784static int sscape_alloc_dma(sscape_info *devc)
785{
786 char *start_addr, *end_addr;
787 int dma_pagesize;
788 int sz, size;
789 struct page *page;
790
791 if (devc->raw_buf != NULL) return 0; /* Already done */
792 dma_pagesize = (devc->dma < 4) ? (64 * 1024) : (128 * 1024);
793 devc->raw_buf = NULL;
794 devc->buffsize = 8192*4;
795 if (devc->buffsize > dma_pagesize) devc->buffsize = dma_pagesize;
796 start_addr = NULL;
797 /*
798 * Now loop until we get a free buffer. Try to get smaller buffer if
799 * it fails. Don't accept smaller than 8k buffer for performance
800 * reasons.
801 */
802 while (start_addr == NULL && devc->buffsize > PAGE_SIZE) {
803 for (sz = 0, size = PAGE_SIZE; size < devc->buffsize; sz++, size <<= 1);
804 devc->buffsize = PAGE_SIZE * (1 << sz);
805 start_addr = (char *) __get_free_pages(GFP_ATOMIC|GFP_DMA, sz);
806 if (start_addr == NULL) devc->buffsize /= 2;
807 }
808
809 if (start_addr == NULL) {
810 printk(KERN_ERR "sscape pnp init error: Couldn't allocate DMA buffer\n");
811 return 0;
812 } else {
813 /* make some checks */
814 end_addr = start_addr + devc->buffsize - 1;
815 /* now check if it fits into the same dma-pagesize */
816
817 if (((long) start_addr & ~(dma_pagesize - 1)) != ((long) end_addr & ~(dma_pagesize - 1))
818 || end_addr >= (char *) (MAX_DMA_ADDRESS)) {
819 printk(KERN_ERR "sscape pnp: Got invalid address 0x%lx for %db DMA-buffer\n", (long) start_addr, devc->buffsize);
820 return 0;
821 }
822 }
823 devc->raw_buf = start_addr;
824 devc->raw_buf_phys = virt_to_bus(start_addr);
825
826 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
827 SetPageReserved(page);
828 return 1;
829}
830
831static void sscape_free_dma(sscape_info *devc)
832{
833 int sz, size;
834 unsigned long start_addr, end_addr;
835 struct page *page;
836
837 if (devc->raw_buf == NULL) return;
838 for (sz = 0, size = PAGE_SIZE; size < devc->buffsize; sz++, size <<= 1);
839 start_addr = (unsigned long) devc->raw_buf;
840 end_addr = start_addr + devc->buffsize;
841
842 for (page = virt_to_page(start_addr); page <= virt_to_page(end_addr); page++)
843 ClearPageReserved(page);
844
845 free_pages((unsigned long) devc->raw_buf, sz);
846 devc->raw_buf = NULL;
847}
848
849/* Intel version !!!!!!!!! */
850
851static int sscape_start_dma(int chan, unsigned long physaddr, int count, int dma_mode)
852{
853 unsigned long flags;
854
855 flags = claim_dma_lock();
856 disable_dma(chan);
857 clear_dma_ff(chan);
858 set_dma_mode(chan, dma_mode);
859 set_dma_addr(chan, physaddr);
860 set_dma_count(chan, count);
861 enable_dma(chan);
862 release_dma_lock(flags);
863 return 0;
864}
865
866static void sscape_pnp_start_dma(sscape_info* devc, int arg )
867{
868 int reg;
869 if (arg == 0) reg = 2;
870 else reg = 3;
871
872 sscape_write(devc, reg, sscape_read( devc, reg) | 0x01);
873 sscape_write(devc, reg, sscape_read( devc, reg) & 0xFE);
874}
875
876static int sscape_pnp_wait_dma (sscape_info* devc, int arg )
877{
878 int reg;
879 unsigned long i;
880 unsigned char d;
881
882 if (arg == 0) reg = 2;
883 else reg = 3;
884
885 sleep ( 1 );
886 i = 0;
887 do {
888 d = sscape_read(devc, reg) & 1;
889 if ( d == 1) break;
890 i++;
891 } while (i < 500000);
892 d = sscape_read(devc, reg) & 1;
893 return d;
894}
895
896static int sscape_pnp_alloc_dma(sscape_info* devc)
897{
898 /* printk(KERN_INFO "sscape: requesting dma\n"); */
899 if (request_dma(devc -> dma, "sscape")) return 0;
900 /* printk(KERN_INFO "sscape: dma channel allocated\n"); */
901 if (!sscape_alloc_dma(devc)) {
902 free_dma(devc -> dma);
903 return 0;
904 };
905 return 1;
906}
907
908static void sscape_pnp_free_dma(sscape_info* devc)
909{
910 sscape_free_dma( devc);
911 free_dma(devc -> dma );
912 /* printk(KERN_INFO "sscape: dma released\n"); */
913}
914
915static int sscape_pnp_upload_file(sscape_info* devc, char* fn)
916{
917 int done = 0;
918 int timeout_val;
919 char* data,*dt;
920 int len,l;
921 unsigned long flags;
922
923 sscape_write( devc, 9, sscape_read(devc, 9 ) & 0x3F );
924 sscape_write( devc, 2, (devc -> dma << 4) | 0x80 );
925 sscape_write( devc, 3, 0x20 );
926 sscape_write( devc, 9, sscape_read( devc, 9 ) | 0x80 );
927
928 len = mod_firmware_load(fn, &data);
929 if (len == 0) {
930 printk(KERN_ERR "sscape: file not found: %s\n", fn);
931 return 0;
932 }
933 dt = data;
934 spin_lock_irqsave(&devc->lock,flags);
935 while ( len > 0 ) {
936 if (len > devc -> buffsize) l = devc->buffsize;
937 else l = len;
938 len -= l;
939 memcpy(devc->raw_buf, dt, l); dt += l;
940 sscape_start_dma(devc->dma, devc->raw_buf_phys, l, 0x48);
941 sscape_pnp_start_dma ( devc, 0 );
942 if (sscape_pnp_wait_dma ( devc, 0 ) == 0) {
943 spin_unlock_irqrestore(&devc->lock,flags);
944 return 0;
945 }
946 }
947
948 spin_unlock_irqrestore(&devc->lock,flags);
949 vfree(data);
950
951 outb(0, devc -> base + 2);
952 outb(0, devc -> base);
953
954 sscape_write ( devc, 9, sscape_read( devc, 9 ) | 0x40);
955
956 timeout_val = 5 * HZ;
957 while (!done && timeout_val-- > 0)
958 {
959 unsigned char x;
960 sleep(1);
961 x = inb( devc -> base + 3);
962 if (x == 0xff || x == 0xfe) /* OBP startup acknowledge */
963 {
964 //printk(KERN_ERR "Soundscape: Acknowledge = %x\n", x);
965 done = 1;
966 }
967 }
968 timeout_val = 5 * HZ;
969 done = 0;
970 while (!done && timeout_val-- > 0)
971 {
972 unsigned char x;
973 sleep(1);
974 x = inb( devc -> base + 3);
975 if (x == 0xfe) /* OBP startup acknowledge */
976 {
977 //printk(KERN_ERR "Soundscape: Acknowledge = %x\n", x);
978 done = 1;
979 }
980 }
981
982 if ( !done ) printk(KERN_ERR "soundscape: OBP Initialization failed.\n");
983
984 sscape_write( devc, 2, devc->ic_type == IC_ODIE ? 0x70 : 0x40);
985 sscape_write( devc, 3, (devc -> dma << 4) + 0x80);
986 return 1;
987}
988
989static void __init sscape_pnp_init_hw(sscape_info* devc)
990{
991 unsigned char midi_irq = 0, sb_irq = 0;
992 unsigned i;
993 static char code_file_name[23] = "/sndscape/sndscape.cox";
994
995 int sscape_joystic_enable = 0x7f;
996 int sscape_mic_enable = 0;
997 int sscape_ext_midi = 0;
998
999 if ( !sscape_pnp_alloc_dma(devc) ) {
1000 printk(KERN_ERR "sscape: faild to allocate dma\n");
1001 return;
1002 }
1003
1004 for (i = 0; i < 4; i++) {
1005 if ( devc -> irq == valid_interrupts[i] )
1006 midi_irq = i;
1007 if ( devc -> codec_irq == valid_interrupts[i] )
1008 sb_irq = i;
1009 }
1010
1011 sscape_write( devc, 5, 0x50);
1012 sscape_write( devc, 7, 0x2e);
1013 sscape_write( devc, 8, 0x00);
1014
1015 sscape_write( devc, 2, devc->ic_type == IC_ODIE ? 0x70 : 0x40);
1016 sscape_write( devc, 3, ( devc -> dma << 4) | 0x80);
1017
1018 sscape_write (devc, 4, 0xF0 | (midi_irq<<2) | midi_irq);
1019
1020 i = 0x10; //sscape_read(devc, 9) & (devc->ic_type == IC_ODIE ? 0xf0 : 0xc0);
1021 if (sscape_joystic_enable) i |= 8;
1022
1023 sscape_write (devc, 9, i);
1024 sscape_write (devc, 6, 0x80);
1025 sscape_write (devc, 1, 0x80);
1026
1027 if (devc -> codec_type == 2) {
1028 sscape_pnp_write_codec( devc, 0x0C, 0x50);
1029 sscape_pnp_write_codec( devc, 0x10, sscape_pnp_read_codec( devc, 0x10) & 0x3F);
1030 sscape_pnp_write_codec( devc, 0x11, sscape_pnp_read_codec( devc, 0x11) | 0xC0);
1031 sscape_pnp_write_codec( devc, 29, 0x20);
1032 }
1033
1034 if (sscape_pnp_upload_file(devc, "/sndscape/scope.cod") == 0 ) {
1035 printk(KERN_ERR "sscape: faild to upload file /sndscape/scope.cod\n");
1036 sscape_pnp_free_dma(devc);
1037 return;
1038 }
1039
1040 i = sscape_read_host_ctrl( devc );
1041
1042 if ( (i & 0x0F) > 7 ) {
1043 printk(KERN_ERR "sscape: scope.cod faild\n");
1044 sscape_pnp_free_dma(devc);
1045 return;
1046 }
1047 if ( i & 0x10 ) sscape_write( devc, 7, 0x2F);
1048 code_file_name[21] = (char) ( i & 0x0F) + 0x30;
1049 if (sscape_pnp_upload_file( devc, code_file_name) == 0) {
1050 printk(KERN_ERR "sscape: faild to upload file %s\n", code_file_name);
1051 sscape_pnp_free_dma(devc);
1052 return;
1053 }
1054
1055 if (devc->ic_type != IC_ODIE) {
1056 sscape_pnp_write_codec( devc, 10, (sscape_pnp_read_codec(devc, 10) & 0x7f) |
1057 ( sscape_mic_enable == 0 ? 0x00 : 0x80) );
1058 }
1059 sscape_write_host_ctrl2( devc, 0x84, 0x64 ); /* MIDI volume */
1060 sscape_write_host_ctrl2( devc, 0x86, 0x64 ); /* MIDI volume?? */
1061 sscape_write_host_ctrl2( devc, 0x8A, sscape_ext_midi);
1062
1063 sscape_pnp_write_codec ( devc, 6, 0x3f ); //WAV_VOL
1064 sscape_pnp_write_codec ( devc, 7, 0x3f ); //WAV_VOL
1065 sscape_pnp_write_codec ( devc, 2, 0x1F ); //WD_CDXVOLL
1066 sscape_pnp_write_codec ( devc, 3, 0x1F ); //WD_CDXVOLR
1067
1068 if (devc -> codec_type == 1) {
1069 sscape_pnp_write_codec ( devc, 4, 0x1F );
1070 sscape_pnp_write_codec ( devc, 5, 0x1F );
1071 sscape_write_host_ctrl2( devc, 0x88, sscape_mic_enable);
1072 } else {
1073 int t;
1074 sscape_pnp_write_codec ( devc, 0x10, 0x1F << 1);
1075 sscape_pnp_write_codec ( devc, 0x11, 0xC0 | (0x1F << 1));
1076
1077 t = sscape_pnp_read_codec( devc, 0x00) & 0xDF;
1078 if ( (sscape_mic_enable == 0)) t |= 0;
1079 else t |= 0x20;
1080 sscape_pnp_write_codec ( devc, 0x00, t);
1081 t = sscape_pnp_read_codec( devc, 0x01) & 0xDF;
1082 if ( (sscape_mic_enable == 0) ) t |= 0;
1083 else t |= 0x20;
1084 sscape_pnp_write_codec ( devc, 0x01, t);
1085 sscape_pnp_write_codec ( devc, 0x40 | 29 , 0x20);
1086 outb(0, devc -> codec);
1087 }
1088 if (devc -> ic_type == IC_OPUS ) {
1089 int i = sscape_read( devc, 9 );
1090 sscape_write( devc, 9, i | 3 );
1091 sscape_write( devc, 3, 0x40);
1092
1093 if (request_region(0x228, 1, "sscape setup junk")) {
1094 outb(0, 0x228);
1095 release_region(0x228,1);
1096 }
1097 sscape_write( devc, 3, (devc -> dma << 4) | 0x80);
1098 sscape_write( devc, 9, i );
1099 }
1100
1101 host_close ( devc );
1102 sscape_pnp_free_dma(devc);
1103}
1104
1105static int __init detect_sscape_pnp(sscape_info* devc)
1106{
1107 long i, irq_bits = 0xff;
1108 unsigned int d;
1109
1110 DDB(printk("Entered detect_sscape_pnp(%x)\n", devc->base));
1111
1112 if (!request_region(devc->codec, 2, "sscape codec")) {
1113 printk(KERN_ERR "detect_sscape_pnp: port %x is not free\n", devc->codec);
1114 return 0;
1115 }
1116
1117 if ((inb(devc->base + 2) & 0x78) != 0)
1118 goto fail;
1119
1120 d = inb ( devc -> base + 4) & 0xF0;
1121 if (d & 0x80)
1122 goto fail;
1123
1124 if (d == 0) {
1125 devc->codec_type = 1;
1126 devc->ic_type = IC_ODIE;
1127 } else if ( (d & 0x60) != 0) {
1128 devc->codec_type = 2;
1129 devc->ic_type = IC_OPUS;
1130 } else if ( (d & 0x40) != 0) { /* WTF? */
1131 devc->codec_type = 2;
1132 devc->ic_type = IC_ODIE;
1133 } else
1134 goto fail;
1135
1136 sscape_is_pnp = 1;
1137
1138 outb(0xFA, devc -> base+4);
1139 if ((inb( devc -> base+4) & 0x9F) != 0x0A)
1140 goto fail;
1141 outb(0xFE, devc -> base+4);
1142 if ( (inb(devc -> base+4) & 0x9F) != 0x0E)
1143 goto fail;
1144 if ( (inb(devc -> base+5) & 0x9F) != 0x0E)
1145 goto fail;
1146
1147 if (devc->codec_type == 2) {
1148 if (devc->codec != devc->base + 8) {
1149 printk("soundscape warning: incorrect codec port specified\n");
1150 goto fail;
1151 }
1152 d = 0x10 | (sscape_read(devc, 9) & 0xCF);
1153 sscape_write(devc, 9, d);
1154 sscape_write(devc, 6, 0x80);
1155 } else {
1156 //todo: check codec is not base + 8
1157 }
1158
1159 d = (sscape_read(devc, 9) & 0x3F) | 0xC0;
1160 sscape_write(devc, 9, d);
1161
1162 for (i = 0; i < 550000; i++)
1163 if ( !(inb(devc -> codec) & 0x80) ) break;
1164
1165 d = inb(devc -> codec);
1166 if (d & 0x80)
1167 goto fail;
1168 if ( inb(devc -> codec + 2) == 0xFF)
1169 goto fail;
1170
1171 sscape_write(devc, 9, sscape_read(devc, 9) & 0x3F );
1172
1173 d = inb(devc -> codec) & 0x80;
1174 if ( d == 0) {
1175 printk(KERN_INFO "soundscape: hardware detected\n");
1176 valid_interrupts = valid_interrupts_new;
1177 } else {
1178 printk(KERN_INFO "soundscape: board looks like media fx\n");
1179 valid_interrupts = valid_interrupts_old;
1180 old_hardware = 1;
1181 }
1182
1183 sscape_write( devc, 9, 0xC0 | (sscape_read(devc, 9) & 0x3F) );
1184
1185 for (i = 0; i < 550000; i++)
1186 if ( !(inb(devc -> codec) & 0x80))
1187 break;
1188
1189 sscape_pnp_init_hw(devc);
1190
1191 for (i = 0; i < 4; i++)
1192 {
1193 if (devc->codec_irq == valid_interrupts[i]) {
1194 irq_bits = i;
1195 break;
1196 }
1197 }
1198 sscape_write(devc, GA_INTENA_REG, 0x00);
1199 sscape_write(devc, GA_DMACFG_REG, 0x50);
1200 sscape_write(devc, GA_DMAA_REG, 0x70);
1201 sscape_write(devc, GA_DMAB_REG, 0x20);
1202 sscape_write(devc, GA_INTCFG_REG, 0xf0);
1203 sscape_write(devc, GA_CDCFG_REG, 0x89 | (devc->dma << 4) | (irq_bits << 1));
1204
1205 sscape_pnp_write_codec( devc, 0, sscape_pnp_read_codec( devc, 0) | 0x20);
1206 sscape_pnp_write_codec( devc, 0, sscape_pnp_read_codec( devc, 1) | 0x20);
1207
1208 return 1;
1209fail:
1210 release_region(devc->codec, 2);
1211 return 0;
1212}
1213
1214static int __init probe_sscape(struct address_info *hw_config)
1215{
1216 devc->base = hw_config->io_base;
1217 devc->irq = hw_config->irq;
1218 devc->dma = hw_config->dma;
1219 devc->osp = hw_config->osp;
1220
1221#ifdef SSCAPE_DEBUG1
1222 /*
1223 * Temporary debugging aid. Print contents of the registers before
1224 * changing them.
1225 */
1226 {
1227 int i;
1228
1229 for (i = 0; i < 13; i++)
1230 printk("I%d = %02x (old value)\n", i, sscape_read(devc, i));
1231 }
1232#endif
1233 devc->failed = 1;
1234
1235 sscape_ports = request_region(devc->base, 2, "mpu401");
1236 if (!sscape_ports)
1237 return 0;
1238
1239 if (!request_region(devc->base + 2, 6, "SoundScape")) {
1240 release_region(devc->base, 2);
1241 return 0;
1242 }
1243
1244 if (!detect_ga(devc)) {
1245 if (detect_sscape_pnp(devc))
1246 return 1;
1247 release_region(devc->base, 2);
1248 release_region(devc->base + 2, 6);
1249 return 0;
1250 }
1251
1252 if (old_hardware) /* Check that it's really an old Spea/Reveal card. */
1253 {
1254 unsigned char tmp;
1255 int cc;
1256
1257 if (!((tmp = sscape_read(devc, GA_HMCTL_REG)) & 0xc0))
1258 {
1259 sscape_write(devc, GA_HMCTL_REG, tmp | 0x80);
1260 for (cc = 0; cc < 200000; ++cc)
1261 inb(devc->base + ODIE_ADDR);
1262 }
1263 }
1264 return 1;
1265}
1266
1267static int __init init_ss_ms_sound(struct address_info *hw_config)
1268{
1269 int i, irq_bits = 0xff;
1270 int ad_flags = 0;
1271 struct resource *ports;
1272
1273 if (devc->failed)
1274 {
1275 printk(KERN_ERR "soundscape: Card not detected\n");
1276 return 0;
1277 }
1278 if (devc->ok == 0)
1279 {
1280 printk(KERN_ERR "soundscape: Invalid initialization order.\n");
1281 return 0;
1282 }
1283 for (i = 0; i < 4; i++)
1284 {
1285 if (hw_config->irq == valid_interrupts[i])
1286 {
1287 irq_bits = i;
1288 break;
1289 }
1290 }
1291 if (irq_bits == 0xff) {
1292 printk(KERN_ERR "soundscape: Invalid MSS IRQ%d\n", hw_config->irq);
1293 return 0;
1294 }
1295
1296 if (old_hardware)
1297 ad_flags = 0x12345677; /* Tell that we may have a CS4248 chip (Spea-V7 Media FX) */
1298 else if (sscape_is_pnp)
1299 ad_flags = 0x87654321; /* Tell that we have a soundscape pnp with 1845 chip */
1300
1301 ports = request_region(hw_config->io_base, 4, "ad1848");
1302 if (!ports) {
1303 printk(KERN_ERR "soundscape: ports busy\n");
1304 return 0;
1305 }
1306
1307 if (!ad1848_detect(ports, &ad_flags, hw_config->osp)) {
1308 release_region(hw_config->io_base, 4);
1309 return 0;
1310 }
1311
1312 if (!sscape_is_pnp) /*pnp is already setup*/
1313 {
1314 /*
1315 * Setup the DMA polarity.
1316 */
1317 sscape_write(devc, GA_DMACFG_REG, 0x50);
1318
1319 /*
1320 * Take the gate-array off of the DMA channel.
1321 */
1322 sscape_write(devc, GA_DMAB_REG, 0x20);
1323
1324 /*
1325 * Init the AD1848 (CD-ROM) config reg.
1326 */
1327 sscape_write(devc, GA_CDCFG_REG, 0x89 | (hw_config->dma << 4) | (irq_bits << 1));
1328 }
1329
1330 if (hw_config->irq == devc->irq)
1331 printk(KERN_WARNING "soundscape: Warning! The WSS mode can't share IRQ with MIDI\n");
1332
1333 hw_config->slots[0] = ad1848_init(
1334 sscape_is_pnp ? "SoundScape" : "SoundScape PNP",
1335 ports,
1336 hw_config->irq,
1337 hw_config->dma,
1338 hw_config->dma,
1339 0,
1340 devc->osp,
1341 THIS_MODULE);
1342
1343
1344 if (hw_config->slots[0] != -1) /* The AD1848 driver installed itself */
1345 {
1346 audio_devs[hw_config->slots[0]]->coproc = &sscape_coproc_operations;
1347 devc->codec_audiodev = hw_config->slots[0];
1348 devc->my_audiodev = hw_config->slots[0];
1349
1350 /* Set proper routings here (what are they) */
1351 AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE);
1352 }
1353
1354#ifdef SSCAPE_DEBUG5
1355 /*
1356 * Temporary debugging aid. Print contents of the registers
1357 * after the AD1848 device has been initialized.
1358 */
1359 {
1360 int i;
1361
1362 for (i = 0; i < 13; i++)
1363 printk("I%d = %02x\n", i, sscape_read(devc, i));
1364 }
1365#endif
1366 return 1;
1367}
1368
1369static void __exit unload_sscape(struct address_info *hw_config)
1370{
1371 release_region(devc->base + 2, 6);
1372 unload_mpu401(hw_config);
1373 if (sscape_is_pnp)
1374 release_region(devc->codec, 2);
1375}
1376
1377static void __exit unload_ss_ms_sound(struct address_info *hw_config)
1378{
1379 ad1848_unload(hw_config->io_base,
1380 hw_config->irq,
1381 devc->dma,
1382 devc->dma,
1383 0);
1384 sound_unload_audiodev(hw_config->slots[0]);
1385}
1386
1387static struct address_info cfg;
1388static struct address_info cfg_mpu;
1389
1390static int __initdata spea = -1;
1391static int mss = 0;
1392static int __initdata dma = -1;
1393static int __initdata irq = -1;
1394static int __initdata io = -1;
1395static int __initdata mpu_irq = -1;
1396static int __initdata mpu_io = -1;
1397
1398module_param(dma, int, 0);
1399module_param(irq, int, 0);
1400module_param(io, int, 0);
1401module_param(spea, int, 0); /* spea=0/1 set the old_hardware */
1402module_param(mpu_irq, int, 0);
1403module_param(mpu_io, int, 0);
1404module_param(mss, int, 0);
1405
1406static int __init init_sscape(void)
1407{
1408 printk(KERN_INFO "Soundscape driver Copyright (C) by Hannu Savolainen 1993-1996\n");
1409
1410 cfg.irq = irq;
1411 cfg.dma = dma;
1412 cfg.io_base = io;
1413
1414 cfg_mpu.irq = mpu_irq;
1415 cfg_mpu.io_base = mpu_io;
1416 /* WEH - Try to get right dma channel */
1417 cfg_mpu.dma = dma;
1418
1419 devc->codec = cfg.io_base;
1420 devc->codec_irq = cfg.irq;
1421 devc->codec_type = 0;
1422 devc->ic_type = 0;
1423 devc->raw_buf = NULL;
1424 spin_lock_init(&devc->lock);
1425
1426 if (cfg.dma == -1 || cfg.irq == -1 || cfg.io_base == -1) {
1427 printk(KERN_ERR "DMA, IRQ, and IO port must be specified.\n");
1428 return -EINVAL;
1429 }
1430
1431 if (cfg_mpu.irq == -1 && cfg_mpu.io_base != -1) {
1432 printk(KERN_ERR "MPU_IRQ must be specified if MPU_IO is set.\n");
1433 return -EINVAL;
1434 }
1435
1436 if(spea != -1) {
1437 old_hardware = spea;
1438 printk(KERN_INFO "Forcing %s hardware support.\n",
1439 spea?"new":"old");
1440 }
1441 if (probe_sscape(&cfg_mpu) == 0)
1442 return -ENODEV;
1443
1444 attach_sscape(&cfg_mpu);
1445
1446 mss = init_ss_ms_sound(&cfg);
1447
1448 return 0;
1449}
1450
1451static void __exit cleanup_sscape(void)
1452{
1453 if (mss)
1454 unload_ss_ms_sound(&cfg);
1455 unload_sscape(&cfg_mpu);
1456}
1457
1458module_init(init_sscape);
1459module_exit(cleanup_sscape);
1460
1461#ifndef MODULE
1462static int __init setup_sscape(char *str)
1463{
1464 /* io, irq, dma, mpu_io, mpu_irq */
1465 int ints[6];
1466
1467 str = get_options(str, ARRAY_SIZE(ints), ints);
1468
1469 io = ints[1];
1470 irq = ints[2];
1471 dma = ints[3];
1472 mpu_io = ints[4];
1473 mpu_irq = ints[5];
1474
1475 return 1;
1476}
1477
1478__setup("sscape=", setup_sscape);
1479#endif
1480MODULE_LICENSE("GPL");
diff --git a/sound/parisc/harmony.c b/sound/parisc/harmony.c
index e924492df21d..f47f9e226b08 100644
--- a/sound/parisc/harmony.c
+++ b/sound/parisc/harmony.c
@@ -624,6 +624,9 @@ snd_harmony_pcm_init(struct snd_harmony *h)
624 struct snd_pcm *pcm; 624 struct snd_pcm *pcm;
625 int err; 625 int err;
626 626
627 if (snd_BUG_ON(!h))
628 return -EINVAL;
629
627 harmony_disable_interrupts(h); 630 harmony_disable_interrupts(h);
628 631
629 err = snd_pcm_new(h->card, "harmony", 0, 1, 1, &pcm); 632 err = snd_pcm_new(h->card, "harmony", 0, 1, 1, &pcm);
@@ -865,11 +868,12 @@ snd_harmony_mixer_reset(struct snd_harmony *h)
865static int __devinit 868static int __devinit
866snd_harmony_mixer_init(struct snd_harmony *h) 869snd_harmony_mixer_init(struct snd_harmony *h)
867{ 870{
868 struct snd_card *card = h->card; 871 struct snd_card *card;
869 int idx, err; 872 int idx, err;
870 873
871 if (snd_BUG_ON(!h)) 874 if (snd_BUG_ON(!h))
872 return -EINVAL; 875 return -EINVAL;
876 card = h->card;
873 strcpy(card->mixername, "Harmony Gain control interface"); 877 strcpy(card->mixername, "Harmony Gain control interface");
874 878
875 for (idx = 0; idx < HARMONY_CONTROLS; idx++) { 879 for (idx = 0; idx < HARMONY_CONTROLS; idx++) {
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index fb5ee3cc3968..75c602b5b132 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -259,7 +259,6 @@ config SND_CS5530
259 259
260config SND_CS5535AUDIO 260config SND_CS5535AUDIO
261 tristate "CS5535/CS5536 Audio" 261 tristate "CS5535/CS5536 Audio"
262 depends on X86 && !X86_64
263 select SND_PCM 262 select SND_PCM
264 select SND_AC97_CODEC 263 select SND_AC97_CODEC
265 help 264 help
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 78288dbfc17a..20cb60afb200 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -603,8 +603,8 @@ AC97_SINGLE("Tone Control - Treble", AC97_MASTER_TONE, 0, 15, 1)
603}; 603};
604 604
605static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = { 605static const struct snd_kcontrol_new snd_ac97_controls_pc_beep[2] = {
606AC97_SINGLE("PC Speaker Playback Switch", AC97_PC_BEEP, 15, 1, 1), 606AC97_SINGLE("Beep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
607AC97_SINGLE("PC Speaker Playback Volume", AC97_PC_BEEP, 1, 15, 1) 607AC97_SINGLE("Beep Playback Volume", AC97_PC_BEEP, 1, 15, 1)
608}; 608};
609 609
610static const struct snd_kcontrol_new snd_ac97_controls_mic_boost = 610static const struct snd_kcontrol_new snd_ac97_controls_mic_boost =
@@ -1393,7 +1393,7 @@ static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
1393 } 1393 }
1394 } 1394 }
1395 1395
1396 /* build PC Speaker controls */ 1396 /* build Beep controls */
1397 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) && 1397 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
1398 ((ac97->flags & AC97_HAS_PC_BEEP) || 1398 ((ac97->flags & AC97_HAS_PC_BEEP) ||
1399 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) { 1399 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 7337abdbe4e3..139cf3b2b9d7 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -800,12 +800,12 @@ AC97_SINGLE("Mono Switch", AC97_MASTER_TONE, 7, 1, 1),
800AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 800AC97_SINGLE("Mono ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
801AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1), 801AC97_SINGLE("Mono Volume", AC97_MASTER_TONE, 0, 31, 1),
802 802
803AC97_SINGLE("PC Beep to Headphone Switch", AC97_AUX, 15, 1, 1), 803AC97_SINGLE("Beep to Headphone Switch", AC97_AUX, 15, 1, 1),
804AC97_SINGLE("PC Beep to Headphone Volume", AC97_AUX, 12, 7, 1), 804AC97_SINGLE("Beep to Headphone Volume", AC97_AUX, 12, 7, 1),
805AC97_SINGLE("PC Beep to Master Switch", AC97_AUX, 11, 1, 1), 805AC97_SINGLE("Beep to Master Switch", AC97_AUX, 11, 1, 1),
806AC97_SINGLE("PC Beep to Master Volume", AC97_AUX, 8, 7, 1), 806AC97_SINGLE("Beep to Master Volume", AC97_AUX, 8, 7, 1),
807AC97_SINGLE("PC Beep to Mono Switch", AC97_AUX, 7, 1, 1), 807AC97_SINGLE("Beep to Mono Switch", AC97_AUX, 7, 1, 1),
808AC97_SINGLE("PC Beep to Mono Volume", AC97_AUX, 4, 7, 1), 808AC97_SINGLE("Beep to Mono Volume", AC97_AUX, 4, 7, 1),
809 809
810AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1), 810AC97_SINGLE("Voice to Headphone Switch", AC97_PCM, 15, 1, 1),
811AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1), 811AC97_SINGLE("Voice to Headphone Volume", AC97_PCM, 12, 7, 1),
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index b458d208720b..aaf4da68969c 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -973,7 +973,7 @@ static void snd_ali_free_voice(struct snd_ali * codec,
973 void *private_data; 973 void *private_data;
974 974
975 snd_ali_printk("free_voice: channel=%d\n",pvoice->number); 975 snd_ali_printk("free_voice: channel=%d\n",pvoice->number);
976 if (pvoice == NULL || !pvoice->use) 976 if (!pvoice->use)
977 return; 977 return;
978 snd_ali_clear_voices(codec, pvoice->number, pvoice->number); 978 snd_ali_clear_voices(codec, pvoice->number, pvoice->number);
979 spin_lock_irq(&codec->voice_alloc); 979 spin_lock_irq(&codec->voice_alloc);
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 8451a0169f32..69867ace7860 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -830,8 +830,8 @@ static struct snd_kcontrol_new snd_azf3328_mixer_controls[] __devinitdata = {
830 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0), 830 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
831 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1), 831 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
832 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1), 832 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
833 AZF3328_MIXER_SWITCH("PC Speaker Playback Switch", IDX_MIXER_PCBEEP, 15, 1), 833 AZF3328_MIXER_SWITCH("Beep Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
834 AZF3328_MIXER_VOL_SPECIAL("PC Speaker Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1), 834 AZF3328_MIXER_VOL_SPECIAL("Beep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
835 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1), 835 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
836 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1), 836 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
837 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1), 837 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 24585c6c6d01..4e2b925a94cc 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -808,6 +808,8 @@ static struct pci_device_id snd_bt87x_ids[] = {
808 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x1002, 0x0001, GENERIC), 808 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x1002, 0x0001, GENERIC),
809 /* Leadtek Winfast tv 2000xp delux */ 809 /* Leadtek Winfast tv 2000xp delux */
810 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x107d, 0x6606, GENERIC), 810 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x107d, 0x6606, GENERIC),
811 /* Pinnacle PCTV */
812 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x11bd, 0x0012, GENERIC),
811 /* Voodoo TV 200 */ 813 /* Voodoo TV 200 */
812 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x121a, 0x3000, GENERIC), 814 BT_DEVICE(PCI_DEVICE_ID_BROOKTREE_878, 0x121a, 0x3000, GENERIC),
813 /* Askey Computer Corp. MagicTView'99 */ 815 /* Askey Computer Corp. MagicTView'99 */
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index c8c6f437f5b3..8f443a9d61ec 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -792,8 +792,8 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
792 "Phone Playback Volume", 792 "Phone Playback Volume",
793 "Video Playback Switch", 793 "Video Playback Switch",
794 "Video Playback Volume", 794 "Video Playback Volume",
795 "PC Speaker Playback Switch", 795 "Beep Playback Switch",
796 "PC Speaker Playback Volume", 796 "Beep Playback Volume",
797 "Mono Output Select", 797 "Mono Output Select",
798 "Capture Source", 798 "Capture Source",
799 "Capture Switch", 799 "Capture Switch",
diff --git a/sound/pci/ca0106/ca0106_proc.c b/sound/pci/ca0106/ca0106_proc.c
index c62b7d10ec61..15523e60351c 100644
--- a/sound/pci/ca0106/ca0106_proc.c
+++ b/sound/pci/ca0106/ca0106_proc.c
@@ -304,7 +304,7 @@ static void snd_ca0106_proc_reg_write32(struct snd_info_entry *entry,
304 while (!snd_info_get_line(buffer, line, sizeof(line))) { 304 while (!snd_info_get_line(buffer, line, sizeof(line))) {
305 if (sscanf(line, "%x %x", &reg, &val) != 2) 305 if (sscanf(line, "%x %x", &reg, &val) != 2)
306 continue; 306 continue;
307 if ((reg < 0x40) && (reg >=0) && (val <= 0xffffffff) ) { 307 if (reg < 0x40 && val <= 0xffffffff) {
308 spin_lock_irqsave(&emu->emu_lock, flags); 308 spin_lock_irqsave(&emu->emu_lock, flags);
309 outl(val, emu->port + (reg & 0xfffffffc)); 309 outl(val, emu->port + (reg & 0xfffffffc));
310 spin_unlock_irqrestore(&emu->emu_lock, flags); 310 spin_unlock_irqrestore(&emu->emu_lock, flags);
@@ -405,7 +405,7 @@ static void snd_ca0106_proc_reg_write(struct snd_info_entry *entry,
405 while (!snd_info_get_line(buffer, line, sizeof(line))) { 405 while (!snd_info_get_line(buffer, line, sizeof(line))) {
406 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 406 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
407 continue; 407 continue;
408 if ((reg < 0x80) && (reg >=0) && (val <= 0xffffffff) && (channel_id >=0) && (channel_id <= 3) ) 408 if (reg < 0x80 && val <= 0xffffffff && channel_id <= 3)
409 snd_ca0106_ptr_write(emu, reg, channel_id, val); 409 snd_ca0106_ptr_write(emu, reg, channel_id, val);
410 } 410 }
411} 411}
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index ddcd4a9fd7e6..a312bae08f52 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2302,7 +2302,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
2302 CMIPCI_SB_VOL_MONO("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31), 2302 CMIPCI_SB_VOL_MONO("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
2303 CMIPCI_SB_SW_MONO("Mic Playback Switch", 0), 2303 CMIPCI_SB_SW_MONO("Mic Playback Switch", 0),
2304 CMIPCI_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1, 0, 0), 2304 CMIPCI_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1, 0, 0),
2305 CMIPCI_SB_VOL_MONO("PC Speaker Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3), 2305 CMIPCI_SB_VOL_MONO("Beep Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
2306 CMIPCI_MIXER_VOL_STEREO("Aux Playback Volume", CM_REG_AUX_VOL, 4, 0, 15), 2306 CMIPCI_MIXER_VOL_STEREO("Aux Playback Volume", CM_REG_AUX_VOL, 4, 0, 15),
2307 CMIPCI_MIXER_SW_STEREO("Aux Playback Switch", CM_REG_MIXER2, CM_VAUXLM_SHIFT, CM_VAUXRM_SHIFT, 0), 2307 CMIPCI_MIXER_SW_STEREO("Aux Playback Switch", CM_REG_MIXER2, CM_VAUXLM_SHIFT, CM_VAUXRM_SHIFT, 0),
2308 CMIPCI_MIXER_SW_STEREO("Aux Capture Switch", CM_REG_MIXER2, CM_RAUXLEN_SHIFT, CM_RAUXREN_SHIFT, 0), 2308 CMIPCI_MIXER_SW_STEREO("Aux Capture Switch", CM_REG_MIXER2, CM_RAUXLEN_SHIFT, CM_RAUXREN_SHIFT, 0),
@@ -2310,7 +2310,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
2310 CMIPCI_MIXER_VOL_MONO("Mic Capture Volume", CM_REG_MIXER2, CM_VADMIC_SHIFT, 7), 2310 CMIPCI_MIXER_VOL_MONO("Mic Capture Volume", CM_REG_MIXER2, CM_VADMIC_SHIFT, 7),
2311 CMIPCI_SB_VOL_MONO("Phone Playback Volume", CM_REG_EXTENT_IND, 5, 7), 2311 CMIPCI_SB_VOL_MONO("Phone Playback Volume", CM_REG_EXTENT_IND, 5, 7),
2312 CMIPCI_DOUBLE("Phone Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 4, 4, 1, 0, 0), 2312 CMIPCI_DOUBLE("Phone Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 4, 4, 1, 0, 0),
2313 CMIPCI_DOUBLE("PC Speaker Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0), 2313 CMIPCI_DOUBLE("Beep Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0),
2314 CMIPCI_DOUBLE("Mic Boost Capture Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 0, 0, 1, 0, 0), 2314 CMIPCI_DOUBLE("Mic Boost Capture Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 0, 0, 1, 0, 0),
2315}; 2315};
2316 2316
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index b1b3a644f738..cb65bd0dd35b 100644
--- a/sound/pci/ctxfi/ctatc.c
+++ b/sound/pci/ctxfi/ctatc.c
@@ -240,7 +240,7 @@ static int select_rom(unsigned int pitch)
240 } else if (pitch == 0x02000000) { 240 } else if (pitch == 0x02000000) {
241 /* pitch == 2 */ 241 /* pitch == 2 */
242 return 3; 242 return 3;
243 } else if (pitch >= 0x0 && pitch <= 0x08000000) { 243 } else if (pitch <= 0x08000000) {
244 /* 0 <= pitch <= 8 */ 244 /* 0 <= pitch <= 8 */
245 return 0; 245 return 0;
246 } else { 246 } else {
@@ -1037,7 +1037,7 @@ static int atc_line_front_unmute(struct ct_atc *atc, unsigned char state)
1037 1037
1038static int atc_line_surround_unmute(struct ct_atc *atc, unsigned char state) 1038static int atc_line_surround_unmute(struct ct_atc *atc, unsigned char state)
1039{ 1039{
1040 return atc_daio_unmute(atc, state, LINEO4); 1040 return atc_daio_unmute(atc, state, LINEO2);
1041} 1041}
1042 1042
1043static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state) 1043static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state)
@@ -1047,7 +1047,7 @@ static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state)
1047 1047
1048static int atc_line_rear_unmute(struct ct_atc *atc, unsigned char state) 1048static int atc_line_rear_unmute(struct ct_atc *atc, unsigned char state)
1049{ 1049{
1050 return atc_daio_unmute(atc, state, LINEO2); 1050 return atc_daio_unmute(atc, state, LINEO4);
1051} 1051}
1052 1052
1053static int atc_line_in_unmute(struct ct_atc *atc, unsigned char state) 1053static int atc_line_in_unmute(struct ct_atc *atc, unsigned char state)
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index da2065cd2c0d..1305f7ca02c3 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -950,7 +950,7 @@ static int __devinit snd_echo_new_pcm(struct echoaudio *chip)
950 Control interface 950 Control interface
951******************************************************************************/ 951******************************************************************************/
952 952
953#ifndef ECHOCARD_HAS_VMIXER 953#if !defined(ECHOCARD_HAS_VMIXER) || defined(ECHOCARD_HAS_LINE_OUT_GAIN)
954 954
955/******************* PCM output volume *******************/ 955/******************* PCM output volume *******************/
956static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol, 956static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
@@ -1003,6 +1003,19 @@ static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
1003 return changed; 1003 return changed;
1004} 1004}
1005 1005
1006#ifdef ECHOCARD_HAS_LINE_OUT_GAIN
1007/* On the Mia this one controls the line-out volume */
1008static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata = {
1009 .name = "Line Playback Volume",
1010 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1011 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1012 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1013 .info = snd_echo_output_gain_info,
1014 .get = snd_echo_output_gain_get,
1015 .put = snd_echo_output_gain_put,
1016 .tlv = {.p = db_scale_output_gain},
1017};
1018#else
1006static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = { 1019static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1007 .name = "PCM Playback Volume", 1020 .name = "PCM Playback Volume",
1008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1021 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1012,9 +1025,10 @@ static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1012 .put = snd_echo_output_gain_put, 1025 .put = snd_echo_output_gain_put,
1013 .tlv = {.p = db_scale_output_gain}, 1026 .tlv = {.p = db_scale_output_gain},
1014}; 1027};
1015
1016#endif 1028#endif
1017 1029
1030#endif /* !ECHOCARD_HAS_VMIXER || ECHOCARD_HAS_LINE_OUT_GAIN */
1031
1018 1032
1019 1033
1020#ifdef ECHOCARD_HAS_INPUT_GAIN 1034#ifdef ECHOCARD_HAS_INPUT_GAIN
@@ -2030,10 +2044,18 @@ static int __devinit snd_echo_probe(struct pci_dev *pci,
2030 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip); 2044 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2031 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0) 2045 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2032 goto ctl_error; 2046 goto ctl_error;
2033#else 2047#ifdef ECHOCARD_HAS_LINE_OUT_GAIN
2034 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_pcm_output_gain, chip))) < 0) 2048 err = snd_ctl_add(chip->card,
2049 snd_ctl_new1(&snd_echo_line_output_gain, chip));
2050 if (err < 0)
2035 goto ctl_error; 2051 goto ctl_error;
2036#endif 2052#endif
2053#else /* ECHOCARD_HAS_VMIXER */
2054 err = snd_ctl_add(chip->card,
2055 snd_ctl_new1(&snd_echo_pcm_output_gain, chip));
2056 if (err < 0)
2057 goto ctl_error;
2058#endif /* ECHOCARD_HAS_VMIXER */
2037 2059
2038#ifdef ECHOCARD_HAS_INPUT_GAIN 2060#ifdef ECHOCARD_HAS_INPUT_GAIN
2039 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0) 2061 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_input_gain, chip))) < 0)
diff --git a/sound/pci/echoaudio/mia.c b/sound/pci/echoaudio/mia.c
index f3b9b45c9c1b..f05c8c097aa8 100644
--- a/sound/pci/echoaudio/mia.c
+++ b/sound/pci/echoaudio/mia.c
@@ -29,6 +29,7 @@
29#define ECHOCARD_HAS_ADAT FALSE 29#define ECHOCARD_HAS_ADAT FALSE
30#define ECHOCARD_HAS_STEREO_BIG_ENDIAN32 30#define ECHOCARD_HAS_STEREO_BIG_ENDIAN32
31#define ECHOCARD_HAS_MIDI 31#define ECHOCARD_HAS_MIDI
32#define ECHOCARD_HAS_LINE_OUT_GAIN
32 33
33/* Pipe indexes */ 34/* Pipe indexes */
34#define PX_ANALOG_OUT 0 /* 8 */ 35#define PX_ANALOG_OUT 0 /* 8 */
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 36e08bd2b3cc..6b8ae7b5cd54 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -1040,8 +1040,7 @@ static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,
1040 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 1040 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
1041 continue; 1041 continue;
1042 1042
1043 if ((reg < 0x49) && (reg >= 0) && (val <= 0xffffffff) 1043 if (reg < 0x49 && val <= 0xffffffff && channel_id <= 2)
1044 && (channel_id >= 0) && (channel_id <= 2) )
1045 snd_emu10k1x_ptr_write(emu, reg, channel_id, val); 1044 snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
1046 } 1045 }
1047} 1046}
diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index b0fb6c917c38..05afe06e353a 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -1818,8 +1818,8 @@ int __devinit snd_emu10k1_mixer(struct snd_emu10k1 *emu,
1818 "Master Playback Switch", "Master Capture Switch", 1818 "Master Playback Switch", "Master Capture Switch",
1819 "Master Playback Volume", "Master Capture Volume", 1819 "Master Playback Volume", "Master Capture Volume",
1820 "Wave Master Playback Volume", "Master Playback Volume", 1820 "Wave Master Playback Volume", "Master Playback Volume",
1821 "PC Speaker Playback Switch", "PC Speaker Capture Switch", 1821 "Beep Playback Switch", "Beep Capture Switch",
1822 "PC Speaker Playback Volume", "PC Speaker Capture Volume", 1822 "Beep Playback Volume", "Beep Capture Volume",
1823 "Phone Playback Switch", "Phone Capture Switch", 1823 "Phone Playback Switch", "Phone Capture Switch",
1824 "Phone Playback Volume", "Phone Capture Volume", 1824 "Phone Playback Volume", "Phone Capture Volume",
1825 "Mic Playback Switch", "Mic Capture Switch", 1825 "Mic Playback Switch", "Mic Capture Switch",
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index 216f9748aff5..baa7cd508cd8 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -451,7 +451,7 @@ static void snd_emu_proc_io_reg_write(struct snd_info_entry *entry,
451 while (!snd_info_get_line(buffer, line, sizeof(line))) { 451 while (!snd_info_get_line(buffer, line, sizeof(line))) {
452 if (sscanf(line, "%x %x", &reg, &val) != 2) 452 if (sscanf(line, "%x %x", &reg, &val) != 2)
453 continue; 453 continue;
454 if ((reg < 0x40) && (reg >= 0) && (val <= 0xffffffff) ) { 454 if (reg < 0x40 && val <= 0xffffffff) {
455 spin_lock_irqsave(&emu->emu_lock, flags); 455 spin_lock_irqsave(&emu->emu_lock, flags);
456 outl(val, emu->port + (reg & 0xfffffffc)); 456 outl(val, emu->port + (reg & 0xfffffffc));
457 spin_unlock_irqrestore(&emu->emu_lock, flags); 457 spin_unlock_irqrestore(&emu->emu_lock, flags);
@@ -527,7 +527,7 @@ static void snd_emu_proc_ptr_reg_write(struct snd_info_entry *entry,
527 while (!snd_info_get_line(buffer, line, sizeof(line))) { 527 while (!snd_info_get_line(buffer, line, sizeof(line))) {
528 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3) 528 if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
529 continue; 529 continue;
530 if ((reg < 0xa0) && (reg >= 0) && (val <= 0xffffffff) && (channel_id >= 0) && (channel_id <= 3) ) 530 if (reg < 0xa0 && val <= 0xffffffff && channel_id <= 3)
531 snd_ptr_write(emu, iobase, reg, channel_id, val); 531 snd_ptr_write(emu, iobase, reg, channel_id, val);
532 } 532 }
533} 533}
diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c
index c1a5aa15af8f..5ef7080e14d0 100644
--- a/sound/pci/emu10k1/io.c
+++ b/sound/pci/emu10k1/io.c
@@ -256,7 +256,7 @@ int snd_emu1010_fpga_write(struct snd_emu10k1 * emu, u32 reg, u32 value)
256 if (reg > 0x3f) 256 if (reg > 0x3f)
257 return 1; 257 return 1;
258 reg += 0x40; /* 0x40 upwards are registers. */ 258 reg += 0x40; /* 0x40 upwards are registers. */
259 if (value < 0 || value > 0x3f) /* 0 to 0x3f are values */ 259 if (value > 0x3f) /* 0 to 0x3f are values */
260 return 1; 260 return 1;
261 spin_lock_irqsave(&emu->emu_lock, flags); 261 spin_lock_irqsave(&emu->emu_lock, flags);
262 outl(reg, emu->port + A_IOCFG); 262 outl(reg, emu->port + A_IOCFG);
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 820318ee62c1..fb83e1ffa5cb 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1387,7 +1387,7 @@ ES1938_DOUBLE_TLV("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0,
1387 db_scale_line), 1387 db_scale_line),
1388ES1938_DOUBLE_TLV("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0, 1388ES1938_DOUBLE_TLV("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0,
1389 db_scale_capture), 1389 db_scale_capture),
1390ES1938_SINGLE("PC Speaker Volume", 0, 0x3c, 0, 7, 0), 1390ES1938_SINGLE("Beep Volume", 0, 0x3c, 0, 7, 0),
1391ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0), 1391ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
1392ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), 1392ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
1393{ 1393{
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 780e1a72114a..85c81feb10cf 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -197,8 +197,8 @@ static struct snd_kcontrol_new cmi9880_basic_mixer[] = {
197 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT), 197 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0, HDA_INPUT),
198 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT), 198 HDA_CODEC_MUTE("Capture Switch", 0x08, 0, HDA_INPUT),
199 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT), 199 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0, HDA_INPUT),
200 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x23, 0, HDA_OUTPUT), 200 HDA_CODEC_VOLUME("Beep Playback Volume", 0x23, 0, HDA_OUTPUT),
201 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x23, 0, HDA_OUTPUT), 201 HDA_CODEC_MUTE("Beep Playback Switch", 0x23, 0, HDA_OUTPUT),
202 { } /* end */ 202 { } /* end */
203}; 203};
204 204
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 5d7b882bd68c..49de107db16b 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -7337,8 +7337,8 @@ static struct snd_kcontrol_new alc882_macpro_mixer[] = {
7337 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT), 7337 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
7338 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT), 7338 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
7339 /* FIXME: this looks suspicious... 7339 /* FIXME: this looks suspicious...
7340 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT), 7340 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x02, HDA_INPUT),
7341 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT), 7341 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x02, HDA_INPUT),
7342 */ 7342 */
7343 { } /* end */ 7343 { } /* end */
7344}; 7344};
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 2d3e2e415eb0..8d65d2b25234 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -3226,7 +3226,7 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3226 /* check for mute support for the the amp */ 3226 /* check for mute support for the the amp */
3227 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) { 3227 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3228 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, 3228 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3229 "PC Beep Playback Switch", 3229 "Beep Playback Switch",
3230 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3230 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3231 if (err < 0) 3231 if (err < 0)
3232 return err; 3232 return err;
@@ -3235,7 +3235,7 @@ static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3235 /* check to see if there is volume support for the amp */ 3235 /* check to see if there is volume support for the amp */
3236 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) { 3236 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3237 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, 3237 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3238 "PC Beep Playback Volume", 3238 "Beep Playback Volume",
3239 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT)); 3239 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3240 if (err < 0) 3240 if (err < 0)
3241 return err; 3241 return err;
@@ -3276,7 +3276,7 @@ static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3276static int stac92xx_beep_switch_ctl(struct hda_codec *codec) 3276static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3277{ 3277{
3278 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl, 3278 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3279 0, "PC Beep Playback Switch", 0); 3279 0, "Beep Playback Switch", 0);
3280} 3280}
3281#endif 3281#endif
3282 3282
diff --git a/sound/pci/ice1712/amp.c b/sound/pci/ice1712/amp.c
index 37564300b50d..6da21a2bcade 100644
--- a/sound/pci/ice1712/amp.c
+++ b/sound/pci/ice1712/amp.c
@@ -52,11 +52,13 @@ static int __devinit snd_vt1724_amp_init(struct snd_ice1712 *ice)
52 52
53 /* only use basic functionality for now */ 53 /* only use basic functionality for now */
54 54
55 ice->num_total_dacs = 2; /* only PSDOUT0 is connected */ 55 /* VT1616 6ch codec connected to PSDOUT0 using packed mode */
56 ice->num_total_dacs = 6;
56 ice->num_total_adcs = 2; 57 ice->num_total_adcs = 2;
57 58
58 /* Chaintech AV-710 has another codecs, which need initialization */ 59 /* Chaintech AV-710 has another WM8728 codec connected to PSDOUT4
59 /* initialize WM8728 codec */ 60 (shared with the SPDIF output). Mixer control for this codec
61 is not yet supported. */
60 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AV710) { 62 if (ice->eeprom.subvendor == VT1724_SUBDEVICE_AV710) {
61 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2) 63 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
62 wm_put(ice, wm_inits[i], wm_inits[i+1]); 64 wm_put(ice, wm_inits[i], wm_inits[i+1]);
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index cecf1ffeeaaa..d74033a2cfbe 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2259,7 +2259,7 @@ static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol,
2259} 2259}
2260 2260
2261static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = { 2261static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = {
2262 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2262 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2263 .name = "Multi Track Peak", 2263 .name = "Multi Track Peak",
2264 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 2264 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2265 .info = snd_ice1712_pro_peak_info, 2265 .info = snd_ice1712_pro_peak_info,
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index af6e00148621..10fc92c05574 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -648,7 +648,7 @@ static int snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
648 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) { 648 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
649 /* running? we cannot change the rate now... */ 649 /* running? we cannot change the rate now... */
650 spin_unlock_irqrestore(&ice->reg_lock, flags); 650 spin_unlock_irqrestore(&ice->reg_lock, flags);
651 return -EBUSY; 651 return ((rate == ice->cur_rate) && !force) ? 0 : -EBUSY;
652 } 652 }
653 if (!force && is_pro_rate_locked(ice)) { 653 if (!force && is_pro_rate_locked(ice)) {
654 spin_unlock_irqrestore(&ice->reg_lock, flags); 654 spin_unlock_irqrestore(&ice->reg_lock, flags);
@@ -1294,7 +1294,7 @@ static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 *ice, int device)
1294 1294
1295 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 1295 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1296 snd_dma_pci_data(ice->pci), 1296 snd_dma_pci_data(ice->pci),
1297 64*1024, 64*1024); 1297 256*1024, 256*1024);
1298 1298
1299 ice->pcm = pcm; 1299 ice->pcm = pcm;
1300 1300
@@ -1408,7 +1408,7 @@ static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 *ice, int device)
1408 1408
1409 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 1409 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
1410 snd_dma_pci_data(ice->pci), 1410 snd_dma_pci_data(ice->pci),
1411 64*1024, 64*1024); 1411 256*1024, 256*1024);
1412 1412
1413 ice->pcm_ds = pcm; 1413 ice->pcm_ds = pcm;
1414 1414
@@ -2110,7 +2110,7 @@ static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol,
2110} 2110}
2111 2111
2112static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = { 2112static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = {
2113 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 2113 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2114 .name = "Multi Track Peak", 2114 .name = "Multi Track Peak",
2115 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, 2115 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
2116 .info = snd_vt1724_pro_peak_info, 2116 .info = snd_vt1724_pro_peak_info,
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 171ada535209..754867ed4785 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -1954,6 +1954,18 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1954 .name = "Sony S1XP", 1954 .name = "Sony S1XP",
1955 .type = AC97_TUNE_INV_EAPD 1955 .type = AC97_TUNE_INV_EAPD
1956 }, 1956 },
1957 {
1958 .subvendor = 0x104d,
1959 .subdevice = 0x81c0,
1960 .name = "Sony VAIO VGN-T350P", /*AD1981B*/
1961 .type = AC97_TUNE_INV_EAPD
1962 },
1963 {
1964 .subvendor = 0x104d,
1965 .subdevice = 0x81c5,
1966 .name = "Sony VAIO VGN-B1VP", /*AD1981B*/
1967 .type = AC97_TUNE_INV_EAPD
1968 },
1957 { 1969 {
1958 .subvendor = 0x1043, 1970 .subvendor = 0x1043,
1959 .subdevice = 0x80f3, 1971 .subdevice = 0x80f3,
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index acfa4760da49..8a332d2f615c 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -386,6 +386,7 @@ struct via82xx {
386 386
387 struct snd_pcm *pcms[2]; 387 struct snd_pcm *pcms[2];
388 struct snd_rawmidi *rmidi; 388 struct snd_rawmidi *rmidi;
389 struct snd_kcontrol *dxs_controls[4];
389 390
390 struct snd_ac97_bus *ac97_bus; 391 struct snd_ac97_bus *ac97_bus;
391 struct snd_ac97 *ac97; 392 struct snd_ac97 *ac97;
@@ -1216,9 +1217,9 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
1216 1217
1217 1218
1218/* 1219/*
1219 * open callback for playback on via686 and via823x DSX 1220 * open callback for playback on via686
1220 */ 1221 */
1221static int snd_via82xx_playback_open(struct snd_pcm_substream *substream) 1222static int snd_via686_playback_open(struct snd_pcm_substream *substream)
1222{ 1223{
1223 struct via82xx *chip = snd_pcm_substream_chip(substream); 1224 struct via82xx *chip = snd_pcm_substream_chip(substream);
1224 struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number]; 1225 struct viadev *viadev = &chip->devs[chip->playback_devno + substream->number];
@@ -1230,6 +1231,32 @@ static int snd_via82xx_playback_open(struct snd_pcm_substream *substream)
1230} 1231}
1231 1232
1232/* 1233/*
1234 * open callback for playback on via823x DXS
1235 */
1236static int snd_via8233_playback_open(struct snd_pcm_substream *substream)
1237{
1238 struct via82xx *chip = snd_pcm_substream_chip(substream);
1239 struct viadev *viadev;
1240 unsigned int stream;
1241 int err;
1242
1243 viadev = &chip->devs[chip->playback_devno + substream->number];
1244 if ((err = snd_via82xx_pcm_open(chip, viadev, substream)) < 0)
1245 return err;
1246 stream = viadev->reg_offset / 0x10;
1247 if (chip->dxs_controls[stream]) {
1248 chip->playback_volume[stream][0] = 0;
1249 chip->playback_volume[stream][1] = 0;
1250 chip->dxs_controls[stream]->vd[0].access &=
1251 ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1252 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
1253 SNDRV_CTL_EVENT_MASK_INFO,
1254 &chip->dxs_controls[stream]->id);
1255 }
1256 return 0;
1257}
1258
1259/*
1233 * open callback for playback on via823x multi-channel 1260 * open callback for playback on via823x multi-channel
1234 */ 1261 */
1235static int snd_via8233_multi_open(struct snd_pcm_substream *substream) 1262static int snd_via8233_multi_open(struct snd_pcm_substream *substream)
@@ -1302,10 +1329,26 @@ static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream)
1302 return 0; 1329 return 0;
1303} 1330}
1304 1331
1332static int snd_via8233_playback_close(struct snd_pcm_substream *substream)
1333{
1334 struct via82xx *chip = snd_pcm_substream_chip(substream);
1335 struct viadev *viadev = substream->runtime->private_data;
1336 unsigned int stream;
1337
1338 stream = viadev->reg_offset / 0x10;
1339 if (chip->dxs_controls[stream]) {
1340 chip->dxs_controls[stream]->vd[0].access |=
1341 SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1342 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO,
1343 &chip->dxs_controls[stream]->id);
1344 }
1345 return snd_via82xx_pcm_close(substream);
1346}
1347
1305 1348
1306/* via686 playback callbacks */ 1349/* via686 playback callbacks */
1307static struct snd_pcm_ops snd_via686_playback_ops = { 1350static struct snd_pcm_ops snd_via686_playback_ops = {
1308 .open = snd_via82xx_playback_open, 1351 .open = snd_via686_playback_open,
1309 .close = snd_via82xx_pcm_close, 1352 .close = snd_via82xx_pcm_close,
1310 .ioctl = snd_pcm_lib_ioctl, 1353 .ioctl = snd_pcm_lib_ioctl,
1311 .hw_params = snd_via82xx_hw_params, 1354 .hw_params = snd_via82xx_hw_params,
@@ -1331,8 +1374,8 @@ static struct snd_pcm_ops snd_via686_capture_ops = {
1331 1374
1332/* via823x DSX playback callbacks */ 1375/* via823x DSX playback callbacks */
1333static struct snd_pcm_ops snd_via8233_playback_ops = { 1376static struct snd_pcm_ops snd_via8233_playback_ops = {
1334 .open = snd_via82xx_playback_open, 1377 .open = snd_via8233_playback_open,
1335 .close = snd_via82xx_pcm_close, 1378 .close = snd_via8233_playback_close,
1336 .ioctl = snd_pcm_lib_ioctl, 1379 .ioctl = snd_pcm_lib_ioctl,
1337 .hw_params = snd_via82xx_hw_params, 1380 .hw_params = snd_via82xx_hw_params,
1338 .hw_free = snd_via82xx_hw_free, 1381 .hw_free = snd_via82xx_hw_free,
@@ -1626,7 +1669,7 @@ static int snd_via8233_dxs_volume_get(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_value *ucontrol) 1669 struct snd_ctl_elem_value *ucontrol)
1627{ 1670{
1628 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1671 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1629 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id); 1672 unsigned int idx = kcontrol->id.subdevice;
1630 1673
1631 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0]; 1674 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0];
1632 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1]; 1675 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1];
@@ -1646,7 +1689,7 @@ static int snd_via8233_dxs_volume_put(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol) 1689 struct snd_ctl_elem_value *ucontrol)
1647{ 1690{
1648 struct via82xx *chip = snd_kcontrol_chip(kcontrol); 1691 struct via82xx *chip = snd_kcontrol_chip(kcontrol);
1649 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id); 1692 unsigned int idx = kcontrol->id.subdevice;
1650 unsigned long port = chip->port + 0x10 * idx; 1693 unsigned long port = chip->port + 0x10 * idx;
1651 unsigned char val; 1694 unsigned char val;
1652 int i, change = 0; 1695 int i, change = 0;
@@ -1705,11 +1748,13 @@ static struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control __devinitdata =
1705}; 1748};
1706 1749
1707static struct snd_kcontrol_new snd_via8233_dxs_volume_control __devinitdata = { 1750static struct snd_kcontrol_new snd_via8233_dxs_volume_control __devinitdata = {
1708 .name = "VIA DXS Playback Volume", 1751 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1709 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1752 .device = 0,
1710 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 1753 /* .subdevice set later */
1711 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 1754 .name = "PCM Playback Volume",
1712 .count = 4, 1755 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
1756 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
1757 SNDRV_CTL_ELEM_ACCESS_INACTIVE,
1713 .info = snd_via8233_dxs_volume_info, 1758 .info = snd_via8233_dxs_volume_info,
1714 .get = snd_via8233_dxs_volume_get, 1759 .get = snd_via8233_dxs_volume_get,
1715 .put = snd_via8233_dxs_volume_put, 1760 .put = snd_via8233_dxs_volume_put,
@@ -1936,10 +1981,19 @@ static int __devinit snd_via8233_init_misc(struct via82xx *chip)
1936 } 1981 }
1937 else /* Using DXS when PCM emulation is enabled is really weird */ 1982 else /* Using DXS when PCM emulation is enabled is really weird */
1938 { 1983 {
1939 /* Standalone DXS controls */ 1984 for (i = 0; i < 4; ++i) {
1940 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip)); 1985 struct snd_kcontrol *kctl;
1941 if (err < 0) 1986
1942 return err; 1987 kctl = snd_ctl_new1(
1988 &snd_via8233_dxs_volume_control, chip);
1989 if (!kctl)
1990 return -ENOMEM;
1991 kctl->id.subdevice = i;
1992 err = snd_ctl_add(chip->card, kctl);
1993 if (err < 0)
1994 return err;
1995 chip->dxs_controls[i] = kctl;
1996 }
1943 } 1997 }
1944 } 1998 }
1945 /* select spdif data slot 10/11 */ 1999 /* select spdif data slot 10/11 */
diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c
index 2cc0eda4f20e..2e156467b814 100644
--- a/sound/ppc/awacs.c
+++ b/sound/ppc/awacs.c
@@ -479,7 +479,7 @@ static int snd_pmac_awacs_put_master_amp(struct snd_kcontrol *kcontrol,
479 479
480static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __devinitdata = { 480static struct snd_kcontrol_new snd_pmac_awacs_amp_vol[] __devinitdata = {
481 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 481 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "PC Speaker Playback Volume", 482 .name = "Speaker Playback Volume",
483 .info = snd_pmac_awacs_info_volume_amp, 483 .info = snd_pmac_awacs_info_volume_amp,
484 .get = snd_pmac_awacs_get_volume_amp, 484 .get = snd_pmac_awacs_get_volume_amp,
485 .put = snd_pmac_awacs_put_volume_amp, 485 .put = snd_pmac_awacs_put_volume_amp,
@@ -525,7 +525,7 @@ static struct snd_kcontrol_new snd_pmac_awacs_amp_hp_sw __devinitdata = {
525 525
526static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __devinitdata = { 526static struct snd_kcontrol_new snd_pmac_awacs_amp_spk_sw __devinitdata = {
527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 527 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
528 .name = "PC Speaker Playback Switch", 528 .name = "Speaker Playback Switch",
529 .info = snd_pmac_boolean_stereo_info, 529 .info = snd_pmac_boolean_stereo_info,
530 .get = snd_pmac_awacs_get_switch_amp, 530 .get = snd_pmac_awacs_get_switch_amp,
531 .put = snd_pmac_awacs_put_switch_amp, 531 .put = snd_pmac_awacs_put_switch_amp,
@@ -696,17 +696,17 @@ static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __devinitdata
696}; 696};
697 697
698static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __devinitdata = { 698static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __devinitdata = {
699 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1), 699 AWACS_VOLUME("Speaker Playback Volume", 4, 6, 1),
700}; 700};
701 701
702static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __devinitdata = 702static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __devinitdata =
703AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1); 703AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
704 704
705static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __devinitdata = 705static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac1 __devinitdata =
706AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 1); 706AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 1);
707 707
708static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __devinitdata = 708static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac2 __devinitdata =
709AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0); 709AWACS_SWITCH("Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
710 710
711 711
712/* 712/*
diff --git a/sound/ppc/burgundy.c b/sound/ppc/burgundy.c
index 16ed240e423c..0accfe49735b 100644
--- a/sound/ppc/burgundy.c
+++ b/sound/ppc/burgundy.c
@@ -505,7 +505,7 @@ static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] __devinitdata = {
505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0), 505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0),
506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0, 506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0), 507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
508 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0, 508 BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1), 509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0, 510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1), 511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1),
@@ -527,7 +527,7 @@ static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] __devinitdata = {
527 MASK_ADDR_BURGUNDY_VOLMIC, 16), 527 MASK_ADDR_BURGUNDY_VOLMIC, 16),
528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0, 528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0), 529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
530 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0, 530 BURGUNDY_VOLUME_B("Speaker Playback Volume", 0,
531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1), 531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1),
532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0, 532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1), 533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
@@ -549,11 +549,11 @@ BURGUNDY_SWITCH_B("Master Playback Switch", 0,
549 BURGUNDY_OUTPUT_INTERN 549 BURGUNDY_OUTPUT_INTERN
550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
551static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __devinitdata = 551static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __devinitdata =
552BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0, 552BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
555static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __devinitdata = 555static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __devinitdata =
556BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0, 556BURGUNDY_SWITCH_B("Speaker Playback Switch", 0,
557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
558 BURGUNDY_OUTPUT_INTERN, 0, 0); 558 BURGUNDY_OUTPUT_INTERN, 0, 0);
559static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __devinitdata = 559static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __devinitdata =
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
index 835fa19ed461..d06f780bd7e8 100644
--- a/sound/ppc/keywest.c
+++ b/sound/ppc/keywest.c
@@ -59,6 +59,18 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
59 strlcpy(info.type, "keywest", I2C_NAME_SIZE); 59 strlcpy(info.type, "keywest", I2C_NAME_SIZE);
60 info.addr = keywest_ctx->addr; 60 info.addr = keywest_ctx->addr;
61 keywest_ctx->client = i2c_new_device(adapter, &info); 61 keywest_ctx->client = i2c_new_device(adapter, &info);
62 if (!keywest_ctx->client)
63 return -ENODEV;
64 /*
65 * We know the driver is already loaded, so the device should be
66 * already bound. If not it means binding failed, and then there
67 * is no point in keeping the device instantiated.
68 */
69 if (!keywest_ctx->client->driver) {
70 i2c_unregister_device(keywest_ctx->client);
71 keywest_ctx->client = NULL;
72 return -ENODEV;
73 }
62 74
63 /* 75 /*
64 * Let i2c-core delete that device on driver removal. 76 * Let i2c-core delete that device on driver removal.
@@ -86,7 +98,7 @@ static const struct i2c_device_id keywest_i2c_id[] = {
86 { } 98 { }
87}; 99};
88 100
89struct i2c_driver keywest_driver = { 101static struct i2c_driver keywest_driver = {
90 .driver = { 102 .driver = {
91 .name = "PMac Keywest Audio", 103 .name = "PMac Keywest Audio",
92 }, 104 },
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index 08e584d1453a..789f44f4ac78 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -905,7 +905,7 @@ static struct snd_kcontrol_new tumbler_hp_sw __devinitdata = {
905}; 905};
906static struct snd_kcontrol_new tumbler_speaker_sw __devinitdata = { 906static struct snd_kcontrol_new tumbler_speaker_sw __devinitdata = {
907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
908 .name = "PC Speaker Playback Switch", 908 .name = "Speaker Playback Switch",
909 .info = snd_pmac_boolean_mono_info, 909 .info = snd_pmac_boolean_mono_info,
910 .get = tumbler_get_mute_switch, 910 .get = tumbler_get_mute_switch,
911 .put = tumbler_put_mute_switch, 911 .put = tumbler_put_mute_switch,
diff --git a/sound/sh/Kconfig b/sound/sh/Kconfig
index aed0f90c3919..61139f3c1614 100644
--- a/sound/sh/Kconfig
+++ b/sound/sh/Kconfig
@@ -19,5 +19,13 @@ config SND_AICA
19 help 19 help
20 ALSA Sound driver for the SEGA Dreamcast console. 20 ALSA Sound driver for the SEGA Dreamcast console.
21 21
22config SND_SH_DAC_AUDIO
23 tristate "SuperH DAC audio support"
24 depends on SND
25 depends on CPU_SH3 && HIGH_RES_TIMERS
26 select SND_PCM
27 help
28 Say Y here to include support for the on-chip DAC.
29
22endif # SND_SUPERH 30endif # SND_SUPERH
23 31
diff --git a/sound/sh/Makefile b/sound/sh/Makefile
index 8fdcb6e26f00..7d09b5188cf7 100644
--- a/sound/sh/Makefile
+++ b/sound/sh/Makefile
@@ -3,6 +3,8 @@
3# 3#
4 4
5snd-aica-objs := aica.o 5snd-aica-objs := aica.o
6snd-sh_dac_audio-objs := sh_dac_audio.o
6 7
7# Toplevel Module Dependency 8# Toplevel Module Dependency
8obj-$(CONFIG_SND_AICA) += snd-aica.o 9obj-$(CONFIG_SND_AICA) += snd-aica.o
10obj-$(CONFIG_SND_SH_DAC_AUDIO) += snd-sh_dac_audio.o
diff --git a/sound/sh/sh_dac_audio.c b/sound/sh/sh_dac_audio.c
new file mode 100644
index 000000000000..76d9ad27d91c
--- /dev/null
+++ b/sound/sh/sh_dac_audio.c
@@ -0,0 +1,453 @@
1/*
2 * sh_dac_audio.c - SuperH DAC audio driver for ALSA
3 *
4 * Copyright (c) 2009 by Rafael Ignacio Zurita <rizurita@yahoo.com>
5 *
6 *
7 * Based on sh_dac_audio.c (Copyright (C) 2004, 2005 by Andriy Skulysh)
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <linux/hrtimer.h>
26#include <linux/interrupt.h>
27#include <linux/io.h>
28#include <linux/platform_device.h>
29#include <sound/core.h>
30#include <sound/initval.h>
31#include <sound/pcm.h>
32#include <sound/sh_dac_audio.h>
33#include <asm/clock.h>
34#include <asm/hd64461.h>
35#include <mach/hp6xx.h>
36#include <cpu/dac.h>
37
38MODULE_AUTHOR("Rafael Ignacio Zurita <rizurita@yahoo.com>");
39MODULE_DESCRIPTION("SuperH DAC audio driver");
40MODULE_LICENSE("GPL");
41MODULE_SUPPORTED_DEVICE("{{SuperH DAC audio support}}");
42
43/* Module Parameters */
44static int index = SNDRV_DEFAULT_IDX1;
45static char *id = SNDRV_DEFAULT_STR1;
46module_param(index, int, 0444);
47MODULE_PARM_DESC(index, "Index value for SuperH DAC audio.");
48module_param(id, charp, 0444);
49MODULE_PARM_DESC(id, "ID string for SuperH DAC audio.");
50
51/* main struct */
52struct snd_sh_dac {
53 struct snd_card *card;
54 struct snd_pcm_substream *substream;
55 struct hrtimer hrtimer;
56 ktime_t wakeups_per_second;
57
58 int rate;
59 int empty;
60 char *data_buffer, *buffer_begin, *buffer_end;
61 int processed; /* bytes proccesed, to compare with period_size */
62 int buffer_size;
63 struct dac_audio_pdata *pdata;
64};
65
66
67static void dac_audio_start_timer(struct snd_sh_dac *chip)
68{
69 hrtimer_start(&chip->hrtimer, chip->wakeups_per_second,
70 HRTIMER_MODE_REL);
71}
72
73static void dac_audio_stop_timer(struct snd_sh_dac *chip)
74{
75 hrtimer_cancel(&chip->hrtimer);
76}
77
78static void dac_audio_reset(struct snd_sh_dac *chip)
79{
80 dac_audio_stop_timer(chip);
81 chip->buffer_begin = chip->buffer_end = chip->data_buffer;
82 chip->processed = 0;
83 chip->empty = 1;
84}
85
86static void dac_audio_set_rate(struct snd_sh_dac *chip)
87{
88 chip->wakeups_per_second = ktime_set(0, 1000000000 / chip->rate);
89}
90
91
92/* PCM INTERFACE */
93
94static struct snd_pcm_hardware snd_sh_dac_pcm_hw = {
95 .info = (SNDRV_PCM_INFO_MMAP |
96 SNDRV_PCM_INFO_MMAP_VALID |
97 SNDRV_PCM_INFO_INTERLEAVED |
98 SNDRV_PCM_INFO_HALF_DUPLEX),
99 .formats = SNDRV_PCM_FMTBIT_U8,
100 .rates = SNDRV_PCM_RATE_8000,
101 .rate_min = 8000,
102 .rate_max = 8000,
103 .channels_min = 1,
104 .channels_max = 1,
105 .buffer_bytes_max = (48*1024),
106 .period_bytes_min = 1,
107 .period_bytes_max = (48*1024),
108 .periods_min = 1,
109 .periods_max = 1024,
110};
111
112static int snd_sh_dac_pcm_open(struct snd_pcm_substream *substream)
113{
114 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
115 struct snd_pcm_runtime *runtime = substream->runtime;
116
117 runtime->hw = snd_sh_dac_pcm_hw;
118
119 chip->substream = substream;
120 chip->buffer_begin = chip->buffer_end = chip->data_buffer;
121 chip->processed = 0;
122 chip->empty = 1;
123
124 chip->pdata->start(chip->pdata);
125
126 return 0;
127}
128
129static int snd_sh_dac_pcm_close(struct snd_pcm_substream *substream)
130{
131 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
132
133 chip->substream = NULL;
134
135 dac_audio_stop_timer(chip);
136 chip->pdata->stop(chip->pdata);
137
138 return 0;
139}
140
141static int snd_sh_dac_pcm_hw_params(struct snd_pcm_substream *substream,
142 struct snd_pcm_hw_params *hw_params)
143{
144 return snd_pcm_lib_malloc_pages(substream,
145 params_buffer_bytes(hw_params));
146}
147
148static int snd_sh_dac_pcm_hw_free(struct snd_pcm_substream *substream)
149{
150 return snd_pcm_lib_free_pages(substream);
151}
152
153static int snd_sh_dac_pcm_prepare(struct snd_pcm_substream *substream)
154{
155 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
156 struct snd_pcm_runtime *runtime = chip->substream->runtime;
157
158 chip->buffer_size = runtime->buffer_size;
159 memset(chip->data_buffer, 0, chip->pdata->buffer_size);
160
161 return 0;
162}
163
164static int snd_sh_dac_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
165{
166 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
167
168 switch (cmd) {
169 case SNDRV_PCM_TRIGGER_START:
170 dac_audio_start_timer(chip);
171 break;
172 case SNDRV_PCM_TRIGGER_STOP:
173 chip->buffer_begin = chip->buffer_end = chip->data_buffer;
174 chip->processed = 0;
175 chip->empty = 1;
176 dac_audio_stop_timer(chip);
177 break;
178 default:
179 return -EINVAL;
180 }
181
182 return 0;
183}
184
185static int snd_sh_dac_pcm_copy(struct snd_pcm_substream *substream, int channel,
186 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
187{
188 /* channel is not used (interleaved data) */
189 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
190 struct snd_pcm_runtime *runtime = substream->runtime;
191 ssize_t b_count = frames_to_bytes(runtime , count);
192 ssize_t b_pos = frames_to_bytes(runtime , pos);
193
194 if (count < 0)
195 return -EINVAL;
196
197 if (!count)
198 return 0;
199
200 memcpy_toio(chip->data_buffer + b_pos, src, b_count);
201 chip->buffer_end = chip->data_buffer + b_pos + b_count;
202
203 if (chip->empty) {
204 chip->empty = 0;
205 dac_audio_start_timer(chip);
206 }
207
208 return 0;
209}
210
211static int snd_sh_dac_pcm_silence(struct snd_pcm_substream *substream,
212 int channel, snd_pcm_uframes_t pos,
213 snd_pcm_uframes_t count)
214{
215 /* channel is not used (interleaved data) */
216 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
217 struct snd_pcm_runtime *runtime = substream->runtime;
218 ssize_t b_count = frames_to_bytes(runtime , count);
219 ssize_t b_pos = frames_to_bytes(runtime , pos);
220
221 if (count < 0)
222 return -EINVAL;
223
224 if (!count)
225 return 0;
226
227 memset_io(chip->data_buffer + b_pos, 0, b_count);
228 chip->buffer_end = chip->data_buffer + b_pos + b_count;
229
230 if (chip->empty) {
231 chip->empty = 0;
232 dac_audio_start_timer(chip);
233 }
234
235 return 0;
236}
237
238static
239snd_pcm_uframes_t snd_sh_dac_pcm_pointer(struct snd_pcm_substream *substream)
240{
241 struct snd_sh_dac *chip = snd_pcm_substream_chip(substream);
242 int pointer = chip->buffer_begin - chip->data_buffer;
243
244 return pointer;
245}
246
247/* pcm ops */
248static struct snd_pcm_ops snd_sh_dac_pcm_ops = {
249 .open = snd_sh_dac_pcm_open,
250 .close = snd_sh_dac_pcm_close,
251 .ioctl = snd_pcm_lib_ioctl,
252 .hw_params = snd_sh_dac_pcm_hw_params,
253 .hw_free = snd_sh_dac_pcm_hw_free,
254 .prepare = snd_sh_dac_pcm_prepare,
255 .trigger = snd_sh_dac_pcm_trigger,
256 .pointer = snd_sh_dac_pcm_pointer,
257 .copy = snd_sh_dac_pcm_copy,
258 .silence = snd_sh_dac_pcm_silence,
259 .mmap = snd_pcm_lib_mmap_iomem,
260};
261
262static int __devinit snd_sh_dac_pcm(struct snd_sh_dac *chip, int device)
263{
264 int err;
265 struct snd_pcm *pcm;
266
267 /* device should be always 0 for us */
268 err = snd_pcm_new(chip->card, "SH_DAC PCM", device, 1, 0, &pcm);
269 if (err < 0)
270 return err;
271
272 pcm->private_data = chip;
273 strcpy(pcm->name, "SH_DAC PCM");
274 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_sh_dac_pcm_ops);
275
276 /* buffer size=48K */
277 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
278 snd_dma_continuous_data(GFP_KERNEL),
279 48 * 1024,
280 48 * 1024);
281
282 return 0;
283}
284/* END OF PCM INTERFACE */
285
286
287/* driver .remove -- destructor */
288static int snd_sh_dac_remove(struct platform_device *devptr)
289{
290 snd_card_free(platform_get_drvdata(devptr));
291 platform_set_drvdata(devptr, NULL);
292
293 return 0;
294}
295
296/* free -- it has been defined by create */
297static int snd_sh_dac_free(struct snd_sh_dac *chip)
298{
299 /* release the data */
300 kfree(chip->data_buffer);
301 kfree(chip);
302
303 return 0;
304}
305
306static int snd_sh_dac_dev_free(struct snd_device *device)
307{
308 struct snd_sh_dac *chip = device->device_data;
309
310 return snd_sh_dac_free(chip);
311}
312
313static enum hrtimer_restart sh_dac_audio_timer(struct hrtimer *handle)
314{
315 struct snd_sh_dac *chip = container_of(handle, struct snd_sh_dac,
316 hrtimer);
317 struct snd_pcm_runtime *runtime = chip->substream->runtime;
318 ssize_t b_ps = frames_to_bytes(runtime, runtime->period_size);
319
320 if (!chip->empty) {
321 sh_dac_output(*chip->buffer_begin, chip->pdata->channel);
322 chip->buffer_begin++;
323
324 chip->processed++;
325 if (chip->processed >= b_ps) {
326 chip->processed -= b_ps;
327 snd_pcm_period_elapsed(chip->substream);
328 }
329
330 if (chip->buffer_begin == (chip->data_buffer +
331 chip->buffer_size - 1))
332 chip->buffer_begin = chip->data_buffer;
333
334 if (chip->buffer_begin == chip->buffer_end)
335 chip->empty = 1;
336
337 }
338
339 if (!chip->empty)
340 hrtimer_start(&chip->hrtimer, chip->wakeups_per_second,
341 HRTIMER_MODE_REL);
342
343 return HRTIMER_NORESTART;
344}
345
346/* create -- chip-specific constructor for the cards components */
347static int __devinit snd_sh_dac_create(struct snd_card *card,
348 struct platform_device *devptr,
349 struct snd_sh_dac **rchip)
350{
351 struct snd_sh_dac *chip;
352 int err;
353
354 static struct snd_device_ops ops = {
355 .dev_free = snd_sh_dac_dev_free,
356 };
357
358 *rchip = NULL;
359
360 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
361 if (chip == NULL)
362 return -ENOMEM;
363
364 chip->card = card;
365
366 hrtimer_init(&chip->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
367 chip->hrtimer.function = sh_dac_audio_timer;
368
369 dac_audio_reset(chip);
370 chip->rate = 8000;
371 dac_audio_set_rate(chip);
372
373 chip->pdata = devptr->dev.platform_data;
374
375 chip->data_buffer = kmalloc(chip->pdata->buffer_size, GFP_KERNEL);
376 if (chip->data_buffer == NULL) {
377 kfree(chip);
378 return -ENOMEM;
379 }
380
381 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
382 if (err < 0) {
383 snd_sh_dac_free(chip);
384 return err;
385 }
386
387 *rchip = chip;
388
389 return 0;
390}
391
392/* driver .probe -- constructor */
393static int __devinit snd_sh_dac_probe(struct platform_device *devptr)
394{
395 struct snd_sh_dac *chip;
396 struct snd_card *card;
397 int err;
398
399 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
400 if (err < 0) {
401 snd_printk(KERN_ERR "cannot allocate the card\n");
402 return err;
403 }
404
405 err = snd_sh_dac_create(card, devptr, &chip);
406 if (err < 0)
407 goto probe_error;
408
409 err = snd_sh_dac_pcm(chip, 0);
410 if (err < 0)
411 goto probe_error;
412
413 strcpy(card->driver, "snd_sh_dac");
414 strcpy(card->shortname, "SuperH DAC audio driver");
415 printk(KERN_INFO "%s %s", card->longname, card->shortname);
416
417 err = snd_card_register(card);
418 if (err < 0)
419 goto probe_error;
420
421 snd_printk("ALSA driver for SuperH DAC audio");
422
423 platform_set_drvdata(devptr, card);
424 return 0;
425
426probe_error:
427 snd_card_free(card);
428 return err;
429}
430
431/*
432 * "driver" definition
433 */
434static struct platform_driver driver = {
435 .probe = snd_sh_dac_probe,
436 .remove = snd_sh_dac_remove,
437 .driver = {
438 .name = "dac_audio",
439 },
440};
441
442static int __init sh_dac_init(void)
443{
444 return platform_driver_register(&driver);
445}
446
447static void __exit sh_dac_exit(void)
448{
449 platform_driver_unregister(&driver);
450}
451
452module_init(sh_dac_init);
453module_exit(sh_dac_exit);
diff --git a/sound/soc/blackfin/Kconfig b/sound/soc/blackfin/Kconfig
index ac927ffdc961..97f1a251e446 100644
--- a/sound/soc/blackfin/Kconfig
+++ b/sound/soc/blackfin/Kconfig
@@ -7,15 +7,6 @@ config SND_BF5XX_I2S
7 mode (supports single stereo In/Out). 7 mode (supports single stereo In/Out).
8 You will also need to select the audio interfaces to support below. 8 You will also need to select the audio interfaces to support below.
9 9
10config SND_BF5XX_TDM
11 tristate "SoC I2S(TDM mode) Audio for the ADI BF5xx chip"
12 depends on (BLACKFIN && SND_SOC)
13 help
14 Say Y or M if you want to add support for codecs attached to
15 the Blackfin SPORT (synchronous serial ports) interface in TDM
16 mode.
17 You will also need to select the audio interfaces to support below.
18
19config SND_BF5XX_SOC_SSM2602 10config SND_BF5XX_SOC_SSM2602
20 tristate "SoC SSM2602 Audio support for BF52x ezkit" 11 tristate "SoC SSM2602 Audio support for BF52x ezkit"
21 depends on SND_BF5XX_I2S 12 depends on SND_BF5XX_I2S
@@ -41,6 +32,31 @@ config SND_BFIN_AD73311_SE
41 Enter the GPIO used to control AD73311's SE pin. Acceptable 32 Enter the GPIO used to control AD73311's SE pin. Acceptable
42 values are 0 to 7 33 values are 0 to 7
43 34
35config SND_BF5XX_TDM
36 tristate "SoC I2S(TDM mode) Audio for the ADI BF5xx chip"
37 depends on (BLACKFIN && SND_SOC)
38 help
39 Say Y or M if you want to add support for codecs attached to
40 the Blackfin SPORT (synchronous serial ports) interface in TDM
41 mode.
42 You will also need to select the audio interfaces to support below.
43
44config SND_BF5XX_SOC_AD1836
45 tristate "SoC AD1836 Audio support for BF5xx"
46 depends on SND_BF5XX_TDM
47 select SND_BF5XX_SOC_TDM
48 select SND_SOC_AD1836
49 help
50 Say Y if you want to add support for SoC audio on BF5xx STAMP/EZKIT.
51
52config SND_BF5XX_SOC_AD1938
53 tristate "SoC AD1938 Audio support for Blackfin"
54 depends on SND_BF5XX_TDM
55 select SND_BF5XX_SOC_TDM
56 select SND_SOC_AD1938
57 help
58 Say Y if you want to add support for AD1938 codec on Blackfin.
59
44config SND_BF5XX_AC97 60config SND_BF5XX_AC97
45 tristate "SoC AC97 Audio for the ADI BF5xx chip" 61 tristate "SoC AC97 Audio for the ADI BF5xx chip"
46 depends on BLACKFIN 62 depends on BLACKFIN
@@ -71,6 +87,30 @@ config SND_BF5XX_MULTICHAN_SUPPORT
71 Say y if you want AC97 driver to support up to 5.1 channel audio. 87 Say y if you want AC97 driver to support up to 5.1 channel audio.
72 this mode will consume much more memory for DMA. 88 this mode will consume much more memory for DMA.
73 89
90config SND_BF5XX_HAVE_COLD_RESET
91 bool "BOARD has COLD Reset GPIO"
92 depends on SND_BF5XX_AC97
93 default y if BFIN548_EZKIT
94 default n if !BFIN548_EZKIT
95
96config SND_BF5XX_RESET_GPIO_NUM
97 int "Set a GPIO for cold reset"
98 depends on SND_BF5XX_HAVE_COLD_RESET
99 range 0 159
100 default 19 if BFIN548_EZKIT
101 default 5 if BFIN537_STAMP
102 default 0
103 help
104 Set the correct GPIO for RESET the sound chip.
105
106config SND_BF5XX_SOC_AD1980
107 tristate "SoC AD1980/1 Audio support for BF5xx"
108 depends on SND_BF5XX_AC97
109 select SND_BF5XX_SOC_AC97
110 select SND_SOC_AD1980
111 help
112 Say Y if you want to add support for SoC audio on BF5xx STAMP/EZKIT.
113
74config SND_BF5XX_SOC_SPORT 114config SND_BF5XX_SOC_SPORT
75 tristate 115 tristate
76 116
@@ -88,30 +128,6 @@ config SND_BF5XX_SOC_AC97
88 select SND_SOC_AC97_BUS 128 select SND_SOC_AC97_BUS
89 select SND_BF5XX_SOC_SPORT 129 select SND_BF5XX_SOC_SPORT
90 130
91config SND_BF5XX_SOC_AD1836
92 tristate "SoC AD1836 Audio support for BF5xx"
93 depends on SND_BF5XX_TDM
94 select SND_BF5XX_SOC_TDM
95 select SND_SOC_AD1836
96 help
97 Say Y if you want to add support for SoC audio on BF5xx STAMP/EZKIT.
98
99config SND_BF5XX_SOC_AD1980
100 tristate "SoC AD1980/1 Audio support for BF5xx"
101 depends on SND_BF5XX_AC97
102 select SND_BF5XX_SOC_AC97
103 select SND_SOC_AD1980
104 help
105 Say Y if you want to add support for SoC audio on BF5xx STAMP/EZKIT.
106
107config SND_BF5XX_SOC_AD1938
108 tristate "SoC AD1938 Audio support for Blackfin"
109 depends on SND_BF5XX_TDM
110 select SND_BF5XX_SOC_TDM
111 select SND_SOC_AD1938
112 help
113 Say Y if you want to add support for AD1938 codec on Blackfin.
114
115config SND_BF5XX_SPORT_NUM 131config SND_BF5XX_SPORT_NUM
116 int "Set a SPORT for Sound chip" 132 int "Set a SPORT for Sound chip"
117 depends on (SND_BF5XX_I2S || SND_BF5XX_AC97 || SND_BF5XX_TDM) 133 depends on (SND_BF5XX_I2S || SND_BF5XX_AC97 || SND_BF5XX_TDM)
@@ -120,19 +136,3 @@ config SND_BF5XX_SPORT_NUM
120 default 0 136 default 0
121 help 137 help
122 Set the correct SPORT for sound chip. 138 Set the correct SPORT for sound chip.
123
124config SND_BF5XX_HAVE_COLD_RESET
125 bool "BOARD has COLD Reset GPIO"
126 depends on SND_BF5XX_AC97
127 default y if BFIN548_EZKIT
128 default n if !BFIN548_EZKIT
129
130config SND_BF5XX_RESET_GPIO_NUM
131 int "Set a GPIO for cold reset"
132 depends on SND_BF5XX_HAVE_COLD_RESET
133 range 0 159
134 default 19 if BFIN548_EZKIT
135 default 5 if BFIN537_STAMP
136 default 0
137 help
138 Set the correct GPIO for RESET the sound chip.
diff --git a/sound/soc/blackfin/bf5xx-i2s.c b/sound/soc/blackfin/bf5xx-i2s.c
index 1e9d161c76c4..084b68884ada 100644
--- a/sound/soc/blackfin/bf5xx-i2s.c
+++ b/sound/soc/blackfin/bf5xx-i2s.c
@@ -77,12 +77,12 @@ static struct sport_param sport_params[2] = {
77 * TFS. When Port G is selected and EMAC then there is a conflict between 77 * TFS. When Port G is selected and EMAC then there is a conflict between
78 * the PHY interrupt line and TFS. Current settings prevent the conflict 78 * the PHY interrupt line and TFS. Current settings prevent the conflict
79 * by ignoring the TFS pin when Port G is selected. This allows both 79 * by ignoring the TFS pin when Port G is selected. This allows both
80 * ssm2602 using Port G and EMAC concurrently. 80 * codecs and EMAC using Port G concurrently.
81 */ 81 */
82#ifdef CONFIG_BF527_SPORT0_PORTF 82#ifdef CONFIG_BF527_SPORT0_PORTG
83#define LOCAL_SPORT0_TFS (P_SPORT0_TFS)
84#else
85#define LOCAL_SPORT0_TFS (0) 83#define LOCAL_SPORT0_TFS (0)
84#else
85#define LOCAL_SPORT0_TFS (P_SPORT0_TFS)
86#endif 86#endif
87 87
88static u16 sport_req[][7] = { {P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS, 88static u16 sport_req[][7] = { {P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
diff --git a/sound/soc/blackfin/bf5xx-tdm.c b/sound/soc/blackfin/bf5xx-tdm.c
index 3096badf09a5..ff546e91a22e 100644
--- a/sound/soc/blackfin/bf5xx-tdm.c
+++ b/sound/soc/blackfin/bf5xx-tdm.c
@@ -78,12 +78,12 @@ static struct sport_param sport_params[2] = {
78 * TFS. When Port G is selected and EMAC then there is a conflict between 78 * TFS. When Port G is selected and EMAC then there is a conflict between
79 * the PHY interrupt line and TFS. Current settings prevent the conflict 79 * the PHY interrupt line and TFS. Current settings prevent the conflict
80 * by ignoring the TFS pin when Port G is selected. This allows both 80 * by ignoring the TFS pin when Port G is selected. This allows both
81 * ssm2602 using Port G and EMAC concurrently. 81 * codecs and EMAC using Port G concurrently.
82 */ 82 */
83#ifdef CONFIG_BF527_SPORT0_PORTF 83#ifdef CONFIG_BF527_SPORT0_PORTG
84#define LOCAL_SPORT0_TFS (P_SPORT0_TFS)
85#else
86#define LOCAL_SPORT0_TFS (0) 84#define LOCAL_SPORT0_TFS (0)
85#else
86#define LOCAL_SPORT0_TFS (P_SPORT0_TFS)
87#endif 87#endif
88 88
89static u16 sport_req[][7] = { {P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS, 89static u16 sport_req[][7] = { {P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS,
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index 0b8dcb5cd729..35606ae60868 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -85,7 +85,7 @@ static int tlv320aic23_write(struct snd_soc_codec *codec, unsigned int reg,
85 * of data into val 85 * of data into val
86 */ 86 */
87 87
88 if ((reg < 0 || reg > 9) && (reg != 15)) { 88 if (reg > 9 && reg != 15) {
89 printk(KERN_WARNING "%s Invalid register R%u\n", __func__, reg); 89 printk(KERN_WARNING "%s Invalid register R%u\n", __func__, reg);
90 return -1; 90 return -1;
91 } 91 }
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index 3ff0373dff89..593d5b9c9f03 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -579,7 +579,7 @@ static const struct snd_kcontrol_new wm8350_left_capt_mixer_controls[] = {
579 SOC_DAPM_SINGLE_TLV("L3 Capture Volume", 579 SOC_DAPM_SINGLE_TLV("L3 Capture Volume",
580 WM8350_INPUT_MIXER_VOLUME_L, 9, 7, 0, out_mix_tlv), 580 WM8350_INPUT_MIXER_VOLUME_L, 9, 7, 0, out_mix_tlv),
581 SOC_DAPM_SINGLE("PGA Capture Switch", 581 SOC_DAPM_SINGLE("PGA Capture Switch",
582 WM8350_LEFT_INPUT_VOLUME, 14, 1, 0), 582 WM8350_LEFT_INPUT_VOLUME, 14, 1, 1),
583}; 583};
584 584
585/* Right Input Mixer */ 585/* Right Input Mixer */
@@ -589,7 +589,7 @@ static const struct snd_kcontrol_new wm8350_right_capt_mixer_controls[] = {
589 SOC_DAPM_SINGLE_TLV("L3 Capture Volume", 589 SOC_DAPM_SINGLE_TLV("L3 Capture Volume",
590 WM8350_INPUT_MIXER_VOLUME_R, 13, 7, 0, out_mix_tlv), 590 WM8350_INPUT_MIXER_VOLUME_R, 13, 7, 0, out_mix_tlv),
591 SOC_DAPM_SINGLE("PGA Capture Switch", 591 SOC_DAPM_SINGLE("PGA Capture Switch",
592 WM8350_RIGHT_INPUT_VOLUME, 14, 1, 0), 592 WM8350_RIGHT_INPUT_VOLUME, 14, 1, 1),
593}; 593};
594 594
595/* Left Mic Mixer */ 595/* Left Mic Mixer */
diff --git a/sound/soc/codecs/wm8940.c b/sound/soc/codecs/wm8940.c
index da97aae475a2..1ef2454c5205 100644
--- a/sound/soc/codecs/wm8940.c
+++ b/sound/soc/codecs/wm8940.c
@@ -790,7 +790,7 @@ static int wm8940_register(struct wm8940_priv *wm8940,
790 codec->reg_cache = &wm8940->reg_cache; 790 codec->reg_cache = &wm8940->reg_cache;
791 791
792 ret = snd_soc_codec_set_cache_io(codec, 8, 16, control); 792 ret = snd_soc_codec_set_cache_io(codec, 8, 16, control);
793 if (ret == 0) { 793 if (ret < 0) {
794 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); 794 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
795 return ret; 795 return ret;
796 } 796 }
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index abed37acf787..60e360b10468 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -165,9 +165,9 @@ SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
165SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 165SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
166SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1), 166SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1),
167 167
168SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1), 168SOC_SINGLE("Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1),
169SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1), 169SOC_SINGLE("Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1),
170SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1), 170SOC_SINGLE("Beep Playback Mono Volume", AC97_AUX, 4, 7, 1),
171 171
172SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1), 172SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1),
173SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1), 173SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
@@ -266,7 +266,7 @@ static int mixer_event(struct snd_soc_dapm_widget *w,
266 266
267/* Left Headphone Mixers */ 267/* Left Headphone Mixers */
268static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = { 268static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
269SOC_DAPM_SINGLE("PC Beep Playback Switch", HPL_MIXER, 5, 1, 0), 269SOC_DAPM_SINGLE("Beep Playback Switch", HPL_MIXER, 5, 1, 0),
270SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0), 270SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0),
271SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0), 271SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0),
272SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0), 272SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0),
@@ -276,7 +276,7 @@ SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0),
276 276
277/* Right Headphone Mixers */ 277/* Right Headphone Mixers */
278static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = { 278static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
279SOC_DAPM_SINGLE("PC Beep Playback Switch", HPR_MIXER, 5, 1, 0), 279SOC_DAPM_SINGLE("Beep Playback Switch", HPR_MIXER, 5, 1, 0),
280SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0), 280SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0),
281SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0), 281SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0),
282SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0), 282SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0),
@@ -294,7 +294,7 @@ SOC_DAPM_ENUM("Route", wm9713_enum[0]);
294 294
295/* Speaker Mixer */ 295/* Speaker Mixer */
296static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = { 296static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = {
297SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1), 297SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 11, 1, 1),
298SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1), 298SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1),
299SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1), 299SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
300SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1), 300SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
@@ -304,7 +304,7 @@ SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
304 304
305/* Mono Mixer */ 305/* Mono Mixer */
306static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = { 306static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = {
307SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1), 307SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 7, 1, 1),
308SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1), 308SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1),
309SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1), 309SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
310SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1), 310SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
@@ -463,7 +463,7 @@ SND_SOC_DAPM_VMID("VMID"),
463 463
464static const struct snd_soc_dapm_route audio_map[] = { 464static const struct snd_soc_dapm_route audio_map[] = {
465 /* left HP mixer */ 465 /* left HP mixer */
466 {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, 466 {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"},
467 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"}, 467 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
468 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"}, 468 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
469 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"}, 469 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
@@ -472,7 +472,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
472 {"Left HP Mixer", NULL, "Capture Headphone Mux"}, 472 {"Left HP Mixer", NULL, "Capture Headphone Mux"},
473 473
474 /* right HP mixer */ 474 /* right HP mixer */
475 {"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, 475 {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"},
476 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"}, 476 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
477 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"}, 477 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
478 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"}, 478 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
@@ -491,7 +491,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
491 {"Capture Mixer", NULL, "Right Capture Source"}, 491 {"Capture Mixer", NULL, "Right Capture Source"},
492 492
493 /* speaker mixer */ 493 /* speaker mixer */
494 {"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"}, 494 {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"},
495 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"}, 495 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
496 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"}, 496 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
497 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"}, 497 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
@@ -499,7 +499,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
499 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"}, 499 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
500 500
501 /* mono mixer */ 501 /* mono mixer */
502 {"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"}, 502 {"Mono Mixer", "Beep Playback Switch", "PCBEEP"},
503 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, 503 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
504 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"}, 504 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
505 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"}, 505 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index 12a6c549ee6e..4ae707048021 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -97,22 +97,19 @@ enum {
97 DAVINCI_MCBSP_WORD_32, 97 DAVINCI_MCBSP_WORD_32,
98}; 98};
99 99
100static struct davinci_pcm_dma_params davinci_i2s_pcm_out = {
101 .name = "I2S PCM Stereo out",
102};
103
104static struct davinci_pcm_dma_params davinci_i2s_pcm_in = {
105 .name = "I2S PCM Stereo in",
106};
107
108struct davinci_mcbsp_dev { 100struct davinci_mcbsp_dev {
101 /*
102 * dma_params must be first because rtd->dai->cpu_dai->private_data
103 * is cast to a pointer of an array of struct davinci_pcm_dma_params in
104 * davinci_pcm_open.
105 */
106 struct davinci_pcm_dma_params dma_params[2];
109 void __iomem *base; 107 void __iomem *base;
110#define MOD_DSP_A 0 108#define MOD_DSP_A 0
111#define MOD_DSP_B 1 109#define MOD_DSP_B 1
112 int mode; 110 int mode;
113 u32 pcr; 111 u32 pcr;
114 struct clk *clk; 112 struct clk *clk;
115 struct davinci_pcm_dma_params *dma_params[2];
116}; 113};
117 114
118static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev, 115static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev,
@@ -215,14 +212,6 @@ static void davinci_mcbsp_stop(struct davinci_mcbsp_dev *dev, int playback)
215 toggle_clock(dev, playback); 212 toggle_clock(dev, playback);
216} 213}
217 214
218static int davinci_i2s_startup(struct snd_pcm_substream *substream,
219 struct snd_soc_dai *cpu_dai)
220{
221 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
222 cpu_dai->dma_data = dev->dma_params[substream->stream];
223 return 0;
224}
225
226#define DEFAULT_BITPERSAMPLE 16 215#define DEFAULT_BITPERSAMPLE 16
227 216
228static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, 217static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai,
@@ -353,8 +342,9 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
353 struct snd_pcm_hw_params *params, 342 struct snd_pcm_hw_params *params,
354 struct snd_soc_dai *dai) 343 struct snd_soc_dai *dai)
355{ 344{
356 struct davinci_pcm_dma_params *dma_params = dai->dma_data;
357 struct davinci_mcbsp_dev *dev = dai->private_data; 345 struct davinci_mcbsp_dev *dev = dai->private_data;
346 struct davinci_pcm_dma_params *dma_params =
347 &dev->dma_params[substream->stream];
358 struct snd_interval *i = NULL; 348 struct snd_interval *i = NULL;
359 int mcbsp_word_length; 349 int mcbsp_word_length;
360 unsigned int rcr, xcr, srgr; 350 unsigned int rcr, xcr, srgr;
@@ -472,7 +462,6 @@ static void davinci_i2s_shutdown(struct snd_pcm_substream *substream,
472#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000 462#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
473 463
474static struct snd_soc_dai_ops davinci_i2s_dai_ops = { 464static struct snd_soc_dai_ops davinci_i2s_dai_ops = {
475 .startup = davinci_i2s_startup,
476 .shutdown = davinci_i2s_shutdown, 465 .shutdown = davinci_i2s_shutdown,
477 .prepare = davinci_i2s_prepare, 466 .prepare = davinci_i2s_prepare,
478 .trigger = davinci_i2s_trigger, 467 .trigger = davinci_i2s_trigger,
@@ -534,12 +523,10 @@ static int davinci_i2s_probe(struct platform_device *pdev)
534 523
535 dev->base = (void __iomem *)IO_ADDRESS(mem->start); 524 dev->base = (void __iomem *)IO_ADDRESS(mem->start);
536 525
537 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK] = &davinci_i2s_pcm_out; 526 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].dma_addr =
538 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->dma_addr =
539 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DXR_REG); 527 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DXR_REG);
540 528
541 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE] = &davinci_i2s_pcm_in; 529 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].dma_addr =
542 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->dma_addr =
543 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DRR_REG); 530 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DRR_REG);
544 531
545 /* first TX, then RX */ 532 /* first TX, then RX */
@@ -549,7 +536,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
549 ret = -ENXIO; 536 ret = -ENXIO;
550 goto err_free_mem; 537 goto err_free_mem;
551 } 538 }
552 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->channel = res->start; 539 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = res->start;
553 540
554 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 541 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
555 if (!res) { 542 if (!res) {
@@ -557,7 +544,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
557 ret = -ENXIO; 544 ret = -ENXIO;
558 goto err_free_mem; 545 goto err_free_mem;
559 } 546 }
560 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->channel = res->start; 547 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start;
561 548
562 davinci_i2s_dai.private_data = dev; 549 davinci_i2s_dai.private_data = dev;
563 ret = snd_soc_register_dai(&davinci_i2s_dai); 550 ret = snd_soc_register_dai(&davinci_i2s_dai);
diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c
index 7a06c0a86665..5d1f98a4c978 100644
--- a/sound/soc/davinci/davinci-mcasp.c
+++ b/sound/soc/davinci/davinci-mcasp.c
@@ -332,14 +332,6 @@ static inline void mcasp_set_ctl_reg(void __iomem *regs, u32 val)
332 printk(KERN_ERR "GBLCTL write error\n"); 332 printk(KERN_ERR "GBLCTL write error\n");
333} 333}
334 334
335static int davinci_mcasp_startup(struct snd_pcm_substream *substream,
336 struct snd_soc_dai *cpu_dai)
337{
338 struct davinci_audio_dev *dev = cpu_dai->private_data;
339 cpu_dai->dma_data = dev->dma_params[substream->stream];
340 return 0;
341}
342
343static void mcasp_start_rx(struct davinci_audio_dev *dev) 335static void mcasp_start_rx(struct davinci_audio_dev *dev)
344{ 336{
345 mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST); 337 mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST);
@@ -386,17 +378,17 @@ static void mcasp_start_tx(struct davinci_audio_dev *dev)
386 378
387static void davinci_mcasp_start(struct davinci_audio_dev *dev, int stream) 379static void davinci_mcasp_start(struct davinci_audio_dev *dev, int stream)
388{ 380{
389 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 381 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
382 if (dev->txnumevt) /* enable FIFO */
383 mcasp_set_bits(dev->base + DAVINCI_MCASP_WFIFOCTL,
384 FIFO_ENABLE);
390 mcasp_start_tx(dev); 385 mcasp_start_tx(dev);
391 else 386 } else {
387 if (dev->rxnumevt) /* enable FIFO */
388 mcasp_set_bits(dev->base + DAVINCI_MCASP_RFIFOCTL,
389 FIFO_ENABLE);
392 mcasp_start_rx(dev); 390 mcasp_start_rx(dev);
393 391 }
394 /* enable FIFO */
395 if (dev->txnumevt)
396 mcasp_set_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE);
397
398 if (dev->rxnumevt)
399 mcasp_set_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE);
400} 392}
401 393
402static void mcasp_stop_rx(struct davinci_audio_dev *dev) 394static void mcasp_stop_rx(struct davinci_audio_dev *dev)
@@ -413,17 +405,17 @@ static void mcasp_stop_tx(struct davinci_audio_dev *dev)
413 405
414static void davinci_mcasp_stop(struct davinci_audio_dev *dev, int stream) 406static void davinci_mcasp_stop(struct davinci_audio_dev *dev, int stream)
415{ 407{
416 if (stream == SNDRV_PCM_STREAM_PLAYBACK) 408 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
409 if (dev->txnumevt) /* disable FIFO */
410 mcasp_clr_bits(dev->base + DAVINCI_MCASP_WFIFOCTL,
411 FIFO_ENABLE);
417 mcasp_stop_tx(dev); 412 mcasp_stop_tx(dev);
418 else 413 } else {
414 if (dev->rxnumevt) /* disable FIFO */
415 mcasp_clr_bits(dev->base + DAVINCI_MCASP_RFIFOCTL,
416 FIFO_ENABLE);
419 mcasp_stop_rx(dev); 417 mcasp_stop_rx(dev);
420 418 }
421 /* disable FIFO */
422 if (dev->txnumevt)
423 mcasp_clr_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE);
424
425 if (dev->rxnumevt)
426 mcasp_clr_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE);
427} 419}
428 420
429static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, 421static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
@@ -720,7 +712,7 @@ static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream,
720{ 712{
721 struct davinci_audio_dev *dev = cpu_dai->private_data; 713 struct davinci_audio_dev *dev = cpu_dai->private_data;
722 struct davinci_pcm_dma_params *dma_params = 714 struct davinci_pcm_dma_params *dma_params =
723 dev->dma_params[substream->stream]; 715 &dev->dma_params[substream->stream];
724 int word_length; 716 int word_length;
725 u8 numevt; 717 u8 numevt;
726 718
@@ -798,7 +790,6 @@ static int davinci_mcasp_trigger(struct snd_pcm_substream *substream,
798} 790}
799 791
800static struct snd_soc_dai_ops davinci_mcasp_dai_ops = { 792static struct snd_soc_dai_ops davinci_mcasp_dai_ops = {
801 .startup = davinci_mcasp_startup,
802 .trigger = davinci_mcasp_trigger, 793 .trigger = davinci_mcasp_trigger,
803 .hw_params = davinci_mcasp_hw_params, 794 .hw_params = davinci_mcasp_hw_params,
804 .set_fmt = davinci_mcasp_set_dai_fmt, 795 .set_fmt = davinci_mcasp_set_dai_fmt,
@@ -849,20 +840,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
849 struct resource *mem, *ioarea, *res; 840 struct resource *mem, *ioarea, *res;
850 struct snd_platform_data *pdata; 841 struct snd_platform_data *pdata;
851 struct davinci_audio_dev *dev; 842 struct davinci_audio_dev *dev;
852 int count = 0;
853 int ret = 0; 843 int ret = 0;
854 844
855 dev = kzalloc(sizeof(struct davinci_audio_dev), GFP_KERNEL); 845 dev = kzalloc(sizeof(struct davinci_audio_dev), GFP_KERNEL);
856 if (!dev) 846 if (!dev)
857 return -ENOMEM; 847 return -ENOMEM;
858 848
859 dma_data = kzalloc(sizeof(struct davinci_pcm_dma_params) * 2,
860 GFP_KERNEL);
861 if (!dma_data) {
862 ret = -ENOMEM;
863 goto err_release_dev;
864 }
865
866 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 849 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
867 if (!mem) { 850 if (!mem) {
868 dev_err(&pdev->dev, "no mem resource?\n"); 851 dev_err(&pdev->dev, "no mem resource?\n");
@@ -897,11 +880,10 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
897 dev->txnumevt = pdata->txnumevt; 880 dev->txnumevt = pdata->txnumevt;
898 dev->rxnumevt = pdata->rxnumevt; 881 dev->rxnumevt = pdata->rxnumevt;
899 882
900 dma_data[count].name = "I2S PCM Stereo out"; 883 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
901 dma_data[count].eventq_no = pdata->eventq_no; 884 dma_data->eventq_no = pdata->eventq_no;
902 dma_data[count].dma_addr = (dma_addr_t) (pdata->tx_dma_offset + 885 dma_data->dma_addr = (dma_addr_t) (pdata->tx_dma_offset +
903 io_v2p(dev->base)); 886 io_v2p(dev->base));
904 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK] = &dma_data[count];
905 887
906 /* first TX, then RX */ 888 /* first TX, then RX */
907 res = platform_get_resource(pdev, IORESOURCE_DMA, 0); 889 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
@@ -910,13 +892,12 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
910 goto err_release_region; 892 goto err_release_region;
911 } 893 }
912 894
913 dma_data[count].channel = res->start; 895 dma_data->channel = res->start;
914 count++; 896
915 dma_data[count].name = "I2S PCM Stereo in"; 897 dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE];
916 dma_data[count].eventq_no = pdata->eventq_no; 898 dma_data->eventq_no = pdata->eventq_no;
917 dma_data[count].dma_addr = (dma_addr_t)(pdata->rx_dma_offset + 899 dma_data->dma_addr = (dma_addr_t)(pdata->rx_dma_offset +
918 io_v2p(dev->base)); 900 io_v2p(dev->base));
919 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE] = &dma_data[count];
920 901
921 res = platform_get_resource(pdev, IORESOURCE_DMA, 1); 902 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
922 if (!res) { 903 if (!res) {
@@ -924,7 +905,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
924 goto err_release_region; 905 goto err_release_region;
925 } 906 }
926 907
927 dma_data[count].channel = res->start; 908 dma_data->channel = res->start;
928 davinci_mcasp_dai[pdata->op_mode].private_data = dev; 909 davinci_mcasp_dai[pdata->op_mode].private_data = dev;
929 davinci_mcasp_dai[pdata->op_mode].dev = &pdev->dev; 910 davinci_mcasp_dai[pdata->op_mode].dev = &pdev->dev;
930 ret = snd_soc_register_dai(&davinci_mcasp_dai[pdata->op_mode]); 911 ret = snd_soc_register_dai(&davinci_mcasp_dai[pdata->op_mode]);
@@ -936,8 +917,6 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
936err_release_region: 917err_release_region:
937 release_mem_region(mem->start, (mem->end - mem->start) + 1); 918 release_mem_region(mem->start, (mem->end - mem->start) + 1);
938err_release_data: 919err_release_data:
939 kfree(dma_data);
940err_release_dev:
941 kfree(dev); 920 kfree(dev);
942 921
943 return ret; 922 return ret;
@@ -946,7 +925,6 @@ err_release_dev:
946static int davinci_mcasp_remove(struct platform_device *pdev) 925static int davinci_mcasp_remove(struct platform_device *pdev)
947{ 926{
948 struct snd_platform_data *pdata = pdev->dev.platform_data; 927 struct snd_platform_data *pdata = pdev->dev.platform_data;
949 struct davinci_pcm_dma_params *dma_data;
950 struct davinci_audio_dev *dev; 928 struct davinci_audio_dev *dev;
951 struct resource *mem; 929 struct resource *mem;
952 930
@@ -959,8 +937,6 @@ static int davinci_mcasp_remove(struct platform_device *pdev)
959 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 937 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
960 release_mem_region(mem->start, (mem->end - mem->start) + 1); 938 release_mem_region(mem->start, (mem->end - mem->start) + 1);
961 939
962 dma_data = dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK];
963 kfree(dma_data);
964 kfree(dev); 940 kfree(dev);
965 941
966 return 0; 942 return 0;
diff --git a/sound/soc/davinci/davinci-mcasp.h b/sound/soc/davinci/davinci-mcasp.h
index 554354c1cc2f..9d179cc88f7b 100644
--- a/sound/soc/davinci/davinci-mcasp.h
+++ b/sound/soc/davinci/davinci-mcasp.h
@@ -39,10 +39,15 @@ enum {
39}; 39};
40 40
41struct davinci_audio_dev { 41struct davinci_audio_dev {
42 /*
43 * dma_params must be first because rtd->dai->cpu_dai->private_data
44 * is cast to a pointer of an array of struct davinci_pcm_dma_params in
45 * davinci_pcm_open.
46 */
47 struct davinci_pcm_dma_params dma_params[2];
42 void __iomem *base; 48 void __iomem *base;
43 int sample_rate; 49 int sample_rate;
44 struct clk *clk; 50 struct clk *clk;
45 struct davinci_pcm_dma_params *dma_params[2];
46 unsigned int codec_fmt; 51 unsigned int codec_fmt;
47 52
48 /* McASP specific data */ 53 /* McASP specific data */
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index 2f7da49ed34f..c73a915f233f 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -126,16 +126,9 @@ static void davinci_pcm_dma_irq(unsigned lch, u16 ch_status, void *data)
126static int davinci_pcm_dma_request(struct snd_pcm_substream *substream) 126static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
127{ 127{
128 struct davinci_runtime_data *prtd = substream->runtime->private_data; 128 struct davinci_runtime_data *prtd = substream->runtime->private_data;
129 struct snd_soc_pcm_runtime *rtd = substream->private_data;
130 struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data;
131 struct edmacc_param p_ram; 129 struct edmacc_param p_ram;
132 int ret; 130 int ret;
133 131
134 if (!dma_data)
135 return -ENODEV;
136
137 prtd->params = dma_data;
138
139 /* Request master DMA channel */ 132 /* Request master DMA channel */
140 ret = edma_alloc_channel(prtd->params->channel, 133 ret = edma_alloc_channel(prtd->params->channel,
141 davinci_pcm_dma_irq, substream, 134 davinci_pcm_dma_irq, substream,
@@ -244,6 +237,11 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream)
244 struct snd_pcm_runtime *runtime = substream->runtime; 237 struct snd_pcm_runtime *runtime = substream->runtime;
245 struct davinci_runtime_data *prtd; 238 struct davinci_runtime_data *prtd;
246 int ret = 0; 239 int ret = 0;
240 struct snd_soc_pcm_runtime *rtd = substream->private_data;
241 struct davinci_pcm_dma_params *pa = rtd->dai->cpu_dai->private_data;
242 struct davinci_pcm_dma_params *params = &pa[substream->stream];
243 if (!params)
244 return -ENODEV;
247 245
248 snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware); 246 snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware);
249 /* ensure that buffer size is a multiple of period size */ 247 /* ensure that buffer size is a multiple of period size */
@@ -257,6 +255,7 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream)
257 return -ENOMEM; 255 return -ENOMEM;
258 256
259 spin_lock_init(&prtd->lock); 257 spin_lock_init(&prtd->lock);
258 prtd->params = params;
260 259
261 runtime->private_data = prtd; 260 runtime->private_data = prtd;
262 261
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h
index 63d96253c73a..8746606efc89 100644
--- a/sound/soc/davinci/davinci-pcm.h
+++ b/sound/soc/davinci/davinci-pcm.h
@@ -17,7 +17,6 @@
17 17
18 18
19struct davinci_pcm_dma_params { 19struct davinci_pcm_dma_params {
20 char *name; /* stream identifier */
21 int channel; /* sync dma channel ID */ 20 int channel; /* sync dma channel ID */
22 unsigned short acnt; 21 unsigned short acnt;
23 dma_addr_t dma_addr; /* device physical address for DMA */ 22 dma_addr_t dma_addr; /* device physical address for DMA */
diff --git a/sound/soc/imx/mxc-ssi.c b/sound/soc/imx/mxc-ssi.c
index 3806ff2c0cd4..ccdefe60e752 100644
--- a/sound/soc/imx/mxc-ssi.c
+++ b/sound/soc/imx/mxc-ssi.c
@@ -397,14 +397,6 @@ static int imx_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai,
397 break; 397 break;
398 } 398 }
399 399
400 /* sync */
401 if (!(fmt & SND_SOC_DAIFMT_ASYNC))
402 scr |= SSI_SCR_SYN;
403
404 /* tdm - only for stereo atm */
405 if (fmt & SND_SOC_DAIFMT_TDM)
406 scr |= SSI_SCR_NET;
407
408 if (cpu_dai->id == IMX_DAI_SSI0 || cpu_dai->id == IMX_DAI_SSI2) { 400 if (cpu_dai->id == IMX_DAI_SSI0 || cpu_dai->id == IMX_DAI_SSI2) {
409 SSI1_STCR = stcr; 401 SSI1_STCR = stcr;
410 SSI1_SRCR = srcr; 402 SSI1_SRCR = srcr;
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
index 6375b4ea525d..dcb3181bb340 100644
--- a/sound/soc/pxa/Kconfig
+++ b/sound/soc/pxa/Kconfig
@@ -138,7 +138,7 @@ config SND_PXA2XX_SOC_MIOA701
138 138
139config SND_PXA2XX_SOC_IMOTE2 139config SND_PXA2XX_SOC_IMOTE2
140 tristate "SoC Audio support for IMote 2" 140 tristate "SoC Audio support for IMote 2"
141 depends on SND_PXA2XX_SOC && MACH_INTELMOTE2 141 depends on SND_PXA2XX_SOC && MACH_INTELMOTE2 && I2C
142 select SND_PXA2XX_SOC_I2S 142 select SND_PXA2XX_SOC_I2S
143 select SND_SOC_WM8940 143 select SND_SOC_WM8940
144 help 144 help
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index f79711b9fa5b..8de6f9dec4a2 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -524,7 +524,7 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
524 524
525 /* connected jack or spk ? */ 525 /* connected jack or spk ? */
526 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk || 526 if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
527 widget->id == snd_soc_dapm_line) 527 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
528 return 1; 528 return 1;
529 } 529 }
530 530
@@ -573,7 +573,8 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
573 return 1; 573 return 1;
574 574
575 /* connected jack ? */ 575 /* connected jack ? */
576 if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line) 576 if (widget->id == snd_soc_dapm_mic ||
577 (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
577 return 1; 578 return 1;
578 } 579 }
579 580
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index 121af0644fd9..86b2c3b92df5 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -62,10 +62,14 @@ static void
62activate_substream(struct snd_usb_caiaqdev *dev, 62activate_substream(struct snd_usb_caiaqdev *dev,
63 struct snd_pcm_substream *sub) 63 struct snd_pcm_substream *sub)
64{ 64{
65 spin_lock(&dev->spinlock);
66
65 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 67 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
66 dev->sub_playback[sub->number] = sub; 68 dev->sub_playback[sub->number] = sub;
67 else 69 else
68 dev->sub_capture[sub->number] = sub; 70 dev->sub_capture[sub->number] = sub;
71
72 spin_unlock(&dev->spinlock);
69} 73}
70 74
71static void 75static void
@@ -269,16 +273,22 @@ snd_usb_caiaq_pcm_pointer(struct snd_pcm_substream *sub)
269{ 273{
270 int index = sub->number; 274 int index = sub->number;
271 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 275 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
276 snd_pcm_uframes_t ptr;
277
278 spin_lock(&dev->spinlock);
272 279
273 if (dev->input_panic || dev->output_panic) 280 if (dev->input_panic || dev->output_panic)
274 return SNDRV_PCM_POS_XRUN; 281 ptr = SNDRV_PCM_POS_XRUN;
275 282
276 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 283 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
277 return bytes_to_frames(sub->runtime, 284 ptr = bytes_to_frames(sub->runtime,
278 dev->audio_out_buf_pos[index]); 285 dev->audio_out_buf_pos[index]);
279 else 286 else
280 return bytes_to_frames(sub->runtime, 287 ptr = bytes_to_frames(sub->runtime,
281 dev->audio_in_buf_pos[index]); 288 dev->audio_in_buf_pos[index]);
289
290 spin_unlock(&dev->spinlock);
291 return ptr;
282} 292}
283 293
284/* operators for both playback and capture */ 294/* operators for both playback and capture */
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index 83e6c1312d47..a3f02dd97440 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -35,7 +35,7 @@
35#include "input.h" 35#include "input.h"
36 36
37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 37MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.19"); 38MODULE_DESCRIPTION("caiaq USB audio, version 1.3.20");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 40MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
41 "{Native Instruments, RigKontrol3}," 41 "{Native Instruments, RigKontrol3},"
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c
index ab5a3ac2ac47..9efcfd08d747 100644
--- a/sound/usb/usbmixer.c
+++ b/sound/usb/usbmixer.c
@@ -898,6 +898,11 @@ static struct snd_kcontrol_new usb_feature_unit_ctl = {
898 * build a feature control 898 * build a feature control
899 */ 899 */
900 900
901static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str)
902{
903 return strlcat(kctl->id.name, str, sizeof(kctl->id.name));
904}
905
901static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, 906static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
902 unsigned int ctl_mask, int control, 907 unsigned int ctl_mask, int control,
903 struct usb_audio_term *iterm, int unitid) 908 struct usb_audio_term *iterm, int unitid)
@@ -978,13 +983,13 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
978 */ 983 */
979 if (! mapped_name && ! (state->oterm.type >> 16)) { 984 if (! mapped_name && ! (state->oterm.type >> 16)) {
980 if ((state->oterm.type & 0xff00) == 0x0100) { 985 if ((state->oterm.type & 0xff00) == 0x0100) {
981 len = strlcat(kctl->id.name, " Capture", sizeof(kctl->id.name)); 986 len = append_ctl_name(kctl, " Capture");
982 } else { 987 } else {
983 len = strlcat(kctl->id.name + len, " Playback", sizeof(kctl->id.name)); 988 len = append_ctl_name(kctl, " Playback");
984 } 989 }
985 } 990 }
986 strlcat(kctl->id.name + len, control == USB_FEATURE_MUTE ? " Switch" : " Volume", 991 append_ctl_name(kctl, control == USB_FEATURE_MUTE ?
987 sizeof(kctl->id.name)); 992 " Switch" : " Volume");
988 if (control == USB_FEATURE_VOLUME) { 993 if (control == USB_FEATURE_VOLUME) {
989 kctl->tlv.c = mixer_vol_tlv; 994 kctl->tlv.c = mixer_vol_tlv;
990 kctl->vd[0].access |= 995 kctl->vd[0].access |=
@@ -1143,7 +1148,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
1143 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); 1148 len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0);
1144 if (! len) 1149 if (! len)
1145 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); 1150 len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1);
1146 strlcat(kctl->id.name + len, " Volume", sizeof(kctl->id.name)); 1151 append_ctl_name(kctl, " Volume");
1147 1152
1148 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", 1153 snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n",
1149 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1154 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
@@ -1400,8 +1405,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
1400 if (! len) 1405 if (! len)
1401 strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); 1406 strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
1402 } 1407 }
1403 strlcat(kctl->id.name, " ", sizeof(kctl->id.name)); 1408 append_ctl_name(kctl, " ");
1404 strlcat(kctl->id.name, valinfo->suffix, sizeof(kctl->id.name)); 1409 append_ctl_name(kctl, valinfo->suffix);
1405 1410
1406 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", 1411 snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
1407 cval->id, kctl->id.name, cval->channels, cval->min, cval->max); 1412 cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
@@ -1610,9 +1615,9 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
1610 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); 1615 strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
1611 1616
1612 if ((state->oterm.type & 0xff00) == 0x0100) 1617 if ((state->oterm.type & 0xff00) == 0x0100)
1613 strlcat(kctl->id.name, " Capture Source", sizeof(kctl->id.name)); 1618 append_ctl_name(kctl, " Capture Source");
1614 else 1619 else
1615 strlcat(kctl->id.name, " Playback Source", sizeof(kctl->id.name)); 1620 append_ctl_name(kctl, " Playback Source");
1616 } 1621 }
1617 1622
1618 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", 1623 snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 99f33766cd51..00cd54c236b4 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -66,6 +66,28 @@ static int us122l_create_usbmidi(struct snd_card *card)
66 iface, &quirk); 66 iface, &quirk);
67} 67}
68 68
69static int us144_create_usbmidi(struct snd_card *card)
70{
71 static struct snd_usb_midi_endpoint_info quirk_data = {
72 .out_ep = 4,
73 .in_ep = 3,
74 .out_cables = 0x001,
75 .in_cables = 0x001
76 };
77 static struct snd_usb_audio_quirk quirk = {
78 .vendor_name = "US144",
79 .product_name = NAME_ALLCAPS,
80 .ifnum = 0,
81 .type = QUIRK_MIDI_US122L,
82 .data = &quirk_data
83 };
84 struct usb_device *dev = US122L(card)->chip.dev;
85 struct usb_interface *iface = usb_ifnum_to_if(dev, 0);
86
87 return snd_usb_create_midi_interface(&US122L(card)->chip,
88 iface, &quirk);
89}
90
69/* 91/*
70 * Wrapper for usb_control_msg(). 92 * Wrapper for usb_control_msg().
71 * Allocates a temp buffer to prevent dmaing from/to the stack. 93 * Allocates a temp buffer to prevent dmaing from/to the stack.
@@ -171,6 +193,11 @@ static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
171 193
172 if (!us122l->first) 194 if (!us122l->first)
173 us122l->first = file; 195 us122l->first = file;
196
197 if (us122l->chip.dev->descriptor.idProduct == USB_ID_US144) {
198 iface = usb_ifnum_to_if(us122l->chip.dev, 0);
199 usb_autopm_get_interface(iface);
200 }
174 iface = usb_ifnum_to_if(us122l->chip.dev, 1); 201 iface = usb_ifnum_to_if(us122l->chip.dev, 1);
175 usb_autopm_get_interface(iface); 202 usb_autopm_get_interface(iface);
176 return 0; 203 return 0;
@@ -179,8 +206,14 @@ static int usb_stream_hwdep_open(struct snd_hwdep *hw, struct file *file)
179static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file) 206static int usb_stream_hwdep_release(struct snd_hwdep *hw, struct file *file)
180{ 207{
181 struct us122l *us122l = hw->private_data; 208 struct us122l *us122l = hw->private_data;
182 struct usb_interface *iface = usb_ifnum_to_if(us122l->chip.dev, 1); 209 struct usb_interface *iface;
183 snd_printdd(KERN_DEBUG "%p %p\n", hw, file); 210 snd_printdd(KERN_DEBUG "%p %p\n", hw, file);
211
212 if (us122l->chip.dev->descriptor.idProduct == USB_ID_US144) {
213 iface = usb_ifnum_to_if(us122l->chip.dev, 0);
214 usb_autopm_put_interface(iface);
215 }
216 iface = usb_ifnum_to_if(us122l->chip.dev, 1);
184 usb_autopm_put_interface(iface); 217 usb_autopm_put_interface(iface);
185 if (us122l->first == file) 218 if (us122l->first == file)
186 us122l->first = NULL; 219 us122l->first = NULL;
@@ -443,6 +476,13 @@ static bool us122l_create_card(struct snd_card *card)
443 int err; 476 int err;
444 struct us122l *us122l = US122L(card); 477 struct us122l *us122l = US122L(card);
445 478
479 if (us122l->chip.dev->descriptor.idProduct == USB_ID_US144) {
480 err = usb_set_interface(us122l->chip.dev, 0, 1);
481 if (err) {
482 snd_printk(KERN_ERR "usb_set_interface error \n");
483 return false;
484 }
485 }
446 err = usb_set_interface(us122l->chip.dev, 1, 1); 486 err = usb_set_interface(us122l->chip.dev, 1, 1);
447 if (err) { 487 if (err) {
448 snd_printk(KERN_ERR "usb_set_interface error \n"); 488 snd_printk(KERN_ERR "usb_set_interface error \n");
@@ -455,7 +495,10 @@ static bool us122l_create_card(struct snd_card *card)
455 if (!us122l_start(us122l, 44100, 256)) 495 if (!us122l_start(us122l, 44100, 256))
456 return false; 496 return false;
457 497
458 err = us122l_create_usbmidi(card); 498 if (us122l->chip.dev->descriptor.idProduct == USB_ID_US144)
499 err = us144_create_usbmidi(card);
500 else
501 err = us122l_create_usbmidi(card);
459 if (err < 0) { 502 if (err < 0) {
460 snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err); 503 snd_printk(KERN_ERR "us122l_create_usbmidi error %i \n", err);
461 us122l_stop(us122l); 504 us122l_stop(us122l);
@@ -542,6 +585,7 @@ static int us122l_usb_probe(struct usb_interface *intf,
542 return err; 585 return err;
543 } 586 }
544 587
588 usb_get_intf(usb_ifnum_to_if(device, 0));
545 usb_get_dev(device); 589 usb_get_dev(device);
546 *cardp = card; 590 *cardp = card;
547 return 0; 591 return 0;
@@ -550,9 +594,16 @@ static int us122l_usb_probe(struct usb_interface *intf,
550static int snd_us122l_probe(struct usb_interface *intf, 594static int snd_us122l_probe(struct usb_interface *intf,
551 const struct usb_device_id *id) 595 const struct usb_device_id *id)
552{ 596{
597 struct usb_device *device = interface_to_usbdev(intf);
553 struct snd_card *card; 598 struct snd_card *card;
554 int err; 599 int err;
555 600
601 if (device->descriptor.idProduct == USB_ID_US144
602 && device->speed == USB_SPEED_HIGH) {
603 snd_printk(KERN_ERR "disable ehci-hcd to run US-144 \n");
604 return -ENODEV;
605 }
606
556 snd_printdd(KERN_DEBUG"%p:%i\n", 607 snd_printdd(KERN_DEBUG"%p:%i\n",
557 intf, intf->cur_altsetting->desc.bInterfaceNumber); 608 intf, intf->cur_altsetting->desc.bInterfaceNumber);
558 if (intf->cur_altsetting->desc.bInterfaceNumber != 1) 609 if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
@@ -591,7 +642,8 @@ static void snd_us122l_disconnect(struct usb_interface *intf)
591 snd_usbmidi_disconnect(p); 642 snd_usbmidi_disconnect(p);
592 } 643 }
593 644
594 usb_put_intf(intf); 645 usb_put_intf(usb_ifnum_to_if(us122l->chip.dev, 0));
646 usb_put_intf(usb_ifnum_to_if(us122l->chip.dev, 1));
595 usb_put_dev(us122l->chip.dev); 647 usb_put_dev(us122l->chip.dev);
596 648
597 while (atomic_read(&us122l->mmap_count)) 649 while (atomic_read(&us122l->mmap_count))
@@ -642,6 +694,13 @@ static int snd_us122l_resume(struct usb_interface *intf)
642 694
643 mutex_lock(&us122l->mutex); 695 mutex_lock(&us122l->mutex);
644 /* needed, doesn't restart without: */ 696 /* needed, doesn't restart without: */
697 if (us122l->chip.dev->descriptor.idProduct == USB_ID_US144) {
698 err = usb_set_interface(us122l->chip.dev, 0, 1);
699 if (err) {
700 snd_printk(KERN_ERR "usb_set_interface error \n");
701 goto unlock;
702 }
703 }
645 err = usb_set_interface(us122l->chip.dev, 1, 1); 704 err = usb_set_interface(us122l->chip.dev, 1, 1);
646 if (err) { 705 if (err) {
647 snd_printk(KERN_ERR "usb_set_interface error \n"); 706 snd_printk(KERN_ERR "usb_set_interface error \n");
@@ -675,11 +734,11 @@ static struct usb_device_id snd_us122l_usb_id_table[] = {
675 .idVendor = 0x0644, 734 .idVendor = 0x0644,
676 .idProduct = USB_ID_US122L 735 .idProduct = USB_ID_US122L
677 }, 736 },
678/* { */ /* US-144 maybe works when @USB1.1. Untested. */ 737 { /* US-144 only works at USB1.1! Disable module ehci-hcd. */
679/* .match_flags = USB_DEVICE_ID_MATCH_DEVICE, */ 738 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
680/* .idVendor = 0x0644, */ 739 .idVendor = 0x0644,
681/* .idProduct = USB_ID_US144 */ 740 .idProduct = USB_ID_US144
682/* }, */ 741 },
683 { /* terminator */ } 742 { /* terminator */ }
684}; 743};
685 744