aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci')
-rw-r--r--sound/pci/Kconfig9
-rw-r--r--sound/pci/ac97/ac97_codec.c56
-rw-r--r--sound/pci/ac97/ac97_patch.c80
-rw-r--r--sound/pci/ac97/ac97_pcm.c9
-rw-r--r--sound/pci/ad1889.c5
-rw-r--r--sound/pci/ali5451/ali5451.c92
-rw-r--r--sound/pci/als4000.c8
-rw-r--r--sound/pci/atiixp.c50
-rw-r--r--sound/pci/atiixp_modem.c37
-rw-r--r--sound/pci/au88x0/au8810.h5
-rw-r--r--sound/pci/au88x0/au8820.h5
-rw-r--r--sound/pci/au88x0/au8830.h5
-rw-r--r--sound/pci/au88x0/au88x0.c2
-rw-r--r--sound/pci/au88x0/au88x0.h8
-rw-r--r--sound/pci/au88x0/au88x0_a3d.c2
-rw-r--r--sound/pci/au88x0/au88x0_core.c10
-rw-r--r--sound/pci/au88x0/au88x0_eq.c2
-rw-r--r--sound/pci/au88x0/au88x0_synth.c8
-rw-r--r--sound/pci/azt3328.c1005
-rw-r--r--sound/pci/azt3328.h135
-rw-r--r--sound/pci/ca0106/Makefile2
-rw-r--r--sound/pci/ca0106/ca0106.h27
-rw-r--r--sound/pci/ca0106/ca0106_main.c123
-rw-r--r--sound/pci/ca0106/ca_midi.c306
-rw-r--r--sound/pci/ca0106/ca_midi.h69
-rw-r--r--sound/pci/cmipci.c126
-rw-r--r--sound/pci/cs4281.c6
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c43
-rw-r--r--sound/pci/emu10k1/emu10k1.c2
-rw-r--r--sound/pci/emu10k1/emu10k1_callback.c4
-rw-r--r--sound/pci/emu10k1/emu10k1x.c6
-rw-r--r--sound/pci/emu10k1/emufx.c59
-rw-r--r--sound/pci/emu10k1/emupcm.c3
-rw-r--r--sound/pci/emu10k1/irq.c2
-rw-r--r--sound/pci/emu10k1/memory.c6
-rw-r--r--sound/pci/emu10k1/p16v.c2
-rw-r--r--sound/pci/ens1370.c17
-rw-r--r--sound/pci/es1938.c38
-rw-r--r--sound/pci/es1968.c22
-rw-r--r--sound/pci/fm801.c25
-rw-r--r--sound/pci/hda/hda_codec.c52
-rw-r--r--sound/pci/hda/hda_codec.h2
-rw-r--r--sound/pci/hda/hda_intel.c72
-rw-r--r--sound/pci/hda/hda_local.h22
-rw-r--r--sound/pci/hda/hda_proc.c5
-rw-r--r--sound/pci/hda/patch_analog.c133
-rw-r--r--sound/pci/hda/patch_realtek.c274
-rw-r--r--sound/pci/hda/patch_si3054.c2
-rw-r--r--sound/pci/ice1712/aureon.c6
-rw-r--r--sound/pci/ice1712/delta.c2
-rw-r--r--sound/pci/ice1712/ews.c6
-rw-r--r--sound/pci/ice1712/ice1712.c10
-rw-r--r--sound/pci/ice1712/ice1724.c43
-rw-r--r--sound/pci/ice1712/pontis.c3
-rw-r--r--sound/pci/ice1712/revo.c13
-rw-r--r--sound/pci/ice1712/vt1720_mobo.c20
-rw-r--r--sound/pci/intel8x0.c160
-rw-r--r--sound/pci/intel8x0m.c55
-rw-r--r--sound/pci/maestro3.c21
-rw-r--r--sound/pci/mixart/mixart.c3
-rw-r--r--sound/pci/nm256/nm256.c145
-rw-r--r--sound/pci/rme32.c4
-rw-r--r--sound/pci/rme96.c4
-rw-r--r--sound/pci/rme9652/hdsp.c588
-rw-r--r--sound/pci/rme9652/hdspm.c3
-rw-r--r--sound/pci/rme9652/rme9652.c6
-rw-r--r--sound/pci/sonicvibes.c24
-rw-r--r--sound/pci/trident/trident_main.c18
-rw-r--r--sound/pci/trident/trident_memory.c4
-rw-r--r--sound/pci/via82xx.c375
-rw-r--r--sound/pci/via82xx_modem.c49
-rw-r--r--sound/pci/ymfpci/ymfpci.c18
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c75
73 files changed, 2845 insertions, 1793 deletions
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index a5d593c66f9f..0fb16cf335ea 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -1,13 +1,5 @@
1# ALSA PCI drivers 1# ALSA PCI drivers
2 2
3config SND_AC97_CODEC
4 tristate
5 select SND_PCM
6 select SND_AC97_BUS
7
8config SND_AC97_BUS
9 tristate
10
11menu "PCI devices" 3menu "PCI devices"
12 depends on SND!=n && PCI 4 depends on SND!=n && PCI
13 5
@@ -192,6 +184,7 @@ config SND_CA0106
192 tristate "SB Audigy LS / Live 24bit" 184 tristate "SB Audigy LS / Live 24bit"
193 depends on SND 185 depends on SND
194 select SND_AC97_CODEC 186 select SND_AC97_CODEC
187 select SND_RAWMIDI
195 help 188 help
196 Say Y here to include support for the Sound Blaster Audigy LS 189 Say Y here to include support for the Sound Blaster Audigy LS
197 and Live 24bit. 190 and Live 24bit.
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 41fc290149ed..9bde76c4c6a2 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -220,12 +220,6 @@ const char *snd_ac97_stereo_enhancements[] =
220 /* 31 */ "Reserved 31" 220 /* 31 */ "Reserved 31"
221}; 221};
222 222
223/*
224 * Shared AC97 controllers (ICH, ATIIXP...)
225 */
226static DECLARE_MUTEX(shared_codec_mutex);
227static ac97_t *shared_codec[AC97_SHARED_TYPES][4];
228
229 223
230/* 224/*
231 * I/O routines 225 * I/O routines
@@ -996,14 +990,8 @@ static int snd_ac97_free(ac97_t *ac97)
996{ 990{
997 if (ac97) { 991 if (ac97) {
998 snd_ac97_proc_done(ac97); 992 snd_ac97_proc_done(ac97);
999 if (ac97->bus) { 993 if (ac97->bus)
1000 ac97->bus->codec[ac97->num] = NULL; 994 ac97->bus->codec[ac97->num] = NULL;
1001 if (ac97->bus->shared_type) {
1002 down(&shared_codec_mutex);
1003 shared_codec[ac97->bus->shared_type-1][ac97->num] = NULL;
1004 up(&shared_codec_mutex);
1005 }
1006 }
1007 if (ac97->private_free) 995 if (ac97->private_free)
1008 ac97->private_free(ac97); 996 ac97->private_free(ac97);
1009 kfree(ac97); 997 kfree(ac97);
@@ -1139,7 +1127,6 @@ snd_kcontrol_t *snd_ac97_cnew(const snd_kcontrol_new_t *_template, ac97_t * ac97
1139{ 1127{
1140 snd_kcontrol_new_t template; 1128 snd_kcontrol_new_t template;
1141 memcpy(&template, _template, sizeof(template)); 1129 memcpy(&template, _template, sizeof(template));
1142 snd_runtime_check(!template.index, return NULL);
1143 template.index = ac97->num; 1130 template.index = ac97->num;
1144 return snd_ctl_new1(&template, ac97); 1131 return snd_ctl_new1(&template, ac97);
1145} 1132}
@@ -1758,8 +1745,7 @@ static int ac97_reset_wait(ac97_t *ac97, int timeout, int with_modem)
1758 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05) 1745 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05)
1759 return 0; 1746 return 0;
1760 } 1747 }
1761 set_current_state(TASK_UNINTERRUPTIBLE); 1748 schedule_timeout_uninterruptible(1);
1762 schedule_timeout(1);
1763 } while (time_after_eq(end_time, jiffies)); 1749 } while (time_after_eq(end_time, jiffies));
1764 return -ENODEV; 1750 return -ENODEV;
1765} 1751}
@@ -1889,21 +1875,6 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
1889 snd_assert(bus != NULL && template != NULL, return -EINVAL); 1875 snd_assert(bus != NULL && template != NULL, return -EINVAL);
1890 snd_assert(template->num < 4 && bus->codec[template->num] == NULL, return -EINVAL); 1876 snd_assert(template->num < 4 && bus->codec[template->num] == NULL, return -EINVAL);
1891 1877
1892 snd_assert(bus->shared_type <= AC97_SHARED_TYPES, return -EINVAL);
1893 if (bus->shared_type) {
1894 /* already shared? */
1895 down(&shared_codec_mutex);
1896 ac97 = shared_codec[bus->shared_type-1][template->num];
1897 if (ac97) {
1898 if ((ac97_is_audio(ac97) && (template->scaps & AC97_SCAP_SKIP_AUDIO)) ||
1899 (ac97_is_modem(ac97) && (template->scaps & AC97_SCAP_SKIP_MODEM))) {
1900 up(&shared_codec_mutex);
1901 return -EACCES; /* skip this */
1902 }
1903 }
1904 up(&shared_codec_mutex);
1905 }
1906
1907 card = bus->card; 1878 card = bus->card;
1908 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL); 1879 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
1909 if (ac97 == NULL) 1880 if (ac97 == NULL)
@@ -2020,8 +1991,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2020 do { 1991 do {
2021 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f) 1992 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2022 goto __ready_ok; 1993 goto __ready_ok;
2023 set_current_state(TASK_UNINTERRUPTIBLE); 1994 schedule_timeout_uninterruptible(1);
2024 schedule_timeout(1);
2025 } while (time_after_eq(end_time, jiffies)); 1995 } while (time_after_eq(end_time, jiffies));
2026 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num); 1996 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num);
2027 } 1997 }
@@ -2053,8 +2023,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2053 do { 2023 do {
2054 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp) 2024 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
2055 goto __ready_ok; 2025 goto __ready_ok;
2056 set_current_state(TASK_UNINTERRUPTIBLE); 2026 schedule_timeout_uninterruptible(1);
2057 schedule_timeout(1);
2058 } while (time_after_eq(end_time, jiffies)); 2027 } while (time_after_eq(end_time, jiffies));
2059 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS)); 2028 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
2060 } 2029 }
@@ -2077,6 +2046,8 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2077 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78); 2046 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78);
2078 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78) 2047 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78)
2079 ac97->flags |= AC97_DOUBLE_RATE; 2048 ac97->flags |= AC97_DOUBLE_RATE;
2049 /* restore to slots 10/11 to avoid the confliction with surrounds */
2050 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0);
2080 } 2051 }
2081 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */ 2052 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */
2082 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]); 2053 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]);
@@ -2153,7 +2124,7 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2153 } 2124 }
2154 } 2125 }
2155 /* make sure the proper powerdown bits are cleared */ 2126 /* make sure the proper powerdown bits are cleared */
2156 if (ac97->scaps) { 2127 if (ac97->scaps && ac97_is_audio(ac97)) {
2157 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS); 2128 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2158 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) 2129 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2159 reg &= ~AC97_EA_PRJ; 2130 reg &= ~AC97_EA_PRJ;
@@ -2167,13 +2138,6 @@ int snd_ac97_mixer(ac97_bus_t *bus, ac97_template_t *template, ac97_t **rac97)
2167 return err; 2138 return err;
2168 } 2139 }
2169 *rac97 = ac97; 2140 *rac97 = ac97;
2170
2171 if (bus->shared_type) {
2172 down(&shared_codec_mutex);
2173 shared_codec[bus->shared_type-1][ac97->num] = ac97;
2174 up(&shared_codec_mutex);
2175 }
2176
2177 return 0; 2141 return 0;
2178} 2142}
2179 2143
@@ -2295,8 +2259,7 @@ void snd_ac97_resume(ac97_t *ac97)
2295 do { 2259 do {
2296 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101) 2260 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
2297 break; 2261 break;
2298 set_current_state(TASK_UNINTERRUPTIBLE); 2262 schedule_timeout_uninterruptible(1);
2299 schedule_timeout(1);
2300 } while (time_after_eq(end_time, jiffies)); 2263 } while (time_after_eq(end_time, jiffies));
2301 /* FIXME: extra delay */ 2264 /* FIXME: extra delay */
2302 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000); 2265 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000);
@@ -2308,8 +2271,7 @@ void snd_ac97_resume(ac97_t *ac97)
2308 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID); 2271 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2309 if (val != 0xffff && (val & 1) != 0) 2272 if (val != 0xffff && (val & 1) != 0)
2310 break; 2273 break;
2311 set_current_state(TASK_UNINTERRUPTIBLE); 2274 schedule_timeout_uninterruptible(1);
2312 schedule_timeout(1);
2313 } while (time_after_eq(end_time, jiffies)); 2275 } while (time_after_eq(end_time, jiffies));
2314 } 2276 }
2315__reset_ready: 2277__reset_ready:
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 0238cc65d32a..de1c72ad2c6b 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -163,14 +163,24 @@ static int ac97_channel_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t
163 .private_value = 1, \ 163 .private_value = 1, \
164 } 164 }
165 165
166static inline int is_surround_on(ac97_t *ac97)
167{
168 return ac97->channel_mode >= 1;
169}
170
171static inline int is_clfe_on(ac97_t *ac97)
172{
173 return ac97->channel_mode >= 2;
174}
175
166static inline int is_shared_linein(ac97_t *ac97) 176static inline int is_shared_linein(ac97_t *ac97)
167{ 177{
168 return ! ac97->indep_surround && ac97->channel_mode >= 1; 178 return ! ac97->indep_surround && is_surround_on(ac97);
169} 179}
170 180
171static inline int is_shared_micin(ac97_t *ac97) 181static inline int is_shared_micin(ac97_t *ac97)
172{ 182{
173 return ! ac97->indep_surround && ac97->channel_mode >= 2; 183 return ! ac97->indep_surround && is_clfe_on(ac97);
174} 184}
175 185
176 186
@@ -1450,7 +1460,8 @@ int patch_ad1881(ac97_t * ac97)
1450 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14)); 1460 codecs[1] = patch_ad1881_unchained(ac97, 1, (1<<14));
1451 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13)); 1461 codecs[2] = patch_ad1881_unchained(ac97, 2, (1<<13));
1452 1462
1453 snd_runtime_check(codecs[0] | codecs[1] | codecs[2], goto __end); 1463 if (! (codecs[0] || codecs[1] || codecs[2]))
1464 goto __end;
1454 1465
1455 for (idx = 0; idx < 3; idx++) 1466 for (idx = 0; idx < 3; idx++)
1456 if (ac97->spec.ad18xx.unchained[idx]) 1467 if (ac97->spec.ad18xx.unchained[idx])
@@ -1753,12 +1764,13 @@ static int snd_ac97_ad1888_downmix_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_va
1753 1764
1754static void ad1888_update_jacks(ac97_t *ac97) 1765static void ad1888_update_jacks(ac97_t *ac97)
1755{ 1766{
1767 unsigned short val = 0;
1768 if (! is_shared_linein(ac97))
1769 val |= (1 << 12);
1770 if (! is_shared_micin(ac97))
1771 val |= (1 << 11);
1756 /* shared Line-In */ 1772 /* shared Line-In */
1757 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12, 1773 snd_ac97_update_bits(ac97, AC97_AD_MISC, (1 << 11) | (1 << 12), val);
1758 is_shared_linein(ac97) ? 0 : 1 << 12);
1759 /* shared Mic */
1760 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1761 is_shared_micin(ac97) ? 0 : 1 << 11);
1762} 1774}
1763 1775
1764static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = { 1776static const snd_kcontrol_new_t snd_ac97_ad1888_controls[] = {
@@ -1852,12 +1864,7 @@ static const snd_kcontrol_new_t snd_ac97_ad1985_controls[] = {
1852 1864
1853static void ad1985_update_jacks(ac97_t *ac97) 1865static void ad1985_update_jacks(ac97_t *ac97)
1854{ 1866{
1855 /* shared Line-In */ 1867 ad1888_update_jacks(ac97);
1856 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 12,
1857 is_shared_linein(ac97) ? 0 : 1 << 12);
1858 /* shared Mic */
1859 snd_ac97_update_bits(ac97, AC97_AD_MISC, 1 << 11,
1860 is_shared_micin(ac97) ? 0 : 1 << 11);
1861 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9, 1868 snd_ac97_update_bits(ac97, AC97_AD_SERIAL_CFG, 1 << 9,
1862 is_shared_micin(ac97) ? 0 : 1 << 9); 1869 is_shared_micin(ac97) ? 0 : 1 << 9);
1863} 1870}
@@ -2442,21 +2449,37 @@ int patch_cm9739(ac97_t * ac97)
2442 2449
2443static void cm9761_update_jacks(ac97_t *ac97) 2450static void cm9761_update_jacks(ac97_t *ac97)
2444{ 2451{
2445 unsigned short surr_vals[2][2] = { 2452 /* FIXME: check the bits for each model
2446 { 0x0008, 0x0400 }, /* off, on */ 2453 * model 83 is confirmed to work
2447 { 0x0000, 0x0408 }, /* off, on (9761-82 rev.B) */ 2454 */
2455 static unsigned short surr_on[3][2] = {
2456 { 0x0008, 0x0000 }, /* 9761-78 & 82 */
2457 { 0x0000, 0x0008 }, /* 9761-82 rev.B */
2458 { 0x0000, 0x0008 }, /* 9761-83 */
2459 };
2460 static unsigned short clfe_on[3][2] = {
2461 { 0x0000, 0x1000 }, /* 9761-78 & 82 */
2462 { 0x1000, 0x0000 }, /* 9761-82 rev.B */
2463 { 0x0000, 0x1000 }, /* 9761-83 */
2464 };
2465 static unsigned short surr_shared[3][2] = {
2466 { 0x0000, 0x0400 }, /* 9761-78 & 82 */
2467 { 0x0000, 0x0400 }, /* 9761-82 rev.B */
2468 { 0x0000, 0x0400 }, /* 9761-83 */
2448 }; 2469 };
2449 unsigned short clfe_vals[2][2] = { 2470 static unsigned short clfe_shared[3][2] = {
2450 { 0x2000, 0x1880 }, /* off, on */ 2471 { 0x2000, 0x0880 }, /* 9761-78 & 82 */
2451 { 0x1000, 0x2880 }, /* off, on (9761-82 rev.B) */ 2472 { 0x0000, 0x2880 }, /* 9761-82 rev.B */
2473 { 0x2000, 0x0800 }, /* 9761-83 */
2452 }; 2474 };
2475 unsigned short val = 0;
2453 2476
2454 /* shared Line-In */ 2477 val |= surr_on[ac97->spec.dev_flags][is_surround_on(ac97)];
2455 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x0408, 2478 val |= clfe_on[ac97->spec.dev_flags][is_clfe_on(ac97)];
2456 surr_vals[ac97->spec.dev_flags][is_shared_linein(ac97)]); 2479 val |= surr_shared[ac97->spec.dev_flags][is_shared_linein(ac97)];
2457 /* shared Mic */ 2480 val |= clfe_shared[ac97->spec.dev_flags][is_shared_micin(ac97)];
2458 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3880, 2481
2459 clfe_vals[ac97->spec.dev_flags][is_shared_micin(ac97)]); 2482 snd_ac97_update_bits(ac97, AC97_CM9761_MULTI_CHAN, 0x3c88, val);
2460} 2483}
2461 2484
2462static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = { 2485static const snd_kcontrol_new_t snd_ac97_cm9761_controls[] = {
@@ -2551,7 +2574,7 @@ int patch_cm9761(ac97_t *ac97)
2551 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808); 2574 snd_ac97_write_cache(ac97, AC97_MASTER, 0x8808);
2552 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808); 2575 snd_ac97_write_cache(ac97, AC97_PCM, 0x8808);
2553 2576
2554 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B */ 2577 ac97->spec.dev_flags = 0; /* 1 = model 82 revision B, 2 = model 83 */
2555 if (ac97->id == AC97_ID_CM9761_82) { 2578 if (ac97->id == AC97_ID_CM9761_82) {
2556 unsigned short tmp; 2579 unsigned short tmp;
2557 /* check page 1, reg 0x60 */ 2580 /* check page 1, reg 0x60 */
@@ -2560,7 +2583,8 @@ int patch_cm9761(ac97_t *ac97)
2560 tmp = snd_ac97_read(ac97, 0x60); 2583 tmp = snd_ac97_read(ac97, 0x60);
2561 ac97->spec.dev_flags = tmp & 1; /* revision B? */ 2584 ac97->spec.dev_flags = tmp & 1; /* revision B? */
2562 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val); 2585 snd_ac97_write_cache(ac97, AC97_INT_PAGING, val);
2563 } 2586 } else if (ac97->id == AC97_ID_CM9761_83)
2587 ac97->spec.dev_flags = 2;
2564 2588
2565 ac97->build_ops = &patch_cm9761_ops; 2589 ac97->build_ops = &patch_cm9761_ops;
2566 2590
diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c
index dd289b9512e1..ded13165d635 100644
--- a/sound/pci/ac97/ac97_pcm.c
+++ b/sound/pci/ac97/ac97_pcm.c
@@ -303,6 +303,15 @@ int snd_ac97_set_rate(ac97_t *ac97, int reg, unsigned int rate)
303 AC97_EA_DRA, dbl ? AC97_EA_DRA : 0); 303 AC97_EA_DRA, dbl ? AC97_EA_DRA : 0);
304 snd_ac97_update(ac97, reg, tmp & 0xffff); 304 snd_ac97_update(ac97, reg, tmp & 0xffff);
305 snd_ac97_read(ac97, reg); 305 snd_ac97_read(ac97, reg);
306 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE) {
307 /* Intel controllers require double rate data to be put in
308 * slots 7+8
309 */
310 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE,
311 AC97_GP_DRSS_MASK,
312 dbl ? AC97_GP_DRSS_78 : 0);
313 snd_ac97_read(ac97, AC97_GENERAL_PURPOSE);
314 }
306 return 0; 315 return 0;
307} 316}
308 317
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index d7d99a25c5e5..e72ccd1a004f 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -50,7 +50,7 @@
50#include "ad1889.h" 50#include "ad1889.h"
51#include "ac97/ac97_id.h" 51#include "ac97/ac97_id.h"
52 52
53#define AD1889_DRVVER "$Revision: 1.3 $" 53#define AD1889_DRVVER "$Revision: 1.4 $"
54 54
55MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>"); 55MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>");
56MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver"); 56MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver");
@@ -982,8 +982,7 @@ snd_ad1889_create(snd_card_t *card,
982 return 0; 982 return 0;
983 983
984free_and_ret: 984free_and_ret:
985 if (chip) 985 kfree(chip);
986 kfree(chip);
987 pci_disable_device(pci); 986 pci_disable_device(pci);
988 987
989 return err; 988 return err;
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index f35b558c29b2..4e76c4a636d9 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -45,23 +45,25 @@ MODULE_DESCRIPTION("ALI M5451");
45MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
46MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}"); 46MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}");
47 47
48static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 48static int index = SNDRV_DEFAULT_IDX1; /* Index */
49static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 49static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
50static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 50static int pcm_channels = 32;
51static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32}; 51static int spdif = 0;
52static int spdif[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
53 52
54module_param_array(index, int, NULL, 0444); 53module_param(index, int, 0444);
55MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio."); 54MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio.");
56module_param_array(id, charp, NULL, 0444); 55module_param(id, charp, 0444);
57MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio."); 56MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio.");
58module_param_array(enable, bool, NULL, 0444); 57module_param(pcm_channels, int, 0444);
59MODULE_PARM_DESC(enable, "Enable ALI 5451 PCI Audio.");
60module_param_array(pcm_channels, int, NULL, 0444);
61MODULE_PARM_DESC(pcm_channels, "PCM Channels"); 58MODULE_PARM_DESC(pcm_channels, "PCM Channels");
62module_param_array(spdif, bool, NULL, 0444); 59module_param(spdif, bool, 0444);
63MODULE_PARM_DESC(spdif, "Support SPDIF I/O"); 60MODULE_PARM_DESC(spdif, "Support SPDIF I/O");
64 61
62/* just for backward compatibility */
63static int enable;
64module_param(enable, bool, 0444);
65
66
65/* 67/*
66 * Debug part definitions 68 * Debug part definitions
67 */ 69 */
@@ -396,10 +398,8 @@ static int snd_ali_codec_ready( ali_t *codec,
396 res = snd_ali_5451_peek(codec,port); 398 res = snd_ali_5451_peek(codec,port);
397 if (! (res & 0x8000)) 399 if (! (res & 0x8000))
398 return 0; 400 return 0;
399 if (sched) { 401 if (sched)
400 set_current_state(TASK_UNINTERRUPTIBLE); 402 schedule_timeout_uninterruptible(1);
401 schedule_timeout(1);
402 }
403 } while (time_after_eq(end_time, jiffies)); 403 } while (time_after_eq(end_time, jiffies));
404 snd_ali_5451_poke(codec, port, res & ~0x8000); 404 snd_ali_5451_poke(codec, port, res & ~0x8000);
405 snd_printdd("ali_codec_ready: codec is not ready.\n "); 405 snd_printdd("ali_codec_ready: codec is not ready.\n ");
@@ -419,12 +419,10 @@ static int snd_ali_stimer_ready(ali_t *codec, int sched)
419 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); 419 dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
420 if (dwChk2 != dwChk1) 420 if (dwChk2 != dwChk1)
421 return 0; 421 return 0;
422 if (sched) { 422 if (sched)
423 set_current_state(TASK_UNINTERRUPTIBLE); 423 schedule_timeout_uninterruptible(1);
424 schedule_timeout(1);
425 }
426 } while (time_after_eq(end_time, jiffies)); 424 } while (time_after_eq(end_time, jiffies));
427 snd_printk("ali_stimer_read: stimer is not ready.\n"); 425 snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n");
428 return -EIO; 426 return -EIO;
429} 427}
430 428
@@ -436,7 +434,7 @@ static void snd_ali_codec_poke(ali_t *codec,int secondary,
436 unsigned int port = 0; 434 unsigned int port = 0;
437 435
438 if (reg >= 0x80) { 436 if (reg >= 0x80) {
439 snd_printk("ali_codec_poke: reg(%xh) invalid.\n", reg); 437 snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg);
440 return; 438 return;
441 } 439 }
442 440
@@ -465,7 +463,7 @@ static unsigned short snd_ali_codec_peek( ali_t *codec,
465 unsigned int port = 0; 463 unsigned int port = 0;
466 464
467 if (reg >= 0x80) { 465 if (reg >= 0x80) {
468 snd_printk("ali_codec_peek: reg(%xh) invalid.\n", reg); 466 snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg);
469 return ~0; 467 return ~0;
470 } 468 }
471 469
@@ -669,7 +667,7 @@ static int snd_ali_alloc_pcm_channel(ali_t *codec, int channel)
669 unsigned int idx = channel & 0x1f; 667 unsigned int idx = channel & 0x1f;
670 668
671 if (codec->synth.chcnt >= ALI_CHANNELS){ 669 if (codec->synth.chcnt >= ALI_CHANNELS){
672 snd_printk("ali_alloc_pcm_channel: no free channels.\n"); 670 snd_printk(KERN_ERR "ali_alloc_pcm_channel: no free channels.\n");
673 return -1; 671 return -1;
674 } 672 }
675 673
@@ -700,7 +698,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
700 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) { 698 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
701 return result; 699 return result;
702 } else { 700 } else {
703 snd_printk("ali_find_free_channel: record channel is busy now.\n"); 701 snd_printk(KERN_ERR "ali_find_free_channel: record channel is busy now.\n");
704 return -1; 702 return -1;
705 } 703 }
706 } 704 }
@@ -712,7 +710,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
712 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) { 710 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
713 return result; 711 return result;
714 } else { 712 } else {
715 snd_printk("ali_find_free_channel: S/PDIF out channel is in busy now.\n"); 713 snd_printk(KERN_ERR "ali_find_free_channel: S/PDIF out channel is in busy now.\n");
716 } 714 }
717 } 715 }
718 716
@@ -720,7 +718,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
720 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) 718 if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0)
721 return result; 719 return result;
722 } 720 }
723 snd_printk("ali_find_free_channel: no free channels.\n"); 721 snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n");
724 return -1; 722 return -1;
725} 723}
726 724
@@ -734,7 +732,7 @@ static void snd_ali_free_channel_pcm(ali_t *codec, int channel)
734 return; 732 return;
735 733
736 if (!(codec->synth.chmap & (1 << idx))) { 734 if (!(codec->synth.chmap & (1 << idx))) {
737 snd_printk("ali_free_channel_pcm: channel %d is not in use.\n",channel); 735 snd_printk(KERN_ERR "ali_free_channel_pcm: channel %d is not in use.\n",channel);
738 return; 736 return;
739 } else { 737 } else {
740 codec->synth.chmap &= ~(1 << idx); 738 codec->synth.chmap &= ~(1 << idx);
@@ -796,7 +794,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec)
796 } 794 }
797 795
798 if (count > 50000) { 796 if (count > 50000) {
799 snd_printk("ali_detect_spdif_rate: timeout!\n"); 797 snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
800 return; 798 return;
801 } 799 }
802 800
@@ -809,7 +807,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec)
809 } 807 }
810 808
811 if (count > 50000) { 809 if (count > 50000) {
812 snd_printk("ali_detect_spdif_rate: timeout!\n"); 810 snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
813 return; 811 return;
814 } 812 }
815 813
@@ -1077,7 +1075,7 @@ static snd_ali_voice_t *snd_ali_alloc_voice(ali_t * codec, int type, int rec, in
1077 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : 1075 idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) :
1078 snd_ali_find_free_channel(codec,rec); 1076 snd_ali_find_free_channel(codec,rec);
1079 if(idx < 0) { 1077 if(idx < 0) {
1080 snd_printk("ali_alloc_voice: err.\n"); 1078 snd_printk(KERN_ERR "ali_alloc_voice: err.\n");
1081 spin_unlock_irqrestore(&codec->voice_alloc, flags); 1079 spin_unlock_irqrestore(&codec->voice_alloc, flags);
1082 return NULL; 1080 return NULL;
1083 } 1081 }
@@ -1479,13 +1477,13 @@ static int snd_ali_prepare(snd_pcm_substream_t * substream)
1479 } 1477 }
1480 rate = snd_ali_get_spdif_in_rate(codec); 1478 rate = snd_ali_get_spdif_in_rate(codec);
1481 if (rate == 0) { 1479 if (rate == 0) {
1482 snd_printk("ali_capture_preapre: spdif rate detect err!\n"); 1480 snd_printk(KERN_WARNING "ali_capture_preapre: spdif rate detect err!\n");
1483 rate = 48000; 1481 rate = 48000;
1484 } 1482 }
1485 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); 1483 bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
1486 if (bValue & 0x10) { 1484 if (bValue & 0x10) {
1487 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); 1485 outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL));
1488 printk("clear SPDIF parity error flag.\n"); 1486 printk(KERN_WARNING "clear SPDIF parity error flag.\n");
1489 } 1487 }
1490 1488
1491 if (rate != 48000) 1489 if (rate != 48000)
@@ -1795,6 +1793,7 @@ struct ali_pcm_description {
1795 unsigned int capture_num; 1793 unsigned int capture_num;
1796 snd_pcm_ops_t *playback_ops; 1794 snd_pcm_ops_t *playback_ops;
1797 snd_pcm_ops_t *capture_ops; 1795 snd_pcm_ops_t *capture_ops;
1796 unsigned short class;
1798}; 1797};
1799 1798
1800 1799
@@ -1813,12 +1812,11 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
1813 err = snd_pcm_new(codec->card, desc->name, device, 1812 err = snd_pcm_new(codec->card, desc->name, device,
1814 desc->playback_num, desc->capture_num, &pcm); 1813 desc->playback_num, desc->capture_num, &pcm);
1815 if (err < 0) { 1814 if (err < 0) {
1816 snd_printk("snd_ali_pcm: err called snd_pcm_new.\n"); 1815 snd_printk(KERN_ERR "snd_ali_pcm: err called snd_pcm_new.\n");
1817 return err; 1816 return err;
1818 } 1817 }
1819 pcm->private_data = codec; 1818 pcm->private_data = codec;
1820 pcm->private_free = snd_ali_pcm_free; 1819 pcm->private_free = snd_ali_pcm_free;
1821 pcm->info_flags = 0;
1822 if (desc->playback_ops) 1820 if (desc->playback_ops)
1823 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, desc->playback_ops); 1821 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, desc->playback_ops);
1824 if (desc->capture_ops) 1822 if (desc->capture_ops)
@@ -1828,6 +1826,7 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
1828 snd_dma_pci_data(codec->pci), 64*1024, 128*1024); 1826 snd_dma_pci_data(codec->pci), 64*1024, 128*1024);
1829 1827
1830 pcm->info_flags = 0; 1828 pcm->info_flags = 0;
1829 pcm->dev_class = desc->class;
1831 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1830 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
1832 strcpy(pcm->name, desc->name); 1831 strcpy(pcm->name, desc->name);
1833 codec->pcm[0] = pcm; 1832 codec->pcm[0] = pcm;
@@ -1836,7 +1835,7 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
1836 1835
1837static struct ali_pcm_description ali_pcms[] = { 1836static struct ali_pcm_description ali_pcms[] = {
1838 { "ALI 5451", ALI_CHANNELS, 1, &snd_ali_playback_ops, &snd_ali_capture_ops }, 1837 { "ALI 5451", ALI_CHANNELS, 1, &snd_ali_playback_ops, &snd_ali_capture_ops },
1839 { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops } 1838 { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops, SNDRV_PCM_CLASS_MODEM }
1840}; 1839};
1841 1840
1842static int __devinit snd_ali_build_pcms(ali_t *codec) 1841static int __devinit snd_ali_build_pcms(ali_t *codec)
@@ -1991,7 +1990,7 @@ static int __devinit snd_ali_mixer(ali_t * codec)
1991 for ( i = 0 ; i < codec->num_of_codecs ; i++) { 1990 for ( i = 0 ; i < codec->num_of_codecs ; i++) {
1992 ac97.num = i; 1991 ac97.num = i;
1993 if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i])) < 0) { 1992 if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i])) < 0) {
1994 snd_printk("ali mixer %d creating error.\n", i); 1993 snd_printk(KERN_ERR "ali mixer %d creating error.\n", i);
1995 if(i == 0) 1994 if(i == 0)
1996 return err; 1995 return err;
1997 codec->num_of_codecs = 1; 1996 codec->num_of_codecs = 1;
@@ -2125,7 +2124,7 @@ static int snd_ali_chip_init(ali_t *codec)
2125 snd_ali_printk("chip initializing ... \n"); 2124 snd_ali_printk("chip initializing ... \n");
2126 2125
2127 if (snd_ali_reset_5451(codec)) { 2126 if (snd_ali_reset_5451(codec)) {
2128 snd_printk("ali_chip_init: reset 5451 error.\n"); 2127 snd_printk(KERN_ERR "ali_chip_init: reset 5451 error.\n");
2129 return -1; 2128 return -1;
2130 } 2129 }
2131 2130
@@ -2200,7 +2199,7 @@ static int __devinit snd_ali_resources(ali_t *codec)
2200 codec->port = pci_resource_start(codec->pci, 0); 2199 codec->port = pci_resource_start(codec->pci, 0);
2201 2200
2202 if (request_irq(codec->pci->irq, snd_ali_card_interrupt, SA_INTERRUPT|SA_SHIRQ, "ALI 5451", (void *)codec)) { 2201 if (request_irq(codec->pci->irq, snd_ali_card_interrupt, SA_INTERRUPT|SA_SHIRQ, "ALI 5451", (void *)codec)) {
2203 snd_printk("Unable to request irq.\n"); 2202 snd_printk(KERN_ERR "Unable to request irq.\n");
2204 return -EBUSY; 2203 return -EBUSY;
2205 } 2204 }
2206 codec->irq = codec->pci->irq; 2205 codec->irq = codec->pci->irq;
@@ -2240,7 +2239,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
2240 /* check, if we can restrict PCI DMA transfers to 31 bits */ 2239 /* check, if we can restrict PCI DMA transfers to 31 bits */
2241 if (pci_set_dma_mask(pci, 0x7fffffff) < 0 || 2240 if (pci_set_dma_mask(pci, 0x7fffffff) < 0 ||
2242 pci_set_consistent_dma_mask(pci, 0x7fffffff) < 0) { 2241 pci_set_consistent_dma_mask(pci, 0x7fffffff) < 0) {
2243 snd_printk("architecture does not support 31bit PCI busmaster DMA\n"); 2242 snd_printk(KERN_ERR "architecture does not support 31bit PCI busmaster DMA\n");
2244 pci_disable_device(pci); 2243 pci_disable_device(pci);
2245 return -ENXIO; 2244 return -ENXIO;
2246 } 2245 }
@@ -2329,7 +2328,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
2329 } 2328 }
2330 2329
2331 if ((err = snd_ali_chip_init(codec)) < 0) { 2330 if ((err = snd_ali_chip_init(codec)) < 0) {
2332 snd_printk("ali create: chip init error.\n"); 2331 snd_printk(KERN_ERR "ali create: chip init error.\n");
2333 return err; 2332 return err;
2334 } 2333 }
2335 2334
@@ -2352,25 +2351,17 @@ static int __devinit snd_ali_create(snd_card_t * card,
2352static int __devinit snd_ali_probe(struct pci_dev *pci, 2351static int __devinit snd_ali_probe(struct pci_dev *pci,
2353 const struct pci_device_id *pci_id) 2352 const struct pci_device_id *pci_id)
2354{ 2353{
2355 static int dev;
2356 snd_card_t *card; 2354 snd_card_t *card;
2357 ali_t *codec; 2355 ali_t *codec;
2358 int err; 2356 int err;
2359 2357
2360 snd_ali_printk("probe ...\n"); 2358 snd_ali_printk("probe ...\n");
2361 2359
2362 if (dev >= SNDRV_CARDS) 2360 card = snd_card_new(index, id, THIS_MODULE, 0);
2363 return -ENODEV;
2364 if (!enable[dev]) {
2365 dev++;
2366 return -ENOENT;
2367 }
2368
2369 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2370 if (card == NULL) 2361 if (card == NULL)
2371 return -ENOMEM; 2362 return -ENOMEM;
2372 2363
2373 if ((err = snd_ali_create(card, pci, pcm_channels[dev], spdif[dev], &codec)) < 0) { 2364 if ((err = snd_ali_create(card, pci, pcm_channels, spdif, &codec)) < 0) {
2374 snd_card_free(card); 2365 snd_card_free(card);
2375 return err; 2366 return err;
2376 } 2367 }
@@ -2401,7 +2392,6 @@ static int __devinit snd_ali_probe(struct pci_dev *pci,
2401 return err; 2392 return err;
2402 } 2393 }
2403 pci_set_drvdata(pci, card); 2394 pci_set_drvdata(pci, card);
2404 dev++;
2405 return 0; 2395 return 0;
2406} 2396}
2407 2397
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index 196ec1c61bb4..7c61561f297f 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -594,8 +594,7 @@ static int __devinit snd_als4000_create_gameport(snd_card_als4000_t *acard, int
594 acard->gameport = gp = gameport_allocate_port(); 594 acard->gameport = gp = gameport_allocate_port();
595 if (!gp) { 595 if (!gp) {
596 printk(KERN_ERR "als4000: cannot allocate memory for gameport\n"); 596 printk(KERN_ERR "als4000: cannot allocate memory for gameport\n");
597 release_resource(r); 597 release_and_free_resource(r);
598 kfree_nocheck(r);
599 return -ENOMEM; 598 return -ENOMEM;
600 } 599 }
601 600
@@ -622,8 +621,7 @@ static void snd_als4000_free_gameport(snd_card_als4000_t *acard)
622 acard->gameport = NULL; 621 acard->gameport = NULL;
623 622
624 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */ 623 snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */
625 release_resource(r); 624 release_and_free_resource(r);
626 kfree_nocheck(r);
627 } 625 }
628} 626}
629#else 627#else
@@ -669,7 +667,7 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
669 /* check, if we can restrict PCI DMA transfers to 24 bits */ 667 /* check, if we can restrict PCI DMA transfers to 24 bits */
670 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 668 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
671 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 669 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
672 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 670 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
673 pci_disable_device(pci); 671 pci_disable_device(pci);
674 return -ENXIO; 672 return -ENXIO;
675 } 673 }
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 241eacf1e652..f5dad9248e39 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -39,26 +39,27 @@ MODULE_DESCRIPTION("ATI IXP AC97 controller");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400}}"); 40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250/300/400}}");
41 41
42static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 42static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
43static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 43static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
44static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 44static int ac97_clock = 48000;
45static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000}; 45static char *ac97_quirk;
46static char *ac97_quirk[SNDRV_CARDS]; 46static int spdif_aclink = 1;
47static int spdif_aclink[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 47
48 48module_param(index, int, 0444);
49module_param_array(index, int, NULL, 0444);
50MODULE_PARM_DESC(index, "Index value for ATI IXP controller."); 49MODULE_PARM_DESC(index, "Index value for ATI IXP controller.");
51module_param_array(id, charp, NULL, 0444); 50module_param(id, charp, 0444);
52MODULE_PARM_DESC(id, "ID string for ATI IXP controller."); 51MODULE_PARM_DESC(id, "ID string for ATI IXP controller.");
53module_param_array(enable, bool, NULL, 0444); 52module_param(ac97_clock, int, 0444);
54MODULE_PARM_DESC(enable, "Enable audio part of ATI IXP controller.");
55module_param_array(ac97_clock, int, NULL, 0444);
56MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 53MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
57module_param_array(ac97_quirk, charp, NULL, 0444); 54module_param(ac97_quirk, charp, 0444);
58MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 55MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
59module_param_array(spdif_aclink, bool, NULL, 0444); 56module_param(spdif_aclink, bool, 0444);
60MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link."); 57MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
61 58
59/* just for backward compatibility */
60static int enable;
61module_param(enable, bool, 0444);
62
62 63
63/* 64/*
64 */ 65 */
@@ -329,8 +330,7 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg,
329 330
330/* delay for one tick */ 331/* delay for one tick */
331#define do_delay() do { \ 332#define do_delay() do { \
332 set_current_state(TASK_UNINTERRUPTIBLE); \ 333 schedule_timeout_uninterruptible(1); \
333 schedule_timeout(1); \
334} while (0) 334} while (0)
335 335
336 336
@@ -1372,7 +1372,6 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock, const char
1372 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 1372 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
1373 return err; 1373 return err;
1374 pbus->clock = clock; 1374 pbus->clock = clock;
1375 pbus->shared_type = AC97_SHARED_TYPE_ATIIXP; /* shared with modem driver */
1376 chip->ac97_bus = pbus; 1375 chip->ac97_bus = pbus;
1377 1376
1378 codec_count = 0; 1377 codec_count = 0;
@@ -1579,26 +1578,18 @@ static int __devinit snd_atiixp_create(snd_card_t *card,
1579static int __devinit snd_atiixp_probe(struct pci_dev *pci, 1578static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1580 const struct pci_device_id *pci_id) 1579 const struct pci_device_id *pci_id)
1581{ 1580{
1582 static int dev;
1583 snd_card_t *card; 1581 snd_card_t *card;
1584 atiixp_t *chip; 1582 atiixp_t *chip;
1585 unsigned char revision; 1583 unsigned char revision;
1586 int err; 1584 int err;
1587 1585
1588 if (dev >= SNDRV_CARDS) 1586 card = snd_card_new(index, id, THIS_MODULE, 0);
1589 return -ENODEV;
1590 if (!enable[dev]) {
1591 dev++;
1592 return -ENOENT;
1593 }
1594
1595 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1596 if (card == NULL) 1587 if (card == NULL)
1597 return -ENOMEM; 1588 return -ENOMEM;
1598 1589
1599 pci_read_config_byte(pci, PCI_REVISION_ID, &revision); 1590 pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
1600 1591
1601 strcpy(card->driver, spdif_aclink[dev] ? "ATIIXP" : "ATIIXP-SPDMA"); 1592 strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA");
1602 strcpy(card->shortname, "ATI IXP"); 1593 strcpy(card->shortname, "ATI IXP");
1603 if ((err = snd_atiixp_create(card, pci, &chip)) < 0) 1594 if ((err = snd_atiixp_create(card, pci, &chip)) < 0)
1604 goto __error; 1595 goto __error;
@@ -1606,9 +1597,9 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1606 if ((err = snd_atiixp_aclink_reset(chip)) < 0) 1597 if ((err = snd_atiixp_aclink_reset(chip)) < 0)
1607 goto __error; 1598 goto __error;
1608 1599
1609 chip->spdif_over_aclink = spdif_aclink[dev]; 1600 chip->spdif_over_aclink = spdif_aclink;
1610 1601
1611 if ((err = snd_atiixp_mixer_new(chip, ac97_clock[dev], ac97_quirk[dev])) < 0) 1602 if ((err = snd_atiixp_mixer_new(chip, ac97_clock, ac97_quirk)) < 0)
1612 goto __error; 1603 goto __error;
1613 1604
1614 if ((err = snd_atiixp_pcm_new(chip)) < 0) 1605 if ((err = snd_atiixp_pcm_new(chip)) < 0)
@@ -1629,7 +1620,6 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1629 goto __error; 1620 goto __error;
1630 1621
1631 pci_set_drvdata(pci, card); 1622 pci_set_drvdata(pci, card);
1632 dev++;
1633 return 0; 1623 return 0;
1634 1624
1635 __error: 1625 __error:
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index c1a239a4dac6..0cf202079571 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -39,20 +39,21 @@ MODULE_DESCRIPTION("ATI IXP MC97 controller");
39MODULE_LICENSE("GPL"); 39MODULE_LICENSE("GPL");
40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250}}"); 40MODULE_SUPPORTED_DEVICE("{{ATI,IXP150/200/250}}");
41 41
42static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */ 42static int index = -2; /* Exclude the first card */
43static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 43static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
44static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 44static int ac97_clock = 48000;
45static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000};
46 45
47module_param_array(index, int, NULL, 0444); 46module_param(index, int, 0444);
48MODULE_PARM_DESC(index, "Index value for ATI IXP controller."); 47MODULE_PARM_DESC(index, "Index value for ATI IXP controller.");
49module_param_array(id, charp, NULL, 0444); 48module_param(id, charp, 0444);
50MODULE_PARM_DESC(id, "ID string for ATI IXP controller."); 49MODULE_PARM_DESC(id, "ID string for ATI IXP controller.");
51module_param_array(enable, bool, NULL, 0444); 50module_param(ac97_clock, int, 0444);
52MODULE_PARM_DESC(enable, "Enable audio part of ATI IXP controller.");
53module_param_array(ac97_clock, int, NULL, 0444);
54MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 51MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
55 52
53/* just for backward compatibility */
54static int enable;
55module_param(enable, bool, 0444);
56
56 57
57/* 58/*
58 */ 59 */
@@ -306,8 +307,7 @@ static int snd_atiixp_update_bits(atiixp_t *chip, unsigned int reg,
306 307
307/* delay for one tick */ 308/* delay for one tick */
308#define do_delay() do { \ 309#define do_delay() do { \
309 set_current_state(TASK_UNINTERRUPTIBLE); \ 310 schedule_timeout_uninterruptible(1); \
310 schedule_timeout(1); \
311} while (0) 311} while (0)
312 312
313 313
@@ -989,6 +989,7 @@ static int __devinit snd_atiixp_pcm_new(atiixp_t *chip)
989 return err; 989 return err;
990 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_playback_ops); 990 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_atiixp_playback_ops);
991 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_atiixp_capture_ops); 991 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_atiixp_capture_ops);
992 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
992 pcm->private_data = chip; 993 pcm->private_data = chip;
993 strcpy(pcm->name, "ATI IXP MC97"); 994 strcpy(pcm->name, "ATI IXP MC97");
994 chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm; 995 chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm;
@@ -1067,7 +1068,6 @@ static int __devinit snd_atiixp_mixer_new(atiixp_t *chip, int clock)
1067 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 1068 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
1068 return err; 1069 return err;
1069 pbus->clock = clock; 1070 pbus->clock = clock;
1070 pbus->shared_type = AC97_SHARED_TYPE_ATIIXP; /* shared with audio driver */
1071 chip->ac97_bus = pbus; 1071 chip->ac97_bus = pbus;
1072 1072
1073 codec_count = 0; 1073 codec_count = 0;
@@ -1256,20 +1256,12 @@ static int __devinit snd_atiixp_create(snd_card_t *card,
1256static int __devinit snd_atiixp_probe(struct pci_dev *pci, 1256static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1257 const struct pci_device_id *pci_id) 1257 const struct pci_device_id *pci_id)
1258{ 1258{
1259 static int dev;
1260 snd_card_t *card; 1259 snd_card_t *card;
1261 atiixp_t *chip; 1260 atiixp_t *chip;
1262 unsigned char revision; 1261 unsigned char revision;
1263 int err; 1262 int err;
1264 1263
1265 if (dev >= SNDRV_CARDS) 1264 card = snd_card_new(index, id, THIS_MODULE, 0);
1266 return -ENODEV;
1267 if (!enable[dev]) {
1268 dev++;
1269 return -ENOENT;
1270 }
1271
1272 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1273 if (card == NULL) 1265 if (card == NULL)
1274 return -ENOMEM; 1266 return -ENOMEM;
1275 1267
@@ -1283,7 +1275,7 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1283 if ((err = snd_atiixp_aclink_reset(chip)) < 0) 1275 if ((err = snd_atiixp_aclink_reset(chip)) < 0)
1284 goto __error; 1276 goto __error;
1285 1277
1286 if ((err = snd_atiixp_mixer_new(chip, ac97_clock[dev])) < 0) 1278 if ((err = snd_atiixp_mixer_new(chip, ac97_clock)) < 0)
1287 goto __error; 1279 goto __error;
1288 1280
1289 if ((err = snd_atiixp_pcm_new(chip)) < 0) 1281 if ((err = snd_atiixp_pcm_new(chip)) < 0)
@@ -1302,7 +1294,6 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1302 goto __error; 1294 goto __error;
1303 1295
1304 pci_set_drvdata(pci, card); 1296 pci_set_drvdata(pci, card);
1305 dev++;
1306 return 0; 1297 return 0;
1307 1298
1308 __error: 1299 __error:
diff --git a/sound/pci/au88x0/au8810.h b/sound/pci/au88x0/au8810.h
index 3837d2ba5e67..5d69c31fe3f4 100644
--- a/sound/pci/au88x0/au8810.h
+++ b/sound/pci/au88x0/au8810.h
@@ -178,11 +178,6 @@
178#define EN_SPDIF 0x000c0000 178#define EN_SPDIF 0x000c0000
179 179
180#define VORTEX_CODEC_CHN 0x29080 180#define VORTEX_CODEC_CHN 0x29080
181#define VORTEX_CODEC_WRITE 0x00800000
182#define VORTEX_CODEC_ADDSHIFT 16
183#define VORTEX_CODEC_ADDMASK 0x7f0000 /* 0x000f0000 */
184#define VORTEX_CODEC_DATSHIFT 0
185#define VORTEX_CODEC_DATMASK 0xffff
186#define VORTEX_CODEC_IO 0x29188 181#define VORTEX_CODEC_IO 0x29188
187 182
188/* SPDIF */ 183/* SPDIF */
diff --git a/sound/pci/au88x0/au8820.h b/sound/pci/au88x0/au8820.h
index be8022e78714..abbe85e4f7a9 100644
--- a/sound/pci/au88x0/au8820.h
+++ b/sound/pci/au88x0/au8820.h
@@ -162,11 +162,6 @@
162#define EN_SPORT 0x00030000 162#define EN_SPORT 0x00030000
163#define EN_SPDIF 0x000c0000 163#define EN_SPDIF 0x000c0000
164#define VORTEX_CODEC_CHN 0x11880 164#define VORTEX_CODEC_CHN 0x11880
165#define VORTEX_CODEC_WRITE 0x00800000
166#define VORTEX_CODEC_ADDSHIFT 16
167#define VORTEX_CODEC_ADDMASK 0x7f0000 /* 0x000f0000 */
168#define VORTEX_CODEC_DATSHIFT 0
169#define VORTEX_CODEC_DATMASK 0xffff
170#define VORTEX_CODEC_IO 0x11988 165#define VORTEX_CODEC_IO 0x11988
171 166
172#define VORTEX_SPDIF_FLAGS 0x1005c /* FIXME */ 167#define VORTEX_SPDIF_FLAGS 0x1005c /* FIXME */
diff --git a/sound/pci/au88x0/au8830.h b/sound/pci/au88x0/au8830.h
index aa77826b5e59..04ece1b1c218 100644
--- a/sound/pci/au88x0/au8830.h
+++ b/sound/pci/au88x0/au8830.h
@@ -194,11 +194,6 @@
194 194
195#define VORTEX_CODEC_CTRL 0x29184 195#define VORTEX_CODEC_CTRL 0x29184
196#define VORTEX_CODEC_IO 0x29188 196#define VORTEX_CODEC_IO 0x29188
197#define VORTEX_CODEC_WRITE 0x00800000
198#define VORTEX_CODEC_ADDSHIFT 16
199#define VORTEX_CODEC_ADDMASK 0x7f0000 /* 0x000f0000 */
200#define VORTEX_CODEC_DATSHIFT 0
201#define VORTEX_CODEC_DATMASK 0xffff
202 197
203#define VORTEX_CODEC_SPORTCTRL 0x2918c 198#define VORTEX_CODEC_SPORTCTRL 0x2918c
204 199
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index 04b695d6fd48..6af3b13f2fd1 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -303,7 +303,7 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
303 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH, 303 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_VORTEX_SYNTH,
304 sizeof(snd_vortex_synth_arg_t), &wave) < 0 304 sizeof(snd_vortex_synth_arg_t), &wave) < 0
305 || wave == NULL) { 305 || wave == NULL) {
306 snd_printk("Can't initialize Aureal wavetable synth\n"); 306 snd_printk(KERN_ERR "Can't initialize Aureal wavetable synth\n");
307 } else { 307 } else {
308 snd_vortex_synth_arg_t *arg; 308 snd_vortex_synth_arg_t *arg;
309 309
diff --git a/sound/pci/au88x0/au88x0.h b/sound/pci/au88x0/au88x0.h
index ee1ede1979f6..b1197cfab3fb 100644
--- a/sound/pci/au88x0/au88x0.h
+++ b/sound/pci/au88x0/au88x0.h
@@ -79,6 +79,14 @@
79#define VORTEX_RESOURCE_A3D 0x00000004 79#define VORTEX_RESOURCE_A3D 0x00000004
80#define VORTEX_RESOURCE_LAST 0x00000005 80#define VORTEX_RESOURCE_LAST 0x00000005
81 81
82/* codec io: VORTEX_CODEC_IO bits */
83#define VORTEX_CODEC_ID_SHIFT 24
84#define VORTEX_CODEC_WRITE 0x00800000
85#define VORTEX_CODEC_ADDSHIFT 16
86#define VORTEX_CODEC_ADDMASK 0x7f0000
87#define VORTEX_CODEC_DATSHIFT 0
88#define VORTEX_CODEC_DATMASK 0xffff
89
82/* Check for SDAC bit in "Extended audio ID" AC97 register */ 90/* Check for SDAC bit in "Extended audio ID" AC97 register */
83//#define VORTEX_IS_QUAD(x) (((x)->codec == NULL) ? 0 : ((x)->codec->ext_id&0x80)) 91//#define VORTEX_IS_QUAD(x) (((x)->codec == NULL) ? 0 : ((x)->codec->ext_id&0x80))
84#define VORTEX_IS_QUAD(x) ((x)->isquad) 92#define VORTEX_IS_QUAD(x) ((x)->isquad)
diff --git a/sound/pci/au88x0/au88x0_a3d.c b/sound/pci/au88x0/au88x0_a3d.c
index 9ea2ba7bc3c8..d5755db5141f 100644
--- a/sound/pci/au88x0/au88x0_a3d.c
+++ b/sound/pci/au88x0/au88x0_a3d.c
@@ -488,7 +488,7 @@ static void a3dsrc_ZeroStateA3D(a3dsrc_t * a)
488 int i, var, var2; 488 int i, var, var2;
489 489
490 if ((a->vortex) == NULL) { 490 if ((a->vortex) == NULL) {
491 printk("vortex: ZeroStateA3D: ERROR: a->vortex is NULL\n"); 491 printk(KERN_ERR "vortex: ZeroStateA3D: ERROR: a->vortex is NULL\n");
492 return; 492 return;
493 } 493 }
494 494
diff --git a/sound/pci/au88x0/au88x0_core.c b/sound/pci/au88x0/au88x0_core.c
index f0eda4bbbb39..5905188d06b5 100644
--- a/sound/pci/au88x0/au88x0_core.c
+++ b/sound/pci/au88x0/au88x0_core.c
@@ -2033,7 +2033,7 @@ vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out, int restype)
2033 } 2033 }
2034 } 2034 }
2035 } 2035 }
2036 printk("vortex: FATAL: ResManager: resource type %d exhausted.\n", restype); 2036 printk(KERN_ERR "vortex: FATAL: ResManager: resource type %d exhausted.\n", restype);
2037 return -ENOMEM; 2037 return -ENOMEM;
2038} 2038}
2039 2039
@@ -2165,7 +2165,7 @@ vortex_adb_allocroute(vortex_t * vortex, int dma, int nr_ch, int dir, int type)
2165 memset(stream->resources, 0, 2165 memset(stream->resources, 0,
2166 sizeof(unsigned char) * 2166 sizeof(unsigned char) *
2167 VORTEX_RESOURCE_LAST); 2167 VORTEX_RESOURCE_LAST);
2168 printk("vortex: out of A3D sources. Sorry\n"); 2168 printk(KERN_ERR "vortex: out of A3D sources. Sorry\n");
2169 return -EBUSY; 2169 return -EBUSY;
2170 } 2170 }
2171 /* (De)Initialize A3D hardware source. */ 2171 /* (De)Initialize A3D hardware source. */
@@ -2532,7 +2532,8 @@ vortex_codec_write(ac97_t * codec, unsigned short addr, unsigned short data)
2532 hwwrite(card->mmio, VORTEX_CODEC_IO, 2532 hwwrite(card->mmio, VORTEX_CODEC_IO,
2533 ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) | 2533 ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) |
2534 ((data << VORTEX_CODEC_DATSHIFT) & VORTEX_CODEC_DATMASK) | 2534 ((data << VORTEX_CODEC_DATSHIFT) & VORTEX_CODEC_DATMASK) |
2535 VORTEX_CODEC_WRITE); 2535 VORTEX_CODEC_WRITE |
2536 (codec->num << VORTEX_CODEC_ID_SHIFT) );
2536 2537
2537 /* Flush Caches. */ 2538 /* Flush Caches. */
2538 hwread(card->mmio, VORTEX_CODEC_IO); 2539 hwread(card->mmio, VORTEX_CODEC_IO);
@@ -2554,7 +2555,8 @@ static unsigned short vortex_codec_read(ac97_t * codec, unsigned short addr)
2554 } 2555 }
2555 } 2556 }
2556 /* set up read address */ 2557 /* set up read address */
2557 read_addr = ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK); 2558 read_addr = ((addr << VORTEX_CODEC_ADDSHIFT) & VORTEX_CODEC_ADDMASK) |
2559 (codec->num << VORTEX_CODEC_ID_SHIFT) ;
2558 hwwrite(card->mmio, VORTEX_CODEC_IO, read_addr); 2560 hwwrite(card->mmio, VORTEX_CODEC_IO, read_addr);
2559 2561
2560 /* wait for address */ 2562 /* wait for address */
diff --git a/sound/pci/au88x0/au88x0_eq.c b/sound/pci/au88x0/au88x0_eq.c
index 53b47a42c7d8..9d933cc0ea0b 100644
--- a/sound/pci/au88x0/au88x0_eq.c
+++ b/sound/pci/au88x0/au88x0_eq.c
@@ -854,7 +854,7 @@ snd_vortex_peaks_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
854 854
855 vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count); 855 vortex_Eqlzr_GetAllPeaks(vortex, peaks, &count);
856 if (count != 20) { 856 if (count != 20) {
857 printk("vortex: peak count error 20 != %d \n", count); 857 printk(KERN_ERR "vortex: peak count error 20 != %d \n", count);
858 return -1; 858 return -1;
859 } 859 }
860 for (i = 0; i < 20; i++) 860 for (i = 0; i < 20; i++)
diff --git a/sound/pci/au88x0/au88x0_synth.c b/sound/pci/au88x0/au88x0_synth.c
index 400417d34609..65f375bad43a 100644
--- a/sound/pci/au88x0/au88x0_synth.c
+++ b/sound/pci/au88x0/au88x0_synth.c
@@ -90,7 +90,7 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
90 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0); 90 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0);
91 91
92 temp = hwread(vortex->mmio, WT_PARM(wt, 3)); 92 temp = hwread(vortex->mmio, WT_PARM(wt, 3));
93 printk("vortex: WT PARM3: %x\n", temp); 93 printk(KERN_DEBUG "vortex: WT PARM3: %x\n", temp);
94 //hwwrite(vortex->mmio, WT_PARM(wt, 3), temp); 94 //hwwrite(vortex->mmio, WT_PARM(wt, 3), temp);
95 95
96 hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0); 96 hwwrite(vortex->mmio, WT_DELAY(wt, 0), 0);
@@ -98,7 +98,7 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
98 hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0); 98 hwwrite(vortex->mmio, WT_DELAY(wt, 2), 0);
99 hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0); 99 hwwrite(vortex->mmio, WT_DELAY(wt, 3), 0);
100 100
101 printk("vortex: WT GMODE: %x\n", hwread(vortex->mmio, WT_GMODE(wt))); 101 printk(KERN_DEBUG "vortex: WT GMODE: %x\n", hwread(vortex->mmio, WT_GMODE(wt)));
102 102
103 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff); 103 hwwrite(vortex->mmio, WT_PARM(wt, 2), 0xffffffff);
104 hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810); 104 hwwrite(vortex->mmio, WT_PARM(wt, 3), 0xcff1c810);
@@ -106,7 +106,7 @@ static int vortex_wt_allocroute(vortex_t * vortex, int wt, int nr_ch)
106 voice->parm0 = voice->parm1 = 0xcfb23e2f; 106 voice->parm0 = voice->parm1 = 0xcfb23e2f;
107 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0); 107 hwwrite(vortex->mmio, WT_PARM(wt, 0), voice->parm0);
108 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1); 108 hwwrite(vortex->mmio, WT_PARM(wt, 1), voice->parm1);
109 printk("vortex: WT GMODE 2 : %x\n", hwread(vortex->mmio, WT_GMODE(wt))); 109 printk(KERN_DEBUG "vortex: WT GMODE 2 : %x\n", hwread(vortex->mmio, WT_GMODE(wt)));
110 return 0; 110 return 0;
111} 111}
112 112
@@ -203,7 +203,7 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
203 } 203 }
204 } else { 204 } else {
205 if (wt >= NR_WT) { 205 if (wt >= NR_WT) {
206 printk("vortex: WT SetReg: voice out of range\n"); 206 printk(KERN_ERR "vortex: WT SetReg: voice out of range\n");
207 return 0; 207 return 0;
208 } 208 }
209 } 209 }
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index d5261bdec583..da99b1be2e8f 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168). 2 * azt3328.c - driver for Aztech AZF3328 based soundcards (e.g. PCI168).
3 * Copyright (C) 2002 by Andreas Mohr <hw7oshyuv3001@sneakemail.com> 3 * Copyright (C) 2002, 2005 by Andreas Mohr <andi AT lisas.de>
4 * 4 *
5 * Framework borrowed from Bart Hartgers's als4000.c. 5 * Framework borrowed from Bart Hartgers's als4000.c.
6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801), 6 * Driver developed on PCI168 AP(W) version (PCI rev. 10, subsystem ID 1801),
@@ -46,7 +46,7 @@
46 * - MPU401 (+ legacy address support) FIXME: how to enable legacy addr?? 46 * - MPU401 (+ legacy address support) FIXME: how to enable legacy addr??
47 * - game port (legacy address support) 47 * - game port (legacy address support)
48 * - built-in General DirectX timer having a 20 bits counter 48 * - built-in General DirectX timer having a 20 bits counter
49 * with 1us resolution (FIXME: where is it?) 49 * with 1us resolution (see below!)
50 * - I2S serial port for external DAC 50 * - I2S serial port for external DAC
51 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI 51 * - supports 33MHz PCI spec 2.1, PCI power management 1.0, compliant with ACPI
52 * - supports hardware volume control 52 * - supports hardware volume control
@@ -55,13 +55,23 @@
55 * required for Microsoft's logo compliance (FIXME: where?) 55 * required for Microsoft's logo compliance (FIXME: where?)
56 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms 56 * - PCI168 AP(W) card: power amplifier with 4 Watts/channel at 4 Ohms
57 * 57 *
58 * Note that this driver now is actually *better* than the Windows driver,
59 * since it additionally supports the card's 1MHz DirectX timer - just try
60 * the following snd-seq module parameters etc.:
61 * - options snd-seq seq_default_timer_class=2 seq_default_timer_sclass=0
62 * seq_default_timer_card=0 seq_client_load=1 seq_default_timer_device=0
63 * seq_default_timer_subdevice=0 seq_default_timer_resolution=1000000
64 * - "timidity -iAv -B2,8 -Os -EFreverb=0"
65 * - "pmidi -p 128:0 jazz.mid"
66 *
58 * Certain PCI versions of this card are susceptible to DMA traffic underruns 67 * Certain PCI versions of this card are susceptible to DMA traffic underruns
59 * in some systems (resulting in sound crackling/clicking/popping), 68 * in some systems (resulting in sound crackling/clicking/popping),
60 * probably because they don't have a DMA FIFO buffer or so. 69 * probably because they don't have a DMA FIFO buffer or so.
61 * Overview (PCI ID/PCI subID/PCI rev.): 70 * Overview (PCI ID/PCI subID/PCI rev.):
62 * - no DMA crackling on SiS735: 0x50DC/0x1801/16 71 * - no DMA crackling on SiS735: 0x50DC/0x1801/16
63 * - unknown performance: 0x50DC/0x1801/10 72 * - unknown performance: 0x50DC/0x1801/10
64 * 73 * (well, it's not bad on an Athlon 1800 with now very optimized IRQ handler)
74 *
65 * Crackling happens with VIA chipsets or, in my case, an SiS735, which is 75 * Crackling happens with VIA chipsets or, in my case, an SiS735, which is
66 * supposed to be very fast and supposed to get rid of crackling much 76 * supposed to be very fast and supposed to get rid of crackling much
67 * better than a VIA, yet ironically I still get crackling, like many other 77 * better than a VIA, yet ironically I still get crackling, like many other
@@ -76,18 +86,13 @@
76 * - Disable ACPI/power management/"Auto Detect RAM/PCI Clk" in BIOS 86 * - Disable ACPI/power management/"Auto Detect RAM/PCI Clk" in BIOS
77 * 87 *
78 * BUGS 88 * BUGS
79 * - when Ctrl-C'ing mpg321, the playback loops a bit 89 * - full-duplex might *still* be problematic, not fully tested recently
80 * (premature DMA playback reset?)
81 * - full-duplex sometimes breaks (IRQ management issues?).
82 * Once even a spontaneous REBOOT happened!!!
83 * 90 *
84 * TODO 91 * TODO
85 * - test MPU401 MIDI playback etc. 92 * - test MPU401 MIDI playback etc.
86 * - power management (CONFIG_PM). See e.g. intel8x0 or cs4281. 93 * - power management. See e.g. intel8x0 or cs4281.
87 * This would be nice since the chip runs a bit hot, and it's *required* 94 * This would be nice since the chip runs a bit hot, and it's *required*
88 * anyway for proper ACPI power management. In other words: rest 95 * anyway for proper ACPI power management.
89 * assured that I *will* implement this very soon; as soon as Linux 2.5.x
90 * has power management that's bugfree enough to work properly on my desktop.
91 * - figure out what all unknown port bits are responsible for 96 * - figure out what all unknown port bits are responsible for
92 */ 97 */
93 98
@@ -108,7 +113,7 @@
108#include <sound/initval.h> 113#include <sound/initval.h>
109#include "azt3328.h" 114#include "azt3328.h"
110 115
111MODULE_AUTHOR("Andreas Mohr <hw7oshyuv3001@sneakemail.com>"); 116MODULE_AUTHOR("Andreas Mohr <andi AT lisas.de>");
112MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)"); 117MODULE_DESCRIPTION("Aztech AZF3328 (PCI168)");
113MODULE_LICENSE("GPL"); 118MODULE_LICENSE("GPL");
114MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}"); 119MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
@@ -122,6 +127,7 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
122#define DEBUG_MIXER 0 127#define DEBUG_MIXER 0
123#define DEBUG_PLAY_REC 0 128#define DEBUG_PLAY_REC 0
124#define DEBUG_IO 0 129#define DEBUG_IO 0
130#define DEBUG_TIMER 0
125#define MIXER_TESTING 0 131#define MIXER_TESTING 0
126 132
127#if DEBUG_MISC 133#if DEBUG_MISC
@@ -132,8 +138,8 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
132 138
133#if DEBUG_CALLS 139#if DEBUG_CALLS
134#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args) 140#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
135#define snd_azf3328_dbgcallenter() printk(KERN_ERR "entering %s\n", __FUNCTION__) 141#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__)
136#define snd_azf3328_dbgcallleave() printk(KERN_ERR "leaving %s\n", __FUNCTION__) 142#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__)
137#else 143#else
138#define snd_azf3328_dbgcalls(format, args...) 144#define snd_azf3328_dbgcalls(format, args...)
139#define snd_azf3328_dbgcallenter() 145#define snd_azf3328_dbgcallenter()
@@ -152,13 +158,12 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
152#define snd_azf3328_dbgplay(format, args...) 158#define snd_azf3328_dbgplay(format, args...)
153#endif 159#endif
154 160
155#if DEBUG_IO 161#if DEBUG_MISC
156#define snd_azf3328_dbgio(chip, where) \ 162#define snd_azf3328_dbgtimer(format, args...) printk(KERN_ERR format, ##args)
157 printk(KERN_ERR "%s: IDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQMASK %04x, IDX_IO_IRQSTATUS %04x\n", where, inw(chip->codec_port+IDX_IO_PLAY_FLAGS), inw(chip->codec_port+IDX_IO_PLAY_IRQMASK), inw(chip->codec_port+IDX_IO_IRQSTATUS))
158#else 163#else
159#define snd_azf3328_dbgio(chip, where) 164#define snd_azf3328_dbgtimer(format, args...)
160#endif 165#endif
161 166
162static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 167static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
163module_param_array(index, int, NULL, 0444); 168module_param_array(index, int, NULL, 0444);
164MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard."); 169MODULE_PARM_DESC(index, "Index value for AZF3328 soundcard.");
@@ -177,35 +182,40 @@ module_param_array(joystick, bool, NULL, 0444);
177MODULE_PARM_DESC(joystick, "Enable joystick for AZF3328 soundcard."); 182MODULE_PARM_DESC(joystick, "Enable joystick for AZF3328 soundcard.");
178#endif 183#endif
179 184
180typedef struct _snd_azf3328 azf3328_t; 185static int seqtimer_scaling = 128;
181 186module_param(seqtimer_scaling, int, 0444);
182struct _snd_azf3328 { 187MODULE_PARM_DESC(seqtimer_scaling, "Set 1024000Hz sequencer timer scale factor (lockup danger!). Default 128.");
183 int irq;
184 188
189typedef struct _snd_azf3328 {
190 /* often-used fields towards beginning, then grouped */
185 unsigned long codec_port; 191 unsigned long codec_port;
186 unsigned long io2_port; 192 unsigned long io2_port;
187 unsigned long mpu_port; 193 unsigned long mpu_port;
188 unsigned long synth_port; 194 unsigned long synth_port;
189 unsigned long mixer_port; 195 unsigned long mixer_port;
190 196
191#ifdef SUPPORT_JOYSTICK 197 spinlock_t reg_lock;
192 struct gameport *gameport;
193#endif
194
195 struct pci_dev *pci;
196 snd_card_t *card;
197 198
199 snd_timer_t *timer;
200
198 snd_pcm_t *pcm; 201 snd_pcm_t *pcm;
199 snd_rawmidi_t *rmidi;
200 snd_pcm_substream_t *playback_substream; 202 snd_pcm_substream_t *playback_substream;
201 snd_pcm_substream_t *capture_substream; 203 snd_pcm_substream_t *capture_substream;
202 unsigned int is_playing; 204 unsigned int is_playing;
203 unsigned int is_recording; 205 unsigned int is_recording;
204 206
205 spinlock_t reg_lock; 207 snd_card_t *card;
206}; 208 snd_rawmidi_t *rmidi;
209
210#ifdef SUPPORT_JOYSTICK
211 struct gameport *gameport;
212#endif
207 213
208static struct pci_device_id snd_azf3328_ids[] = { 214 struct pci_dev *pci;
215 int irq;
216} azf3328_t;
217
218static const struct pci_device_id snd_azf3328_ids[] = {
209 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */ 219 { 0x122D, 0x50DC, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* PCI168/3328 */
210 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */ 220 { 0x122D, 0x80DA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* 3328 */
211 { 0, } 221 { 0, }
@@ -213,57 +223,90 @@ static struct pci_device_id snd_azf3328_ids[] = {
213 223
214MODULE_DEVICE_TABLE(pci, snd_azf3328_ids); 224MODULE_DEVICE_TABLE(pci, snd_azf3328_ids);
215 225
216static inline void snd_azf3328_io2_write(azf3328_t *chip, int reg, unsigned char value) 226static inline void
227snd_azf3328_codec_outb(const azf3328_t *chip, int reg, u8 value)
228{
229 outb(value, chip->codec_port + reg);
230}
231
232static inline u8
233snd_azf3328_codec_inb(const azf3328_t *chip, int reg)
234{
235 return inb(chip->codec_port + reg);
236}
237
238static inline void
239snd_azf3328_codec_outw(const azf3328_t *chip, int reg, u16 value)
240{
241 outw(value, chip->codec_port + reg);
242}
243
244static inline u16
245snd_azf3328_codec_inw(const azf3328_t *chip, int reg)
246{
247 return inw(chip->codec_port + reg);
248}
249
250static inline void
251snd_azf3328_codec_outl(const azf3328_t *chip, int reg, u32 value)
252{
253 outl(value, chip->codec_port + reg);
254}
255
256static inline void
257snd_azf3328_io2_outb(const azf3328_t *chip, int reg, u8 value)
217{ 258{
218 outb(value, chip->io2_port + reg); 259 outb(value, chip->io2_port + reg);
219} 260}
220 261
221static inline unsigned char snd_azf3328_io2_read(azf3328_t *chip, int reg) 262static inline u8
263snd_azf3328_io2_inb(const azf3328_t *chip, int reg)
222{ 264{
223 return inb(chip->io2_port + reg); 265 return inb(chip->io2_port + reg);
224} 266}
225 267
226static void snd_azf3328_mixer_write(azf3328_t *chip, int reg, unsigned long value, int type) 268static inline void
269snd_azf3328_mixer_outw(const azf3328_t *chip, int reg, u16 value)
227{ 270{
228 switch(type) { 271 outw(value, chip->mixer_port + reg);
229 case WORD_VALUE: 272}
230 outw(value, chip->mixer_port + reg); 273
231 break; 274static inline u16
232 case DWORD_VALUE: 275snd_azf3328_mixer_inw(const azf3328_t *chip, int reg)
233 outl(value, chip->mixer_port + reg); 276{
234 break; 277 return inw(chip->mixer_port + reg);
235 case BYTE_VALUE:
236 outb(value, chip->mixer_port + reg);
237 break;
238 }
239} 278}
240 279
241static void snd_azf3328_mixer_set_mute(azf3328_t *chip, int reg, int do_mute) 280static void
281snd_azf3328_mixer_set_mute(const azf3328_t *chip, int reg, int do_mute)
242{ 282{
283 unsigned long portbase = chip->mixer_port + reg + 1;
243 unsigned char oldval; 284 unsigned char oldval;
244 285
245 /* the mute bit is on the *second* (i.e. right) register of a 286 /* the mute bit is on the *second* (i.e. right) register of a
246 * left/right channel setting */ 287 * left/right channel setting */
247 oldval = inb(chip->mixer_port + reg + 1); 288 oldval = inb(portbase);
248 if (do_mute) 289 if (do_mute)
249 oldval |= 0x80; 290 oldval |= 0x80;
250 else 291 else
251 oldval &= ~0x80; 292 oldval &= ~0x80;
252 outb(oldval, chip->mixer_port + reg + 1); 293 outb(oldval, portbase);
253} 294}
254 295
255static void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay) 296static void
297snd_azf3328_mixer_write_volume_gradually(const azf3328_t *chip, int reg, unsigned char dst_vol_left, unsigned char dst_vol_right, int chan_sel, int delay)
256{ 298{
299 unsigned long portbase = chip->mixer_port + reg;
257 unsigned char curr_vol_left = 0, curr_vol_right = 0; 300 unsigned char curr_vol_left = 0, curr_vol_right = 0;
258 int left_done = 0, right_done = 0; 301 int left_done = 0, right_done = 0;
259 302
260 snd_azf3328_dbgcallenter(); 303 snd_azf3328_dbgcallenter();
261 if (chan_sel & SET_CHAN_LEFT) 304 if (chan_sel & SET_CHAN_LEFT)
262 curr_vol_left = inb(chip->mixer_port + reg + 1); 305 curr_vol_left = inb(portbase + 1);
263 else 306 else
264 left_done = 1; 307 left_done = 1;
265 if (chan_sel & SET_CHAN_RIGHT) 308 if (chan_sel & SET_CHAN_RIGHT)
266 curr_vol_right = inb(chip->mixer_port + reg + 0); 309 curr_vol_right = inb(portbase + 0);
267 else 310 else
268 right_done = 1; 311 right_done = 1;
269 312
@@ -284,7 +327,7 @@ static void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, u
284 curr_vol_left++; 327 curr_vol_left++;
285 else 328 else
286 left_done = 1; 329 left_done = 1;
287 outb(curr_vol_left, chip->mixer_port + reg + 1); 330 outb(curr_vol_left, portbase + 1);
288 } 331 }
289 if (!right_done) 332 if (!right_done)
290 { 333 {
@@ -298,7 +341,7 @@ static void snd_azf3328_mixer_write_volume_gradually(azf3328_t *chip, int reg, u
298 /* during volume change, the right channel is crackling 341 /* during volume change, the right channel is crackling
299 * somewhat more than the left channel, unfortunately. 342 * somewhat more than the left channel, unfortunately.
300 * This seems to be a hardware issue. */ 343 * This seems to be a hardware issue. */
301 outb(curr_vol_right, chip->mixer_port + reg + 0); 344 outb(curr_vol_right, portbase + 0);
302 } 345 }
303 if (delay) 346 if (delay)
304 mdelay(delay); 347 mdelay(delay);
@@ -320,7 +363,11 @@ typedef struct azf3328_mixer_reg {
320} azf3328_mixer_reg_t; 363} azf3328_mixer_reg_t;
321 364
322#define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \ 365#define COMPOSE_MIXER_REG(reg,lchan_shift,rchan_shift,mask,invert,stereo,enum_c) \
323 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | (mask << 16) | (invert << 24) | (stereo << 25) | (enum_c << 26)) 366 ((reg) | (lchan_shift << 8) | (rchan_shift << 12) | \
367 (mask << 16) | \
368 (invert << 24) | \
369 (stereo << 25) | \
370 (enum_c << 26))
324 371
325static void snd_azf3328_mixer_reg_decode(azf3328_mixer_reg_t *r, unsigned long val) 372static void snd_azf3328_mixer_reg_decode(azf3328_mixer_reg_t *r, unsigned long val)
326{ 373{
@@ -372,13 +419,15 @@ static void snd_azf3328_mixer_reg_decode(azf3328_mixer_reg_t *r, unsigned long v
372 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \ 419 .private_value = COMPOSE_MIXER_REG(reg, shift, 0, 0, 0, 0, enum_c), \
373} 420}
374 421
375static int snd_azf3328_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo) 422static int
423snd_azf3328_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
376{ 424{
377 azf3328_mixer_reg_t reg; 425 azf3328_mixer_reg_t reg;
378 426
379 snd_azf3328_dbgcallenter(); 427 snd_azf3328_dbgcallenter();
380 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 428 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
381 uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; 429 uinfo->type = reg.mask == 1 ?
430 SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
382 uinfo->count = reg.stereo + 1; 431 uinfo->count = reg.stereo + 1;
383 uinfo->value.integer.min = 0; 432 uinfo->value.integer.min = 0;
384 uinfo->value.integer.max = reg.mask; 433 uinfo->value.integer.max = reg.mask;
@@ -386,7 +435,8 @@ static int snd_azf3328_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
386 return 0; 435 return 0;
387} 436}
388 437
389static int snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 438static int
439snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
390{ 440{
391 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 441 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
392 azf3328_mixer_reg_t reg; 442 azf3328_mixer_reg_t reg;
@@ -395,7 +445,7 @@ static int snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
395 snd_azf3328_dbgcallenter(); 445 snd_azf3328_dbgcallenter();
396 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 446 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
397 447
398 oreg = inw(chip->mixer_port + reg.reg); 448 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
399 val = (oreg >> reg.lchan_shift) & reg.mask; 449 val = (oreg >> reg.lchan_shift) & reg.mask;
400 if (reg.invert) 450 if (reg.invert)
401 val = reg.mask - val; 451 val = reg.mask - val;
@@ -406,12 +456,17 @@ static int snd_azf3328_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
406 val = reg.mask - val; 456 val = reg.mask - val;
407 ucontrol->value.integer.value[1] = val; 457 ucontrol->value.integer.value[1] = val;
408 } 458 }
409 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx (shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n", reg.reg, oreg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1], reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo); 459 snd_azf3328_dbgmixer("get: %02x is %04x -> vol %02lx|%02lx "
460 "(shift %02d|%02d, mask %02x, inv. %d, stereo %d)\n",
461 reg.reg, oreg,
462 ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
463 reg.lchan_shift, reg.rchan_shift, reg.mask, reg.invert, reg.stereo);
410 snd_azf3328_dbgcallleave(); 464 snd_azf3328_dbgcallleave();
411 return 0; 465 return 0;
412} 466}
413 467
414static int snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 468static int
469snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
415{ 470{
416 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 471 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
417 azf3328_mixer_reg_t reg; 472 azf3328_mixer_reg_t reg;
@@ -419,7 +474,7 @@ static int snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
419 474
420 snd_azf3328_dbgcallenter(); 475 snd_azf3328_dbgcallenter();
421 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 476 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
422 oreg = inw(chip->mixer_port + reg.reg); 477 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
423 val = ucontrol->value.integer.value[0] & reg.mask; 478 val = ucontrol->value.integer.value[0] & reg.mask;
424 if (reg.invert) 479 if (reg.invert)
425 val = reg.mask - val; 480 val = reg.mask - val;
@@ -433,24 +488,37 @@ static int snd_azf3328_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
433 nreg |= (val << reg.rchan_shift); 488 nreg |= (val << reg.rchan_shift);
434 } 489 }
435 if (reg.mask >= 0x07) /* it's a volume control, so better take care */ 490 if (reg.mask >= 0x07) /* it's a volume control, so better take care */
436 snd_azf3328_mixer_write_volume_gradually(chip, reg.reg, nreg >> 8, nreg & 0xff, SET_CHAN_LEFT|SET_CHAN_RIGHT, 0); /* just set both channels, doesn't matter */ 491 snd_azf3328_mixer_write_volume_gradually(
492 chip, reg.reg, nreg >> 8, nreg & 0xff,
493 /* just set both channels, doesn't matter */
494 SET_CHAN_LEFT|SET_CHAN_RIGHT,
495 0);
437 else 496 else
438 outw(nreg, chip->mixer_port + reg.reg); 497 snd_azf3328_mixer_outw(chip, reg.reg, nreg);
439 498
440 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n", reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1], oreg, reg.lchan_shift, reg.rchan_shift, nreg, inw(chip->mixer_port + reg.reg)); 499 snd_azf3328_dbgmixer("put: %02x to %02lx|%02lx, "
500 "oreg %04x; shift %02d|%02d -> nreg %04x; after: %04x\n",
501 reg.reg, ucontrol->value.integer.value[0], ucontrol->value.integer.value[1],
502 oreg, reg.lchan_shift, reg.rchan_shift,
503 nreg, snd_azf3328_mixer_inw(chip, reg.reg));
441 snd_azf3328_dbgcallleave(); 504 snd_azf3328_dbgcallleave();
442 return (nreg != oreg); 505 return (nreg != oreg);
443} 506}
444 507
445static int snd_azf3328_info_mixer_enum(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 508static int
509snd_azf3328_info_mixer_enum(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
446{ 510{
447 azf3328_mixer_reg_t reg; 511 static const char * const texts1[] = {
448 static char *texts1[2] = { "ModemOut1", "ModemOut2" }; 512 "ModemOut1", "ModemOut2"
449 static char *texts2[2] = { "MonoSelectSource1", "MonoSelectSource2" }; 513 };
450 static char *texts3[8] = { 514 static const char * const texts2[] = {
451 "Mic", "CD", "Video", "Aux", "Line", 515 "MonoSelectSource1", "MonoSelectSource2"
452 "Mix", "Mix Mono", "Phone" 516 };
517 static const char * const texts3[] = {
518 "Mic", "CD", "Video", "Aux",
519 "Line", "Mix", "Mix Mono", "Phone"
453 }; 520 };
521 azf3328_mixer_reg_t reg;
454 522
455 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 523 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
456 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 524 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
@@ -471,14 +539,15 @@ static int snd_azf3328_info_mixer_enum(snd_kcontrol_t *kcontrol, snd_ctl_elem_in
471 return 0; 539 return 0;
472} 540}
473 541
474static int snd_azf3328_get_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 542static int
543snd_azf3328_get_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
475{ 544{
476 azf3328_mixer_reg_t reg;
477 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 545 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
546 azf3328_mixer_reg_t reg;
478 unsigned short val; 547 unsigned short val;
479 548
480 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 549 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
481 val = inw(chip->mixer_port + reg.reg); 550 val = snd_azf3328_mixer_inw(chip, reg.reg);
482 if (reg.reg == IDX_MIXER_REC_SELECT) 551 if (reg.reg == IDX_MIXER_REC_SELECT)
483 { 552 {
484 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1); 553 ucontrol->value.enumerated.item[0] = (val >> 8) & (reg.enum_c - 1);
@@ -486,18 +555,22 @@ static int snd_azf3328_get_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
486 } 555 }
487 else 556 else
488 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1); 557 ucontrol->value.enumerated.item[0] = (val >> reg.lchan_shift) & (reg.enum_c - 1);
489 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n", reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1], reg.lchan_shift, reg.enum_c); 558
559 snd_azf3328_dbgmixer("get_enum: %02x is %04x -> %d|%d (shift %02d, enum_c %d)\n",
560 reg.reg, val, ucontrol->value.enumerated.item[0], ucontrol->value.enumerated.item[1],
561 reg.lchan_shift, reg.enum_c);
490 return 0; 562 return 0;
491} 563}
492 564
493static int snd_azf3328_put_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 565static int
566snd_azf3328_put_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
494{ 567{
495 azf3328_mixer_reg_t reg;
496 azf3328_t *chip = snd_kcontrol_chip(kcontrol); 568 azf3328_t *chip = snd_kcontrol_chip(kcontrol);
569 azf3328_mixer_reg_t reg;
497 unsigned int oreg, nreg, val; 570 unsigned int oreg, nreg, val;
498 571
499 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value); 572 snd_azf3328_mixer_reg_decode(&reg, kcontrol->private_value);
500 oreg = inw(chip->mixer_port + reg.reg); 573 oreg = snd_azf3328_mixer_inw(chip, reg.reg);
501 val = oreg; 574 val = oreg;
502 if (reg.reg == IDX_MIXER_REC_SELECT) 575 if (reg.reg == IDX_MIXER_REC_SELECT)
503 { 576 {
@@ -514,19 +587,19 @@ static int snd_azf3328_put_mixer_enum(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
514 val &= ~((reg.enum_c - 1) << reg.lchan_shift); 587 val &= ~((reg.enum_c - 1) << reg.lchan_shift);
515 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift); 588 val |= (ucontrol->value.enumerated.item[0] << reg.lchan_shift);
516 } 589 }
517 outw(val, chip->mixer_port + reg.reg); 590 snd_azf3328_mixer_outw(chip, reg.reg, val);
518 nreg = val; 591 nreg = val;
519 592
520 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg); 593 snd_azf3328_dbgmixer("put_enum: %02x to %04x, oreg %04x\n", reg.reg, val, oreg);
521 return (nreg != oreg); 594 return (nreg != oreg);
522} 595}
523 596
524static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = { 597static const snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
525 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1), 598 AZF3328_MIXER_SWITCH("Master Playback Switch", IDX_MIXER_PLAY_MASTER, 15, 1),
526 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1), 599 AZF3328_MIXER_VOL_STEREO("Master Playback Volume", IDX_MIXER_PLAY_MASTER, 0x1f, 1),
527 AZF3328_MIXER_SWITCH("Wave Playback Switch", IDX_MIXER_WAVEOUT, 15, 1), 600 AZF3328_MIXER_SWITCH("Wave Playback Switch", IDX_MIXER_WAVEOUT, 15, 1),
528 AZF3328_MIXER_VOL_STEREO("Wave Playback Volume", IDX_MIXER_WAVEOUT, 0x1f, 1), 601 AZF3328_MIXER_VOL_STEREO("Wave Playback Volume", IDX_MIXER_WAVEOUT, 0x1f, 1),
529 AZF3328_MIXER_SWITCH("Wave Playback 3D Bypass", IDX_MIXER_ADVCTL2, 7, 1), 602 AZF3328_MIXER_SWITCH("Wave 3D Bypass Playback Switch", IDX_MIXER_ADVCTL2, 7, 1),
530 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1), 603 AZF3328_MIXER_SWITCH("FM Playback Switch", IDX_MIXER_FMSYNTH, 15, 1),
531 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1), 604 AZF3328_MIXER_VOL_STEREO("FM Playback Volume", IDX_MIXER_FMSYNTH, 0x1f, 1),
532 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1), 605 AZF3328_MIXER_SWITCH("CD Playback Switch", IDX_MIXER_CDAUDIO, 15, 1),
@@ -539,8 +612,8 @@ static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
539 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0), 612 AZF3328_MIXER_SWITCH("Mic Boost (+20dB)", IDX_MIXER_MIC, 6, 0),
540 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1), 613 AZF3328_MIXER_SWITCH("Line Playback Switch", IDX_MIXER_LINEIN, 15, 1),
541 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1), 614 AZF3328_MIXER_VOL_STEREO("Line Playback Volume", IDX_MIXER_LINEIN, 0x1f, 1),
542 AZF3328_MIXER_SWITCH("PCBeep Playback Switch", IDX_MIXER_PCBEEP, 15, 1), 615 AZF3328_MIXER_SWITCH("PC Speaker Playback Switch", IDX_MIXER_PCBEEP, 15, 1),
543 AZF3328_MIXER_VOL_SPECIAL("PCBeep Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1), 616 AZF3328_MIXER_VOL_SPECIAL("PC Speaker Playback Volume", IDX_MIXER_PCBEEP, 0x0f, 1, 1),
544 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1), 617 AZF3328_MIXER_SWITCH("Video Playback Switch", IDX_MIXER_VIDEO, 15, 1),
545 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1), 618 AZF3328_MIXER_VOL_STEREO("Video Playback Volume", IDX_MIXER_VIDEO, 0x1f, 1),
546 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1), 619 AZF3328_MIXER_SWITCH("Aux Playback Switch", IDX_MIXER_AUX, 15, 1),
@@ -553,8 +626,8 @@ static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
553 AZF3328_MIXER_ENUM("Mono Select Source", IDX_MIXER_ADVCTL2, 2, 9), 626 AZF3328_MIXER_ENUM("Mono Select Source", IDX_MIXER_ADVCTL2, 2, 9),
554 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0), 627 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Treble", IDX_MIXER_BASSTREBLE, 0x07, 1, 0),
555 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0), 628 AZF3328_MIXER_VOL_SPECIAL("Tone Control - Bass", IDX_MIXER_BASSTREBLE, 0x07, 9, 0),
556 AZF3328_MIXER_SWITCH("3D Control - Toggle", IDX_MIXER_ADVCTL2, 13, 0), 629 AZF3328_MIXER_SWITCH("3D Control - Switch", IDX_MIXER_ADVCTL2, 13, 0),
557 AZF3328_MIXER_VOL_SPECIAL("3D Control - Volume", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */ 630 AZF3328_MIXER_VOL_SPECIAL("3D Control - Wide", IDX_MIXER_ADVCTL1, 0x07, 1, 0), /* "3D Width" */
558 AZF3328_MIXER_VOL_SPECIAL("3D Control - Space", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */ 631 AZF3328_MIXER_VOL_SPECIAL("3D Control - Space", IDX_MIXER_ADVCTL1, 0x03, 8, 0), /* "Hifi 3D" */
559#if MIXER_TESTING 632#if MIXER_TESTING
560 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0), 633 AZF3328_MIXER_SWITCH("0", IDX_MIXER_ADVCTL2, 0, 0),
@@ -576,9 +649,7 @@ static snd_kcontrol_new_t snd_azf3328_mixer_controls[] __devinitdata = {
576#endif 649#endif
577}; 650};
578 651
579#define AZF3328_INIT_VALUES (sizeof(snd_azf3328_init_values)/sizeof(unsigned int)/2) 652static const u16 __devinitdata snd_azf3328_init_values[][2] = {
580
581static unsigned int snd_azf3328_init_values[][2] = {
582 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f }, 653 { IDX_MIXER_PLAY_MASTER, MIXER_MUTE_MASK|0x1f1f },
583 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f }, 654 { IDX_MIXER_MODEMOUT, MIXER_MUTE_MASK|0x1f1f },
584 { IDX_MIXER_BASSTREBLE, 0x0000 }, 655 { IDX_MIXER_BASSTREBLE, 0x0000 },
@@ -594,10 +665,11 @@ static unsigned int snd_azf3328_init_values[][2] = {
594 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 }, 665 { IDX_MIXER_REC_VOLUME, MIXER_MUTE_MASK|0x0707 },
595}; 666};
596 667
597static int __devinit snd_azf3328_mixer_new(azf3328_t *chip) 668static int __devinit
669snd_azf3328_mixer_new(azf3328_t *chip)
598{ 670{
599 snd_card_t *card; 671 snd_card_t *card;
600 snd_kcontrol_new_t *sw; 672 const snd_kcontrol_new_t *sw;
601 unsigned int idx; 673 unsigned int idx;
602 int err; 674 int err;
603 675
@@ -607,11 +679,13 @@ static int __devinit snd_azf3328_mixer_new(azf3328_t *chip)
607 card = chip->card; 679 card = chip->card;
608 680
609 /* mixer reset */ 681 /* mixer reset */
610 snd_azf3328_mixer_write(chip, IDX_MIXER_RESET, 0x0, WORD_VALUE); 682 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
611 683
612 /* mute and zero volume channels */ 684 /* mute and zero volume channels */
613 for (idx = 0; idx < AZF3328_INIT_VALUES; idx++) { 685 for (idx = 0; idx < ARRAY_SIZE(snd_azf3328_init_values); idx++) {
614 snd_azf3328_mixer_write(chip, snd_azf3328_init_values[idx][0], snd_azf3328_init_values[idx][1], WORD_VALUE); 686 snd_azf3328_mixer_outw(chip,
687 snd_azf3328_init_values[idx][0],
688 snd_azf3328_init_values[idx][1]);
615 } 689 }
616 690
617 /* add mixer controls */ 691 /* add mixer controls */
@@ -627,7 +701,8 @@ static int __devinit snd_azf3328_mixer_new(azf3328_t *chip)
627 return 0; 701 return 0;
628} 702}
629 703
630static int snd_azf3328_hw_params(snd_pcm_substream_t * substream, 704static int
705snd_azf3328_hw_params(snd_pcm_substream_t * substream,
631 snd_pcm_hw_params_t * hw_params) 706 snd_pcm_hw_params_t * hw_params)
632{ 707{
633 int res; 708 int res;
@@ -637,7 +712,8 @@ static int snd_azf3328_hw_params(snd_pcm_substream_t * substream,
637 return res; 712 return res;
638} 713}
639 714
640static int snd_azf3328_hw_free(snd_pcm_substream_t * substream) 715static int
716snd_azf3328_hw_free(snd_pcm_substream_t * substream)
641{ 717{
642 snd_azf3328_dbgcallenter(); 718 snd_azf3328_dbgcallenter();
643 snd_pcm_lib_free_pages(substream); 719 snd_pcm_lib_free_pages(substream);
@@ -645,43 +721,48 @@ static int snd_azf3328_hw_free(snd_pcm_substream_t * substream)
645 return 0; 721 return 0;
646} 722}
647 723
648static void snd_azf3328_setfmt(azf3328_t *chip, 724static void
725snd_azf3328_setfmt(azf3328_t *chip,
649 unsigned int reg, 726 unsigned int reg,
650 unsigned int bitrate, 727 unsigned int bitrate,
651 unsigned int format_width, 728 unsigned int format_width,
652 unsigned int channels 729 unsigned int channels
653) 730)
654{ 731{
655 unsigned int val = 0xff00; 732 u16 val = 0xff00;
656 unsigned long flags; 733 unsigned long flags;
657 734
658 snd_azf3328_dbgcallenter(); 735 snd_azf3328_dbgcallenter();
659 switch (bitrate) { 736 switch (bitrate) {
660 case 5512: val |= 0x0d; break; /* the AZF3328 names it "5510" for some strange reason */ 737 case 4000: val |= SOUNDFORMAT_FREQ_SUSPECTED_4000; break;
661 case 6620: val |= 0x0b; break; 738 case 4800: val |= SOUNDFORMAT_FREQ_SUSPECTED_4800; break;
662 case 8000: val |= 0x00; break; 739 case 5512: val |= SOUNDFORMAT_FREQ_5510; break; /* the AZF3328 names it "5510" for some strange reason */
663 case 9600: val |= 0x08; break; 740 case 6620: val |= SOUNDFORMAT_FREQ_6620; break;
664 case 11025: val |= 0x01; break; 741 case 8000: val |= SOUNDFORMAT_FREQ_8000; break;
665 case 16000: val |= 0x02; break; 742 case 9600: val |= SOUNDFORMAT_FREQ_9600; break;
666 case 22050: val |= 0x03; break; 743 case 11025: val |= SOUNDFORMAT_FREQ_11025; break;
667 case 32000: val |= 0x04; break; 744 case 13240: val |= SOUNDFORMAT_FREQ_SUSPECTED_13240; break;
668 case 44100: val |= 0x05; break; 745 case 16000: val |= SOUNDFORMAT_FREQ_16000; break;
669 case 48000: val |= 0x06; break; 746 case 22050: val |= SOUNDFORMAT_FREQ_22050; break;
670 case 64000: val |= 0x07; break; 747 case 32000: val |= SOUNDFORMAT_FREQ_32000; break;
748 case 44100: val |= SOUNDFORMAT_FREQ_44100; break;
749 case 48000: val |= SOUNDFORMAT_FREQ_48000; break;
750 case 66200: val |= SOUNDFORMAT_FREQ_SUSPECTED_66200; break;
671 default: 751 default:
672 snd_printk("unknown bitrate %d, assuming 44.1kHz!\n", bitrate); 752 snd_printk(KERN_WARNING "unknown bitrate %d, assuming 44.1kHz!\n", bitrate);
673 val |= 0x05; /* 44100 */ 753 val |= SOUNDFORMAT_FREQ_44100;
674 break; 754 break;
675 } 755 }
676 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) */ 756 /* val = 0xff07; 3m27.993s (65301Hz; -> 64000Hz???) hmm, 66120, 65967, 66123 */
677 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) */ 757 /* val = 0xff09; 17m15.098s (13123,478Hz; -> 12000Hz???) hmm, 13237.2Hz? */
678 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) */ 758 /* val = 0xff0a; 47m30.599s (4764,891Hz; -> 4800Hz???) yup, 4803Hz */
679 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) */ 759 /* val = 0xff0c; 57m0.510s (4010,263Hz; -> 4000Hz???) yup, 4003Hz */
680 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */ 760 /* val = 0xff05; 5m11.556s (... -> 44100Hz) */
681 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */ 761 /* val = 0xff03; 10m21.529s (21872,463Hz; -> 22050Hz???) */
682 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */ 762 /* val = 0xff0f; 20m41.883s (10937,993Hz; -> 11025Hz???) */
683 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */ 763 /* val = 0xff0d; 41m23.135s (5523,600Hz; -> 5512Hz???) */
684 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */ 764 /* val = 0xff0e; 28m30.777s (8017Hz; -> 8000Hz???) */
765
685 if (channels == 2) 766 if (channels == 2)
686 val |= SOUNDFORMAT_FLAG_2CHANNELS; 767 val |= SOUNDFORMAT_FLAG_2CHANNELS;
687 768
@@ -691,7 +772,7 @@ static void snd_azf3328_setfmt(azf3328_t *chip,
691 spin_lock_irqsave(&chip->reg_lock, flags); 772 spin_lock_irqsave(&chip->reg_lock, flags);
692 773
693 /* set bitrate/format */ 774 /* set bitrate/format */
694 outw(val, chip->codec_port+reg); 775 snd_azf3328_codec_outw(chip, reg, val);
695 776
696 /* changing the bitrate/format settings switches off the 777 /* changing the bitrate/format settings switches off the
697 * audio output with an annoying click in case of 8/16bit format change 778 * audio output with an annoying click in case of 8/16bit format change
@@ -701,47 +782,67 @@ static void snd_azf3328_setfmt(azf3328_t *chip,
701 * FIXME: does this have some side effects for full-duplex 782 * FIXME: does this have some side effects for full-duplex
702 * or other dramatic side effects? */ 783 * or other dramatic side effects? */
703 if (reg == IDX_IO_PLAY_SOUNDFORMAT) /* only do it for playback */ 784 if (reg == IDX_IO_PLAY_SOUNDFORMAT) /* only do it for playback */
704 outw(inw(chip->codec_port + IDX_IO_PLAY_FLAGS)|DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_PLAY_FLAGS); 785 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
786 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS) |
787 DMA_PLAY_SOMETHING1 |
788 DMA_PLAY_SOMETHING2 |
789 SOMETHING_ALMOST_ALWAYS_SET |
790 DMA_EPILOGUE_SOMETHING |
791 DMA_SOMETHING_ELSE
792 );
705 793
706 spin_unlock_irqrestore(&chip->reg_lock, flags); 794 spin_unlock_irqrestore(&chip->reg_lock, flags);
707 snd_azf3328_dbgcallleave(); 795 snd_azf3328_dbgcallleave();
708} 796}
709 797
710static void snd_azf3328_setdmaa(azf3328_t *chip, 798static void
799snd_azf3328_setdmaa(azf3328_t *chip,
711 long unsigned int addr, 800 long unsigned int addr,
712 unsigned int count, 801 unsigned int count,
713 unsigned int size, 802 unsigned int size,
714 int do_recording) 803 int do_recording)
715{ 804{
716 long unsigned int addr1; 805 unsigned long flags, portbase;
717 long unsigned int addr2; 806 unsigned int is_running;
718 unsigned int count1;
719 unsigned int count2;
720 unsigned long flags;
721 int reg_offs = do_recording ? 0x20 : 0x00;
722 807
723 snd_azf3328_dbgcallenter(); 808 snd_azf3328_dbgcallenter();
809 if (do_recording)
810 {
811 /* access capture registers, i.e. skip playback reg section */
812 portbase = chip->codec_port + 0x20;
813 is_running = chip->is_recording;
814 }
815 else
816 {
817 /* access the playback register section */
818 portbase = chip->codec_port + 0x00;
819 is_running = chip->is_playing;
820 }
821
724 /* AZF3328 uses a two buffer pointer DMA playback approach */ 822 /* AZF3328 uses a two buffer pointer DMA playback approach */
725 if (!chip->is_playing) 823 if (!is_running)
726 { 824 {
727 addr1 = addr; 825 unsigned long addr_area2;
728 addr2 = addr+(size/2); 826 unsigned long count_areas, count_tmp; /* width 32bit -- overflow!! */
729 count1 = (size/2)-1; 827 count_areas = size/2;
730 count2 = (size/2)-1; 828 addr_area2 = addr+count_areas;
731#if DEBUG_PLAY_REC 829 count_areas--; /* max. index */
732 snd_azf3328_dbgplay("setting dma: buf1 %08lx[%d], buf2 %08lx[%d]\n", addr1, count1, addr2, count2); 830 snd_azf3328_dbgplay("set DMA: buf1 %08lx[%lu], buf2 %08lx[%lu]\n", addr, count_areas, addr_area2, count_areas);
733#endif 831
832 /* build combined I/O buffer length word */
833 count_tmp = count_areas;
834 count_areas |= (count_tmp << 16);
734 spin_lock_irqsave(&chip->reg_lock, flags); 835 spin_lock_irqsave(&chip->reg_lock, flags);
735 outl(addr1, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_START_1); 836 outl(addr, portbase + IDX_IO_PLAY_DMA_START_1);
736 outl(addr2, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_START_2); 837 outl(addr_area2, portbase + IDX_IO_PLAY_DMA_START_2);
737 outw(count1, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_LEN_1); 838 outl(count_areas, portbase + IDX_IO_PLAY_DMA_LEN_1);
738 outw(count2, chip->codec_port+reg_offs+IDX_IO_PLAY_DMA_LEN_2);
739 spin_unlock_irqrestore(&chip->reg_lock, flags); 839 spin_unlock_irqrestore(&chip->reg_lock, flags);
740 } 840 }
741 snd_azf3328_dbgcallleave(); 841 snd_azf3328_dbgcallleave();
742} 842}
743 843
744static int snd_azf3328_playback_prepare(snd_pcm_substream_t *substream) 844static int
845snd_azf3328_playback_prepare(snd_pcm_substream_t *substream)
745{ 846{
746#if 0 847#if 0
747 azf3328_t *chip = snd_pcm_substream_chip(substream); 848 azf3328_t *chip = snd_pcm_substream_chip(substream);
@@ -752,14 +853,18 @@ static int snd_azf3328_playback_prepare(snd_pcm_substream_t *substream)
752 853
753 snd_azf3328_dbgcallenter(); 854 snd_azf3328_dbgcallenter();
754#if 0 855#if 0
755 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 856 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
857 runtime->rate,
858 snd_pcm_format_width(runtime->format),
859 runtime->channels);
756 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 0); 860 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 0);
757#endif 861#endif
758 snd_azf3328_dbgcallleave(); 862 snd_azf3328_dbgcallleave();
759 return 0; 863 return 0;
760} 864}
761 865
762static int snd_azf3328_capture_prepare(snd_pcm_substream_t * substream) 866static int
867snd_azf3328_capture_prepare(snd_pcm_substream_t * substream)
763{ 868{
764#if 0 869#if 0
765 azf3328_t *chip = snd_pcm_substream_chip(substream); 870 azf3328_t *chip = snd_pcm_substream_chip(substream);
@@ -770,14 +875,18 @@ static int snd_azf3328_capture_prepare(snd_pcm_substream_t * substream)
770 875
771 snd_azf3328_dbgcallenter(); 876 snd_azf3328_dbgcallenter();
772#if 0 877#if 0
773 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 878 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
879 runtime->rate,
880 snd_pcm_format_width(runtime->format),
881 runtime->channels);
774 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 1); 882 snd_azf3328_setdmaa(chip, runtime->dma_addr, count, size, 1);
775#endif 883#endif
776 snd_azf3328_dbgcallleave(); 884 snd_azf3328_dbgcallleave();
777 return 0; 885 return 0;
778} 886}
779 887
780static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd) 888static int
889snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd)
781{ 890{
782 azf3328_t *chip = snd_pcm_substream_chip(substream); 891 azf3328_t *chip = snd_pcm_substream_chip(substream);
783 snd_pcm_runtime_t *runtime = substream->runtime; 892 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -785,79 +894,98 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
785 unsigned int status1; 894 unsigned int status1;
786 895
787 snd_azf3328_dbgcalls("snd_azf3328_playback_trigger cmd %d\n", cmd); 896 snd_azf3328_dbgcalls("snd_azf3328_playback_trigger cmd %d\n", cmd);
897
788 switch (cmd) { 898 switch (cmd) {
789 case SNDRV_PCM_TRIGGER_START: 899 case SNDRV_PCM_TRIGGER_START:
790 900 snd_azf3328_dbgplay("START PLAYBACK\n");
791 snd_azf3328_dbgio(chip, "trigger1");
792 901
793 /* mute WaveOut */ 902 /* mute WaveOut */
794 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1); 903 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
795 904
796 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 905 snd_azf3328_setfmt(chip, IDX_IO_PLAY_SOUNDFORMAT,
906 runtime->rate,
907 snd_pcm_format_width(runtime->format),
908 runtime->channels);
797 909
798 spin_lock(&chip->reg_lock); 910 spin_lock(&chip->reg_lock);
799 /* stop playback */ 911 /* stop playback */
800 status1 = inw(chip->codec_port+IDX_IO_PLAY_FLAGS); 912 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
801 status1 &= ~DMA_RESUME; 913 status1 &= ~DMA_RESUME;
802 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 914 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
803 915
804 /* FIXME: clear interrupts or what??? */ 916 /* FIXME: clear interrupts or what??? */
805 outw(0xffff, chip->codec_port+IDX_IO_PLAY_IRQMASK); 917 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_IRQTYPE, 0xffff);
806 spin_unlock(&chip->reg_lock); 918 spin_unlock(&chip->reg_lock);
807 919
808 snd_azf3328_setdmaa(chip, runtime->dma_addr, snd_pcm_lib_period_bytes(substream), snd_pcm_lib_buffer_bytes(substream), 0); 920 snd_azf3328_setdmaa(chip, runtime->dma_addr,
921 snd_pcm_lib_period_bytes(substream),
922 snd_pcm_lib_buffer_bytes(substream),
923 0);
809 924
810 spin_lock(&chip->reg_lock); 925 spin_lock(&chip->reg_lock);
811#ifdef WIN9X 926#ifdef WIN9X
812 /* FIXME: enable playback/recording??? */ 927 /* FIXME: enable playback/recording??? */
813 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2; 928 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
814 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 929 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
815 930
816 /* start playback again */ 931 /* start playback again */
817 /* FIXME: what is this value (0x0010)??? */ 932 /* FIXME: what is this value (0x0010)??? */
818 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING; 933 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
819 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 934 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
820#else /* NT4 */ 935#else /* NT4 */
821 outw(0x00, chip->codec_port+IDX_IO_PLAY_FLAGS); 936 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
822 outw(DMA_PLAY_SOMETHING1, chip->codec_port+IDX_IO_PLAY_FLAGS); 937 0x0000);
823 outw(DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2, chip->codec_port+IDX_IO_PLAY_FLAGS); 938 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
824 outw(DMA_RESUME|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port+IDX_IO_PLAY_FLAGS); 939 DMA_PLAY_SOMETHING1);
940 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
941 DMA_PLAY_SOMETHING1 |
942 DMA_PLAY_SOMETHING2);
943 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS,
944 DMA_RESUME |
945 SOMETHING_ALMOST_ALWAYS_SET |
946 DMA_EPILOGUE_SOMETHING |
947 DMA_SOMETHING_ELSE);
825#endif 948#endif
826 spin_unlock(&chip->reg_lock); 949 spin_unlock(&chip->reg_lock);
827 950
828 /* now unmute WaveOut */ 951 /* now unmute WaveOut */
829 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0); 952 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
830 953
831 snd_azf3328_dbgio(chip, "trigger2");
832 chip->is_playing = 1; 954 chip->is_playing = 1;
955 snd_azf3328_dbgplay("STARTED PLAYBACK\n");
833 break; 956 break;
834 case SNDRV_PCM_TRIGGER_STOP: 957 case SNDRV_PCM_TRIGGER_STOP:
958 snd_azf3328_dbgplay("STOP PLAYBACK\n");
959
835 /* mute WaveOut */ 960 /* mute WaveOut */
836 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1); 961 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 1);
837 962
838 spin_lock(&chip->reg_lock); 963 spin_lock(&chip->reg_lock);
839 /* stop playback */ 964 /* stop playback */
840 status1 = inw(chip->codec_port+IDX_IO_PLAY_FLAGS); 965 status1 = snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS);
841 966
842 status1 &= ~DMA_RESUME; 967 status1 &= ~DMA_RESUME;
843 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 968 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
844 969
970 /* hmm, is this really required? we're resetting the same bit
971 * immediately thereafter... */
845 status1 |= DMA_PLAY_SOMETHING1; 972 status1 |= DMA_PLAY_SOMETHING1;
846 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 973 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
847 974
848 status1 &= ~DMA_PLAY_SOMETHING1; 975 status1 &= ~DMA_PLAY_SOMETHING1;
849 outw(status1, chip->codec_port+IDX_IO_PLAY_FLAGS); 976 snd_azf3328_codec_outw(chip, IDX_IO_PLAY_FLAGS, status1);
850 spin_unlock(&chip->reg_lock); 977 spin_unlock(&chip->reg_lock);
851 978
852 /* now unmute WaveOut */ 979 /* now unmute WaveOut */
853 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0); 980 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_WAVEOUT, 0);
854 chip->is_playing = 0; 981 chip->is_playing = 0;
982 snd_azf3328_dbgplay("STOPPED PLAYBACK\n");
855 break; 983 break;
856 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 984 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
857 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n"); 985 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
858 break; 986 break;
859 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 987 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
860 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n"); 988 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
861 break; 989 break;
862 default: 990 default:
863 return -EINVAL; 991 return -EINVAL;
@@ -869,7 +997,8 @@ static int snd_azf3328_playback_trigger(snd_pcm_substream_t * substream, int cmd
869 997
870/* this is just analogous to playback; I'm not quite sure whether recording 998/* this is just analogous to playback; I'm not quite sure whether recording
871 * should actually be triggered like that */ 999 * should actually be triggered like that */
872static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd) 1000static int
1001snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
873{ 1002{
874 azf3328_t *chip = snd_pcm_substream_chip(substream); 1003 azf3328_t *chip = snd_pcm_substream_chip(substream);
875 snd_pcm_runtime_t *runtime = substream->runtime; 1004 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -877,68 +1006,86 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
877 unsigned int status1; 1006 unsigned int status1;
878 1007
879 snd_azf3328_dbgcalls("snd_azf3328_capture_trigger cmd %d\n", cmd); 1008 snd_azf3328_dbgcalls("snd_azf3328_capture_trigger cmd %d\n", cmd);
1009
880 switch (cmd) { 1010 switch (cmd) {
881 case SNDRV_PCM_TRIGGER_START: 1011 case SNDRV_PCM_TRIGGER_START:
882 1012
883 snd_azf3328_dbgio(chip, "trigger1"); 1013 snd_azf3328_dbgplay("START CAPTURE\n");
884 1014
885 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT, runtime->rate, snd_pcm_format_width(runtime->format), runtime->channels); 1015 snd_azf3328_setfmt(chip, IDX_IO_REC_SOUNDFORMAT,
1016 runtime->rate,
1017 snd_pcm_format_width(runtime->format),
1018 runtime->channels);
886 1019
887 spin_lock(&chip->reg_lock); 1020 spin_lock(&chip->reg_lock);
888 /* stop recording */ 1021 /* stop recording */
889 status1 = inw(chip->codec_port+IDX_IO_REC_FLAGS); 1022 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
890 status1 &= ~DMA_RESUME; 1023 status1 &= ~DMA_RESUME;
891 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1024 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
892 1025
893 /* FIXME: clear interrupts or what??? */ 1026 /* FIXME: clear interrupts or what??? */
894 outw(0xffff, chip->codec_port+IDX_IO_REC_IRQMASK); 1027 snd_azf3328_codec_outw(chip, IDX_IO_REC_IRQTYPE, 0xffff);
895 spin_unlock(&chip->reg_lock); 1028 spin_unlock(&chip->reg_lock);
896 1029
897 snd_azf3328_setdmaa(chip, runtime->dma_addr, snd_pcm_lib_period_bytes(substream), snd_pcm_lib_buffer_bytes(substream), 1); 1030 snd_azf3328_setdmaa(chip, runtime->dma_addr,
1031 snd_pcm_lib_period_bytes(substream),
1032 snd_pcm_lib_buffer_bytes(substream),
1033 1);
898 1034
899 spin_lock(&chip->reg_lock); 1035 spin_lock(&chip->reg_lock);
900#ifdef WIN9X 1036#ifdef WIN9X
901 /* FIXME: enable playback/recording??? */ 1037 /* FIXME: enable playback/recording??? */
902 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2; 1038 status1 |= DMA_PLAY_SOMETHING1 | DMA_PLAY_SOMETHING2;
903 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1039 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
904 1040
905 /* start playback again */ 1041 /* start capture again */
906 /* FIXME: what is this value (0x0010)??? */ 1042 /* FIXME: what is this value (0x0010)??? */
907 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING; 1043 status1 |= DMA_RESUME | DMA_EPILOGUE_SOMETHING;
908 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1044 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
909#else 1045#else
910 outw(0x00, chip->codec_port+IDX_IO_REC_FLAGS); 1046 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
911 outw(DMA_PLAY_SOMETHING1, chip->codec_port+IDX_IO_REC_FLAGS); 1047 0x0000);
912 outw(DMA_PLAY_SOMETHING1|DMA_PLAY_SOMETHING2, chip->codec_port+IDX_IO_REC_FLAGS); 1048 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
913 outw(DMA_RESUME|SOMETHING_ALMOST_ALWAYS_SET|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port+IDX_IO_REC_FLAGS); 1049 DMA_PLAY_SOMETHING1);
1050 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1051 DMA_PLAY_SOMETHING1 |
1052 DMA_PLAY_SOMETHING2);
1053 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS,
1054 DMA_RESUME |
1055 SOMETHING_ALMOST_ALWAYS_SET |
1056 DMA_EPILOGUE_SOMETHING |
1057 DMA_SOMETHING_ELSE);
914#endif 1058#endif
915 spin_unlock(&chip->reg_lock); 1059 spin_unlock(&chip->reg_lock);
916 1060
917 snd_azf3328_dbgio(chip, "trigger2"); 1061 chip->is_recording = 1;
918 chip->is_playing = 1; 1062 snd_azf3328_dbgplay("STARTED CAPTURE\n");
919 break; 1063 break;
920 case SNDRV_PCM_TRIGGER_STOP: 1064 case SNDRV_PCM_TRIGGER_STOP:
1065 snd_azf3328_dbgplay("STOP CAPTURE\n");
1066
921 spin_lock(&chip->reg_lock); 1067 spin_lock(&chip->reg_lock);
922 /* stop recording */ 1068 /* stop recording */
923 status1 = inw(chip->codec_port+IDX_IO_REC_FLAGS); 1069 status1 = snd_azf3328_codec_inw(chip, IDX_IO_REC_FLAGS);
924 1070
925 status1 &= ~DMA_RESUME; 1071 status1 &= ~DMA_RESUME;
926 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1072 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
927 1073
928 status1 |= DMA_PLAY_SOMETHING1; 1074 status1 |= DMA_PLAY_SOMETHING1;
929 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1075 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
930 1076
931 status1 &= ~DMA_PLAY_SOMETHING1; 1077 status1 &= ~DMA_PLAY_SOMETHING1;
932 outw(status1, chip->codec_port+IDX_IO_REC_FLAGS); 1078 snd_azf3328_codec_outw(chip, IDX_IO_REC_FLAGS, status1);
933 spin_unlock(&chip->reg_lock); 1079 spin_unlock(&chip->reg_lock);
934 1080
935 chip->is_playing = 0; 1081 chip->is_recording = 0;
1082 snd_azf3328_dbgplay("STOPPED CAPTURE\n");
936 break; 1083 break;
937 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1084 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
938 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n"); 1085 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_PUSH NIY!\n");
939 break; 1086 break;
940 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1087 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
941 snd_printk("FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n"); 1088 snd_printk(KERN_ERR "FIXME: SNDRV_PCM_TRIGGER_PAUSE_RELEASE NIY!\n");
942 break; 1089 break;
943 default: 1090 default:
944 return -EINVAL; 1091 return -EINVAL;
@@ -948,11 +1095,11 @@ static int snd_azf3328_capture_trigger(snd_pcm_substream_t * substream, int cmd)
948 return result; 1095 return result;
949} 1096}
950 1097
951static snd_pcm_uframes_t snd_azf3328_playback_pointer(snd_pcm_substream_t * substream) 1098static snd_pcm_uframes_t
1099snd_azf3328_playback_pointer(snd_pcm_substream_t * substream)
952{ 1100{
953 azf3328_t *chip = snd_pcm_substream_chip(substream); 1101 azf3328_t *chip = snd_pcm_substream_chip(substream);
954 unsigned long bufptr, playptr; 1102 unsigned long bufptr, result;
955 unsigned long result;
956 snd_pcm_uframes_t frmres; 1103 snd_pcm_uframes_t frmres;
957 1104
958#ifdef QUERY_HARDWARE 1105#ifdef QUERY_HARDWARE
@@ -960,19 +1107,20 @@ static snd_pcm_uframes_t snd_azf3328_playback_pointer(snd_pcm_substream_t * subs
960#else 1107#else
961 bufptr = substream->runtime->dma_addr; 1108 bufptr = substream->runtime->dma_addr;
962#endif 1109#endif
963 playptr = inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS); 1110 result = inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS);
964 1111
965 result = playptr - bufptr; 1112 /* calculate offset */
966 frmres = bytes_to_frames( substream->runtime, result ); 1113 result -= bufptr;
967 snd_azf3328_dbgplay("result %lx, playptr %lx (base %x), frames %ld\n", result, playptr, substream->runtime->dma_addr, frmres); 1114 frmres = bytes_to_frames( substream->runtime, result);
1115 snd_azf3328_dbgplay("PLAY @ 0x%8lx, frames %8ld\n", result, frmres);
968 return frmres; 1116 return frmres;
969} 1117}
970 1118
971static snd_pcm_uframes_t snd_azf3328_capture_pointer(snd_pcm_substream_t * substream) 1119static snd_pcm_uframes_t
1120snd_azf3328_capture_pointer(snd_pcm_substream_t * substream)
972{ 1121{
973 azf3328_t *chip = snd_pcm_substream_chip(substream); 1122 azf3328_t *chip = snd_pcm_substream_chip(substream);
974 unsigned long bufptr, recptr; 1123 unsigned long bufptr, result;
975 unsigned long result;
976 snd_pcm_uframes_t frmres; 1124 snd_pcm_uframes_t frmres;
977 1125
978#ifdef QUERY_HARDWARE 1126#ifdef QUERY_HARDWARE
@@ -980,96 +1128,116 @@ static snd_pcm_uframes_t snd_azf3328_capture_pointer(snd_pcm_substream_t * subst
980#else 1128#else
981 bufptr = substream->runtime->dma_addr; 1129 bufptr = substream->runtime->dma_addr;
982#endif 1130#endif
983 recptr = inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS); 1131 result = inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS);
984 1132
985 result = recptr - bufptr; 1133 /* calculate offset */
986 frmres = bytes_to_frames( substream->runtime, result ); 1134 result -= bufptr;
987 snd_azf3328_dbgplay("result %lx, rec ptr %lx (base %x), frames %ld\n", result, recptr, substream->runtime->dma_addr, frmres); 1135 frmres = bytes_to_frames( substream->runtime, result);
1136 snd_azf3328_dbgplay("REC @ 0x%8lx, frames %8ld\n", result, frmres);
988 return frmres; 1137 return frmres;
989} 1138}
990 1139
991static irqreturn_t snd_azf3328_interrupt(int irq, void *dev_id, struct pt_regs *regs) 1140static irqreturn_t
1141snd_azf3328_interrupt(int irq, void *dev_id, struct pt_regs *regs)
992{ 1142{
993 azf3328_t *chip = dev_id; 1143 azf3328_t *chip = dev_id;
994 unsigned int status, which; 1144 u8 status, which;
995 static unsigned long count; 1145 static unsigned long irq_count;
996 1146
997 status = inw(chip->codec_port+IDX_IO_IRQSTATUS); 1147 status = snd_azf3328_codec_inb(chip, IDX_IO_IRQSTATUS);
998 1148
999 /* fast path out, to ease interrupt sharing */ 1149 /* fast path out, to ease interrupt sharing */
1000 if (!(status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_MPU401|IRQ_SOMEIRQ))) 1150 if (!(status & (IRQ_PLAYBACK|IRQ_RECORDING|IRQ_MPU401|IRQ_TIMER)))
1001 return IRQ_NONE; /* must be interrupt for another device */ 1151 return IRQ_NONE; /* must be interrupt for another device */
1002 1152
1003 snd_azf3328_dbgplay("Interrupt %ld!\nIDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQMASK %04x, IDX_IO_IRQSTATUS %04x\n", count, inw(chip->codec_port+IDX_IO_PLAY_FLAGS), inw(chip->codec_port+IDX_IO_PLAY_IRQMASK), inw(chip->codec_port+IDX_IO_IRQSTATUS)); 1153 snd_azf3328_dbgplay("Interrupt %ld!\nIDX_IO_PLAY_FLAGS %04x, IDX_IO_PLAY_IRQTYPE %04x, IDX_IO_IRQSTATUS %04x\n",
1154 irq_count,
1155 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_FLAGS),
1156 snd_azf3328_codec_inw(chip, IDX_IO_PLAY_IRQTYPE),
1157 status);
1004 1158
1159 if (status & IRQ_TIMER)
1160 {
1161 /* snd_azf3328_dbgplay("timer %ld\n", inl(chip->codec_port+IDX_IO_TIMER_VALUE) & TIMER_VALUE_MASK); */
1162 if (chip->timer)
1163 snd_timer_interrupt(chip->timer, chip->timer->sticks);
1164 /* ACK timer */
1165 spin_lock(&chip->reg_lock);
1166 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x07);
1167 spin_unlock(&chip->reg_lock);
1168 snd_azf3328_dbgplay("azt3328: timer IRQ\n");
1169 }
1005 if (status & IRQ_PLAYBACK) 1170 if (status & IRQ_PLAYBACK)
1006 { 1171 {
1007 spin_lock(&chip->reg_lock); 1172 spin_lock(&chip->reg_lock);
1008 which = inw(chip->codec_port+IDX_IO_PLAY_IRQMASK); 1173 which = snd_azf3328_codec_inb(chip, IDX_IO_PLAY_IRQTYPE);
1009 if (which & IRQ_FINISHED_PLAYBUF_1) 1174 /* ack all IRQ types immediately */
1010 /* ack IRQ */ 1175 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_IRQTYPE, which);
1011 outw(which | IRQ_FINISHED_PLAYBUF_1, chip->codec_port+IDX_IO_PLAY_IRQMASK); 1176 spin_unlock(&chip->reg_lock);
1012 if (which & IRQ_FINISHED_PLAYBUF_2) 1177
1013 /* ack IRQ */
1014 outw(which | IRQ_FINISHED_PLAYBUF_2, chip->codec_port+IDX_IO_PLAY_IRQMASK);
1015 if (which & IRQ_PLAY_SOMETHING)
1016 {
1017 snd_azf3328_dbgplay("azt3328: unknown play IRQ type occurred, please report!\n");
1018 }
1019 if (chip->pcm && chip->playback_substream) 1178 if (chip->pcm && chip->playback_substream)
1020 { 1179 {
1021 snd_azf3328_dbgplay("which %x, playptr %lx\n", which, inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS));
1022 snd_pcm_period_elapsed(chip->playback_substream); 1180 snd_pcm_period_elapsed(chip->playback_substream);
1023 snd_azf3328_dbgplay("period done, playptr %lx.\n", inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS)); 1181 snd_azf3328_dbgplay("PLAY period done (#%x), @ %x\n",
1182 which,
1183 inl(chip->codec_port+IDX_IO_PLAY_DMA_CURRPOS));
1024 } 1184 }
1025 else 1185 else
1026 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n"); 1186 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
1027 spin_unlock(&chip->reg_lock); 1187 if (which & IRQ_PLAY_SOMETHING)
1188 snd_azf3328_dbgplay("azt3328: unknown play IRQ type occurred, please report!\n");
1028 } 1189 }
1029 if (status & IRQ_RECORDING) 1190 if (status & IRQ_RECORDING)
1030 { 1191 {
1031 spin_lock(&chip->reg_lock); 1192 spin_lock(&chip->reg_lock);
1032 which = inw(chip->codec_port+IDX_IO_REC_IRQMASK); 1193 which = snd_azf3328_codec_inb(chip, IDX_IO_REC_IRQTYPE);
1033 if (which & IRQ_FINISHED_RECBUF_1) 1194 /* ack all IRQ types immediately */
1034 /* ack interrupt */ 1195 snd_azf3328_codec_outb(chip, IDX_IO_REC_IRQTYPE, which);
1035 outw(which | IRQ_FINISHED_RECBUF_1, chip->codec_port+IDX_IO_REC_IRQMASK); 1196 spin_unlock(&chip->reg_lock);
1036 if (which & IRQ_FINISHED_RECBUF_2) 1197
1037 /* ack interrupt */
1038 outw(which | IRQ_FINISHED_RECBUF_2, chip->codec_port+IDX_IO_REC_IRQMASK);
1039 if (which & IRQ_REC_SOMETHING)
1040 {
1041 snd_azf3328_dbgplay("azt3328: unknown rec IRQ type occurred, please report!\n");
1042 }
1043 if (chip->pcm && chip->capture_substream) 1198 if (chip->pcm && chip->capture_substream)
1044 { 1199 {
1045 snd_azf3328_dbgplay("which %x, recptr %lx\n", which, inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS));
1046 spin_unlock(&chip->reg_lock);
1047 snd_pcm_period_elapsed(chip->capture_substream); 1200 snd_pcm_period_elapsed(chip->capture_substream);
1048 spin_lock(&chip->reg_lock); 1201 snd_azf3328_dbgplay("REC period done (#%x), @ %x\n",
1049 snd_azf3328_dbgplay("period done, recptr %lx.\n", inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS)); 1202 which,
1203 inl(chip->codec_port+IDX_IO_REC_DMA_CURRPOS));
1050 } 1204 }
1051 spin_unlock(&chip->reg_lock); 1205 else
1206 snd_azf3328_dbgplay("azt3328: ouch, irq handler problem!\n");
1207 if (which & IRQ_REC_SOMETHING)
1208 snd_azf3328_dbgplay("azt3328: unknown rec IRQ type occurred, please report!\n");
1052 } 1209 }
1210 /* MPU401 has less critical IRQ requirements
1211 * than timer and playback/recording, right? */
1053 if (status & IRQ_MPU401) 1212 if (status & IRQ_MPU401)
1213 {
1054 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs); 1214 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
1055 if (status & IRQ_SOMEIRQ) 1215
1056 snd_azf3328_dbgplay("azt3328: unknown IRQ type occurred, please report!\n"); 1216 /* hmm, do we have to ack the IRQ here somehow?
1057 count++; 1217 * If so, then I don't know how... */
1218 snd_azf3328_dbgplay("azt3328: MPU401 IRQ\n");
1219 }
1220 irq_count++;
1058 return IRQ_HANDLED; 1221 return IRQ_HANDLED;
1059} 1222}
1060 1223
1061/*****************************************************************/ 1224/*****************************************************************/
1062 1225
1063static snd_pcm_hardware_t snd_azf3328_playback = 1226static const snd_pcm_hardware_t snd_azf3328_playback =
1064{ 1227{
1065 /* FIXME!! Correct? */ 1228 /* FIXME!! Correct? */
1066 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1229 .info = SNDRV_PCM_INFO_MMAP |
1067 SNDRV_PCM_INFO_MMAP_VALID), 1230 SNDRV_PCM_INFO_INTERLEAVED |
1068 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | 1231 SNDRV_PCM_INFO_MMAP_VALID,
1069 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, 1232 .formats = SNDRV_PCM_FMTBIT_S8 |
1070 .rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_KNOT, 1233 SNDRV_PCM_FMTBIT_U8 |
1071 .rate_min = 5512, 1234 SNDRV_PCM_FMTBIT_S16_LE |
1072 .rate_max = 64000, 1235 SNDRV_PCM_FMTBIT_U16_LE,
1236 .rates = SNDRV_PCM_RATE_5512 |
1237 SNDRV_PCM_RATE_8000_48000 |
1238 SNDRV_PCM_RATE_KNOT,
1239 .rate_min = 4000,
1240 .rate_max = 66200,
1073 .channels_min = 1, 1241 .channels_min = 1,
1074 .channels_max = 2, 1242 .channels_max = 2,
1075 .buffer_bytes_max = 65536, 1243 .buffer_bytes_max = 65536,
@@ -1083,16 +1251,21 @@ static snd_pcm_hardware_t snd_azf3328_playback =
1083 .fifo_size = 0, 1251 .fifo_size = 0,
1084}; 1252};
1085 1253
1086static snd_pcm_hardware_t snd_azf3328_capture = 1254static const snd_pcm_hardware_t snd_azf3328_capture =
1087{ 1255{
1088 /* FIXME */ 1256 /* FIXME */
1089 .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | 1257 .info = SNDRV_PCM_INFO_MMAP |
1090 SNDRV_PCM_INFO_MMAP_VALID), 1258 SNDRV_PCM_INFO_INTERLEAVED |
1091 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 | 1259 SNDRV_PCM_INFO_MMAP_VALID,
1092 SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE, 1260 .formats = SNDRV_PCM_FMTBIT_S8 |
1093 .rates = SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_KNOT, 1261 SNDRV_PCM_FMTBIT_U8 |
1094 .rate_min = 5512, 1262 SNDRV_PCM_FMTBIT_S16_LE |
1095 .rate_max = 64000, 1263 SNDRV_PCM_FMTBIT_U16_LE,
1264 .rates = SNDRV_PCM_RATE_5512 |
1265 SNDRV_PCM_RATE_8000_48000 |
1266 SNDRV_PCM_RATE_KNOT,
1267 .rate_min = 4000,
1268 .rate_max = 66200,
1096 .channels_min = 1, 1269 .channels_min = 1,
1097 .channels_max = 2, 1270 .channels_max = 2,
1098 .buffer_bytes_max = 65536, 1271 .buffer_bytes_max = 65536,
@@ -1105,8 +1278,8 @@ static snd_pcm_hardware_t snd_azf3328_capture =
1105 1278
1106 1279
1107static unsigned int snd_azf3328_fixed_rates[] = { 1280static unsigned int snd_azf3328_fixed_rates[] = {
1108 5512, 6620, 8000, 9600, 11025, 16000, 22050, 32000, 44100, 48000, 64000 1281 4000, 4800, 5512, 6620, 8000, 9600, 11025, 13240, 16000, 22050, 32000,
1109}; 1282 44100, 48000, 66200 };
1110static snd_pcm_hw_constraint_list_t snd_azf3328_hw_constraints_rates = { 1283static snd_pcm_hw_constraint_list_t snd_azf3328_hw_constraints_rates = {
1111 .count = ARRAY_SIZE(snd_azf3328_fixed_rates), 1284 .count = ARRAY_SIZE(snd_azf3328_fixed_rates),
1112 .list = snd_azf3328_fixed_rates, 1285 .list = snd_azf3328_fixed_rates,
@@ -1115,7 +1288,8 @@ static snd_pcm_hw_constraint_list_t snd_azf3328_hw_constraints_rates = {
1115 1288
1116/*****************************************************************/ 1289/*****************************************************************/
1117 1290
1118static int snd_azf3328_playback_open(snd_pcm_substream_t * substream) 1291static int
1292snd_azf3328_playback_open(snd_pcm_substream_t * substream)
1119{ 1293{
1120 azf3328_t *chip = snd_pcm_substream_chip(substream); 1294 azf3328_t *chip = snd_pcm_substream_chip(substream);
1121 snd_pcm_runtime_t *runtime = substream->runtime; 1295 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -1129,7 +1303,8 @@ static int snd_azf3328_playback_open(snd_pcm_substream_t * substream)
1129 return 0; 1303 return 0;
1130} 1304}
1131 1305
1132static int snd_azf3328_capture_open(snd_pcm_substream_t * substream) 1306static int
1307snd_azf3328_capture_open(snd_pcm_substream_t * substream)
1133{ 1308{
1134 azf3328_t *chip = snd_pcm_substream_chip(substream); 1309 azf3328_t *chip = snd_pcm_substream_chip(substream);
1135 snd_pcm_runtime_t *runtime = substream->runtime; 1310 snd_pcm_runtime_t *runtime = substream->runtime;
@@ -1143,7 +1318,8 @@ static int snd_azf3328_capture_open(snd_pcm_substream_t * substream)
1143 return 0; 1318 return 0;
1144} 1319}
1145 1320
1146static int snd_azf3328_playback_close(snd_pcm_substream_t * substream) 1321static int
1322snd_azf3328_playback_close(snd_pcm_substream_t * substream)
1147{ 1323{
1148 azf3328_t *chip = snd_pcm_substream_chip(substream); 1324 azf3328_t *chip = snd_pcm_substream_chip(substream);
1149 1325
@@ -1154,7 +1330,8 @@ static int snd_azf3328_playback_close(snd_pcm_substream_t * substream)
1154 return 0; 1330 return 0;
1155} 1331}
1156 1332
1157static int snd_azf3328_capture_close(snd_pcm_substream_t * substream) 1333static int
1334snd_azf3328_capture_close(snd_pcm_substream_t * substream)
1158{ 1335{
1159 azf3328_t *chip = snd_pcm_substream_chip(substream); 1336 azf3328_t *chip = snd_pcm_substream_chip(substream);
1160 1337
@@ -1188,14 +1365,16 @@ static snd_pcm_ops_t snd_azf3328_capture_ops = {
1188 .pointer = snd_azf3328_capture_pointer 1365 .pointer = snd_azf3328_capture_pointer
1189}; 1366};
1190 1367
1191static void snd_azf3328_pcm_free(snd_pcm_t *pcm) 1368static void
1369snd_azf3328_pcm_free(snd_pcm_t *pcm)
1192{ 1370{
1193 azf3328_t *chip = pcm->private_data; 1371 azf3328_t *chip = pcm->private_data;
1194 chip->pcm = NULL; 1372 chip->pcm = NULL;
1195 snd_pcm_lib_preallocate_free_for_all(pcm); 1373 snd_pcm_lib_preallocate_free_for_all(pcm);
1196} 1374}
1197 1375
1198static int __devinit snd_azf3328_pcm(azf3328_t *chip, int device) 1376static int __devinit
1377snd_azf3328_pcm(azf3328_t *chip, int device)
1199{ 1378{
1200 snd_pcm_t *pcm; 1379 snd_pcm_t *pcm;
1201 int err; 1380 int err;
@@ -1222,7 +1401,8 @@ static int __devinit snd_azf3328_pcm(azf3328_t *chip, int device)
1222/******************************************************************/ 1401/******************************************************************/
1223 1402
1224#ifdef SUPPORT_JOYSTICK 1403#ifdef SUPPORT_JOYSTICK
1225static int __devinit snd_azf3328_config_joystick(azf3328_t *chip, int dev) 1404static int __devinit
1405snd_azf3328_config_joystick(azf3328_t *chip, int dev)
1226{ 1406{
1227 struct gameport *gp; 1407 struct gameport *gp;
1228 struct resource *r; 1408 struct resource *r;
@@ -1238,8 +1418,7 @@ static int __devinit snd_azf3328_config_joystick(azf3328_t *chip, int dev)
1238 chip->gameport = gp = gameport_allocate_port(); 1418 chip->gameport = gp = gameport_allocate_port();
1239 if (!gp) { 1419 if (!gp) {
1240 printk(KERN_ERR "azt3328: cannot allocate memory for gameport\n"); 1420 printk(KERN_ERR "azt3328: cannot allocate memory for gameport\n");
1241 release_resource(r); 1421 release_and_free_resource(r);
1242 kfree_nocheck(r);
1243 return -ENOMEM; 1422 return -ENOMEM;
1244 } 1423 }
1245 1424
@@ -1249,15 +1428,16 @@ static int __devinit snd_azf3328_config_joystick(azf3328_t *chip, int dev)
1249 gp->io = 0x200; 1428 gp->io = 0x200;
1250 gameport_set_port_data(gp, r); 1429 gameport_set_port_data(gp, r);
1251 1430
1252 snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR, 1431 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1253 snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) | LEGACY_JOY); 1432 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) | LEGACY_JOY);
1254 1433
1255 gameport_register_port(chip->gameport); 1434 gameport_register_port(chip->gameport);
1256 1435
1257 return 0; 1436 return 0;
1258} 1437}
1259 1438
1260static void snd_azf3328_free_joystick(azf3328_t *chip) 1439static void
1440snd_azf3328_free_joystick(azf3328_t *chip)
1261{ 1441{
1262 if (chip->gameport) { 1442 if (chip->gameport) {
1263 struct resource *r = gameport_get_port_data(chip->gameport); 1443 struct resource *r = gameport_get_port_data(chip->gameport);
@@ -1265,33 +1445,36 @@ static void snd_azf3328_free_joystick(azf3328_t *chip)
1265 gameport_unregister_port(chip->gameport); 1445 gameport_unregister_port(chip->gameport);
1266 chip->gameport = NULL; 1446 chip->gameport = NULL;
1267 /* disable gameport */ 1447 /* disable gameport */
1268 snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR, 1448 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1269 snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY); 1449 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
1270 release_resource(r); 1450 release_and_free_resource(r);
1271 kfree_nocheck(r);
1272 } 1451 }
1273} 1452}
1274#else 1453#else
1275static inline int snd_azf3328_config_joystick(azf3328_t *chip, int dev) { return -ENOSYS; } 1454static inline int
1276static inline void snd_azf3328_free_joystick(azf3328_t *chip) { } 1455snd_azf3328_config_joystick(azf3328_t *chip, int dev) { return -ENOSYS; }
1456static inline void
1457snd_azf3328_free_joystick(azf3328_t *chip) { }
1277#endif 1458#endif
1278 1459
1279/******************************************************************/ 1460/******************************************************************/
1280 1461
1281static int snd_azf3328_free(azf3328_t *chip) 1462static int
1463snd_azf3328_free(azf3328_t *chip)
1282{ 1464{
1283 if (chip->irq < 0) 1465 if (chip->irq < 0)
1284 goto __end_hw; 1466 goto __end_hw;
1285 1467
1286 /* reset (close) mixer */ 1468 /* reset (close) mixer */
1287 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */ 1469 snd_azf3328_mixer_set_mute(chip, IDX_MIXER_PLAY_MASTER, 1); /* first mute master volume */
1288 snd_azf3328_mixer_write(chip, IDX_MIXER_RESET, 0x0, WORD_VALUE); 1470 snd_azf3328_mixer_outw(chip, IDX_MIXER_RESET, 0x0000);
1289 1471
1290 /* interrupt setup - mask everything */ 1472 /* interrupt setup - mask everything (FIXME!) */
1291 /* FIXME */ 1473 /* well, at least we know how to disable the timer IRQ */
1474 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
1292 1475
1293 synchronize_irq(chip->irq); 1476 synchronize_irq(chip->irq);
1294 __end_hw: 1477__end_hw:
1295 snd_azf3328_free_joystick(chip); 1478 snd_azf3328_free_joystick(chip);
1296 if (chip->irq >= 0) 1479 if (chip->irq >= 0)
1297 free_irq(chip->irq, (void *)chip); 1480 free_irq(chip->irq, (void *)chip);
@@ -1302,15 +1485,129 @@ static int snd_azf3328_free(azf3328_t *chip)
1302 return 0; 1485 return 0;
1303} 1486}
1304 1487
1305static int snd_azf3328_dev_free(snd_device_t *device) 1488static int
1489snd_azf3328_dev_free(snd_device_t *device)
1306{ 1490{
1307 azf3328_t *chip = device->device_data; 1491 azf3328_t *chip = device->device_data;
1308 return snd_azf3328_free(chip); 1492 return snd_azf3328_free(chip);
1309} 1493}
1310 1494
1495/******************************************************************/
1496
1497/*** NOTE: the physical timer resolution actually is 1024000 ticks per second,
1498 *** but announcing those attributes to user-space would make programs
1499 *** configure the timer to a 1 tick value, resulting in an absolutely fatal
1500 *** timer IRQ storm.
1501 *** Thus I chose to announce a down-scaled virtual timer to the outside and
1502 *** calculate real timer countdown values internally.
1503 *** (the scale factor can be set via module parameter "seqtimer_scaling").
1504 ***/
1505
1506static int
1507snd_azf3328_timer_start(snd_timer_t *timer)
1508{
1509 azf3328_t *chip;
1510 unsigned long flags;
1511 unsigned int delay;
1512
1513 snd_azf3328_dbgcallenter();
1514 chip = snd_timer_chip(timer);
1515 delay = ((timer->sticks * seqtimer_scaling) - 1) & TIMER_VALUE_MASK;
1516 if (delay < 49)
1517 {
1518 /* uhoh, that's not good, since user-space won't know about
1519 * this timing tweak
1520 * (we need to do it to avoid a lockup, though) */
1521
1522 snd_azf3328_dbgtimer("delay was too low (%d)!\n", delay);
1523 delay = 49; /* minimum time is 49 ticks */
1524 }
1525 snd_azf3328_dbgtimer("setting timer countdown value %d, add COUNTDOWN|IRQ\n", delay);
1526 delay |= TIMER_ENABLE_COUNTDOWN | TIMER_ENABLE_IRQ;
1527 spin_lock_irqsave(&chip->reg_lock, flags);
1528 snd_azf3328_codec_outl(chip, IDX_IO_TIMER_VALUE, delay);
1529 spin_unlock_irqrestore(&chip->reg_lock, flags);
1530 snd_azf3328_dbgcallleave();
1531 return 0;
1532}
1533
1534static int
1535snd_azf3328_timer_stop(snd_timer_t *timer)
1536{
1537 azf3328_t *chip;
1538 unsigned long flags;
1539
1540 snd_azf3328_dbgcallenter();
1541 chip = snd_timer_chip(timer);
1542 spin_lock_irqsave(&chip->reg_lock, flags);
1543 /* disable timer countdown and interrupt */
1544 /* FIXME: should we write TIMER_ACK_IRQ here? */
1545 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0);
1546 spin_unlock_irqrestore(&chip->reg_lock, flags);
1547 snd_azf3328_dbgcallleave();
1548 return 0;
1549}
1550
1551
1552static int
1553snd_azf3328_timer_precise_resolution(snd_timer_t *timer,
1554 unsigned long *num, unsigned long *den)
1555{
1556 snd_azf3328_dbgcallenter();
1557 *num = 1;
1558 *den = 1024000 / seqtimer_scaling;
1559 snd_azf3328_dbgcallleave();
1560 return 0;
1561}
1562
1563static struct _snd_timer_hardware snd_azf3328_timer_hw = {
1564 .flags = SNDRV_TIMER_HW_AUTO,
1565 .resolution = 977, /* 1000000/1024000 = 0.9765625us */
1566 .ticks = 1024000, /* max tick count, defined by the value register; actually it's not 1024000, but 1048576, but we don't care */
1567 .start = snd_azf3328_timer_start,
1568 .stop = snd_azf3328_timer_stop,
1569 .precise_resolution = snd_azf3328_timer_precise_resolution,
1570};
1571
1572static int __devinit
1573snd_azf3328_timer(azf3328_t *chip, int device)
1574{
1575 snd_timer_t *timer = NULL;
1576 snd_timer_id_t tid;
1577 int err;
1578
1579 snd_azf3328_dbgcallenter();
1580 tid.dev_class = SNDRV_TIMER_CLASS_CARD;
1581 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1582 tid.card = chip->card->number;
1583 tid.device = device;
1584 tid.subdevice = 0;
1585
1586 snd_azf3328_timer_hw.resolution *= seqtimer_scaling;
1587 snd_azf3328_timer_hw.ticks /= seqtimer_scaling;
1588 if ((err = snd_timer_new(chip->card, "AZF3328", &tid, &timer)) < 0) {
1589 goto out;
1590 }
1591
1592 strcpy(timer->name, "AZF3328 timer");
1593 timer->private_data = chip;
1594 timer->hw = snd_azf3328_timer_hw;
1595
1596 chip->timer = timer;
1597
1598 err = 0;
1599
1600out:
1601 snd_azf3328_dbgcallleave();
1602 return err;
1603}
1604
1605/******************************************************************/
1606
1311#if 0 1607#if 0
1312/* check whether a bit can be modified */ 1608/* check whether a bit can be modified */
1313static void snd_azf3328_test_bit(unsigned int reg, int bit) 1609static void
1610snd_azf3328_test_bit(unsigned int reg, int bit)
1314{ 1611{
1315 unsigned char val, valoff, valon; 1612 unsigned char val, valoff, valon;
1316 1613
@@ -1328,7 +1625,26 @@ static void snd_azf3328_test_bit(unsigned int reg, int bit)
1328} 1625}
1329#endif 1626#endif
1330 1627
1331static int __devinit snd_azf3328_create(snd_card_t * card, 1628static void
1629snd_azf3328_debug_show_ports(const azf3328_t *chip)
1630{
1631#if DEBUG_MISC
1632 u16 tmp;
1633
1634 snd_azf3328_dbgmisc("codec_port 0x%lx, io2_port 0x%lx, mpu_port 0x%lx, synth_port 0x%lx, mixer_port 0x%lx, irq %d\n", chip->codec_port, chip->io2_port, chip->mpu_port, chip->synth_port, chip->mixer_port, chip->irq);
1635
1636 snd_azf3328_dbgmisc("io2 %02x %02x %02x %02x %02x %02x\n", snd_azf3328_io2_inb(chip, 0), snd_azf3328_io2_inb(chip, 1), snd_azf3328_io2_inb(chip, 2), snd_azf3328_io2_inb(chip, 3), snd_azf3328_io2_inb(chip, 4), snd_azf3328_io2_inb(chip, 5));
1637
1638 for (tmp=0; tmp <= 0x01; tmp += 1)
1639 snd_azf3328_dbgmisc("0x%02x: opl 0x%04x, mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, mpu330 0x%04x\n", tmp, inb(0x388 + tmp), inb(0x300 + tmp), inb(0x310 + tmp), inb(0x320 + tmp), inb(0x330 + tmp));
1640
1641 for (tmp = 0; tmp <= 0x6E; tmp += 2)
1642 snd_azf3328_dbgmisc("0x%02x: 0x%04x\n", tmp, snd_azf3328_codec_inb(chip, tmp));
1643#endif
1644}
1645
1646static int __devinit
1647snd_azf3328_create(snd_card_t * card,
1332 struct pci_dev *pci, 1648 struct pci_dev *pci,
1333 unsigned long device_type, 1649 unsigned long device_type,
1334 azf3328_t ** rchip) 1650 azf3328_t ** rchip)
@@ -1347,8 +1663,8 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
1347 1663
1348 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1664 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1349 if (chip == NULL) { 1665 if (chip == NULL) {
1350 pci_disable_device(pci); 1666 err = -ENOMEM;
1351 return -ENOMEM; 1667 goto out_err;
1352 } 1668 }
1353 spin_lock_init(&chip->reg_lock); 1669 spin_lock_init(&chip->reg_lock);
1354 chip->card = card; 1670 chip->card = card;
@@ -1358,47 +1674,39 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
1358 /* check if we can restrict PCI DMA transfers to 24 bits */ 1674 /* check if we can restrict PCI DMA transfers to 24 bits */
1359 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 1675 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
1360 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 1676 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
1361 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 1677 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
1362 pci_disable_device(pci); 1678 err = -ENXIO;
1363 return -ENXIO; 1679 goto out_err;
1364 } 1680 }
1365 1681
1366 if ((err = pci_request_regions(pci, "Aztech AZF3328")) < 0) { 1682 if ((err = pci_request_regions(pci, "Aztech AZF3328")) < 0) {
1367 kfree(chip); 1683 goto out_err;
1368 pci_disable_device(pci);
1369 return err;
1370 } 1684 }
1371 1685
1372 chip->codec_port = pci_resource_start(pci, 0); 1686 chip->codec_port = pci_resource_start(pci, 0);
1373 chip->io2_port = pci_resource_start(pci, 1); 1687 chip->io2_port = pci_resource_start(pci, 1);
1374 chip->mpu_port = pci_resource_start(pci, 2); 1688 chip->mpu_port = pci_resource_start(pci, 2);
1375 chip->synth_port = pci_resource_start(pci, 3); 1689 chip->synth_port = pci_resource_start(pci, 3);
1376 chip->mixer_port = pci_resource_start(pci, 4); 1690 chip->mixer_port = pci_resource_start(pci, 4);
1377 1691
1378 if (request_irq(pci->irq, snd_azf3328_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) { 1692 if (request_irq(pci->irq, snd_azf3328_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
1379 snd_printk("unable to grab IRQ %d\n", pci->irq); 1693 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1380 snd_azf3328_free(chip); 1694 err = -EBUSY;
1381 return -EBUSY; 1695 goto out_err;
1382 } 1696 }
1383 chip->irq = pci->irq; 1697 chip->irq = pci->irq;
1384 pci_set_master(pci); 1698 pci_set_master(pci);
1385 synchronize_irq(chip->irq); 1699 synchronize_irq(chip->irq);
1386 1700
1387 snd_azf3328_dbgmisc("codec_port 0x%lx, io2_port 0x%lx, mpu_port 0x%lx, synth_port 0x%lx, mixer_port 0x%lx, irq %d\n", chip->codec_port, chip->io2_port, chip->mpu_port, chip->synth_port, chip->mixer_port, chip->irq); 1701 snd_azf3328_debug_show_ports(chip);
1388 1702
1389 snd_azf3328_dbgmisc("io2 %02x %02x %02x %02x %02x %02x\n", snd_azf3328_io2_read(chip, 0), snd_azf3328_io2_read(chip, 1), snd_azf3328_io2_read(chip, 2), snd_azf3328_io2_read(chip, 3), snd_azf3328_io2_read(chip, 4), snd_azf3328_io2_read(chip, 5));
1390
1391 for (tmp=0; tmp <= 0x01; tmp += 1)
1392 snd_azf3328_dbgmisc("0x%02x: opl 0x%04x, mpu300 0x%04x, mpu310 0x%04x, mpu320 0x%04x, mpu330 0x%04x\n", tmp, inb(0x388 + tmp), inb(0x300 + tmp), inb(0x310 + tmp), inb(0x320 + tmp), inb(0x330 + tmp));
1393
1394 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { 1703 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1395 snd_azf3328_free(chip); 1704 goto out_err;
1396 return err;
1397 } 1705 }
1398 1706
1399 /* create mixer interface & switches */ 1707 /* create mixer interface & switches */
1400 if ((err = snd_azf3328_mixer_new(chip)) < 0) 1708 if ((err = snd_azf3328_mixer_new(chip)) < 0)
1401 return err; 1709 goto out_err;
1402 1710
1403#if 0 1711#if 0
1404 /* set very low bitrate to reduce noise and power consumption? */ 1712 /* set very low bitrate to reduce noise and power consumption? */
@@ -1406,22 +1714,34 @@ static int __devinit snd_azf3328_create(snd_card_t * card,
1406#endif 1714#endif
1407 1715
1408 /* standard chip init stuff */ 1716 /* standard chip init stuff */
1409 spin_lock_irq(&chip->reg_lock); 1717 /* default IRQ init value */
1410 outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_PLAY_FLAGS); 1718 tmp = DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE;
1411 outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_SOMETHING_FLAGS);
1412 outb(DMA_PLAY_SOMETHING2|DMA_EPILOGUE_SOMETHING|DMA_SOMETHING_ELSE, chip->codec_port + IDX_IO_REC_FLAGS);
1413 outb(0x0, chip->codec_port + IDX_IO_IRQ63H);
1414 1719
1720 spin_lock_irq(&chip->reg_lock);
1721 snd_azf3328_codec_outb(chip, IDX_IO_PLAY_FLAGS, tmp);
1722 snd_azf3328_codec_outb(chip, IDX_IO_REC_FLAGS, tmp);
1723 snd_azf3328_codec_outb(chip, IDX_IO_SOMETHING_FLAGS, tmp);
1724 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00); /* disable timer */
1415 spin_unlock_irq(&chip->reg_lock); 1725 spin_unlock_irq(&chip->reg_lock);
1416 1726
1417 snd_card_set_dev(card, &pci->dev); 1727 snd_card_set_dev(card, &pci->dev);
1418 1728
1419 *rchip = chip; 1729 *rchip = chip;
1420 return 0; 1730
1731 err = 0;
1732 goto out;
1733
1734out_err:
1735 if (chip)
1736 snd_azf3328_free(chip);
1737 pci_disable_device(pci);
1738
1739out:
1740 return err;
1421} 1741}
1422 1742
1423static int __devinit snd_azf3328_probe(struct pci_dev *pci, 1743static int __devinit
1424 const struct pci_device_id *pci_id) 1744snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1425{ 1745{
1426 static int dev; 1746 static int dev;
1427 snd_card_t *card; 1747 snd_card_t *card;
@@ -1445,63 +1765,70 @@ static int __devinit snd_azf3328_probe(struct pci_dev *pci,
1445 strcpy(card->shortname, "Aztech AZF3328 (PCI168)"); 1765 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
1446 1766
1447 if ((err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip)) < 0) { 1767 if ((err = snd_azf3328_create(card, pci, pci_id->driver_data, &chip)) < 0) {
1448 snd_card_free(card); 1768 goto out_err;
1449 return err;
1450 } 1769 }
1451 1770
1452 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_MPU401, 1771 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_MPU401,
1453 chip->mpu_port, 1, pci->irq, 0, 1772 chip->mpu_port, 1, pci->irq, 0,
1454 &chip->rmidi)) < 0) { 1773 &chip->rmidi)) < 0) {
1455 snd_printk("azf3328: no MPU-401 device at 0x%lx?\n", chip->mpu_port); 1774 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", chip->mpu_port);
1456 snd_card_free(card); 1775 goto out_err;
1457 return err; 1776 }
1777
1778 if ((err = snd_azf3328_timer(chip, 0)) < 0) {
1779 goto out_err;
1458 } 1780 }
1459 1781
1460 if ((err = snd_azf3328_pcm(chip, 0)) < 0) { 1782 if ((err = snd_azf3328_pcm(chip, 0)) < 0) {
1461 snd_card_free(card); 1783 goto out_err;
1462 return err;
1463 } 1784 }
1464 1785
1465 if (snd_opl3_create(card, chip->synth_port, chip->synth_port+2, 1786 if (snd_opl3_create(card, chip->synth_port, chip->synth_port+2,
1466 OPL3_HW_AUTO, 1, &opl3) < 0) { 1787 OPL3_HW_AUTO, 1, &opl3) < 0) {
1467 snd_printk("azf3328: no OPL3 device at 0x%lx-0x%lx?\n", 1788 snd_printk(KERN_ERR "azf3328: no OPL3 device at 0x%lx-0x%lx?\n",
1468 chip->synth_port, chip->synth_port+2 ); 1789 chip->synth_port, chip->synth_port+2 );
1469 } else { 1790 } else {
1470 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 1791 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
1471 snd_card_free(card); 1792 goto out_err;
1472 return err;
1473 } 1793 }
1474 } 1794 }
1475 1795
1476 snd_azf3328_dbgio(chip, "create");
1477
1478 sprintf(card->longname, "%s at 0x%lx, irq %i", 1796 sprintf(card->longname, "%s at 0x%lx, irq %i",
1479 card->shortname, chip->codec_port, chip->irq); 1797 card->shortname, chip->codec_port, chip->irq);
1480 1798
1481 if ((err = snd_card_register(card)) < 0) { 1799 if ((err = snd_card_register(card)) < 0) {
1482 snd_card_free(card); 1800 goto out_err;
1483 return err;
1484 } 1801 }
1485 1802
1486#ifdef MODULE 1803#ifdef MODULE
1487 printk( 1804 printk(
1488"azt3328: Experimental driver for Aztech AZF3328-based soundcards such as PCI168.\n" 1805"azt3328: Sound driver for Aztech AZF3328-based soundcards such as PCI168\n"
1489"azt3328: ZERO support from Aztech: you might think hard about future purchase.\n" 1806"azt3328: (hardware was completely undocumented - ZERO support from Aztech).\n"
1490"azt3328: Feel free to contact hw7oshyuv3001@sneakemail.com for bug reports etc.!\n"); 1807"azt3328: Feel free to contact andi AT lisas.de for bug reports etc.!\n"
1808"azt3328: User-scalable sequencer timer set to %dHz (1024000Hz / %d).\n",
1809 1024000 / seqtimer_scaling, seqtimer_scaling);
1491#endif 1810#endif
1492 1811
1493 if (snd_azf3328_config_joystick(chip, dev) < 0) 1812 if (snd_azf3328_config_joystick(chip, dev) < 0)
1494 snd_azf3328_io2_write(chip, IDX_IO2_LEGACY_ADDR, 1813 snd_azf3328_io2_outb(chip, IDX_IO2_LEGACY_ADDR,
1495 snd_azf3328_io2_read(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY); 1814 snd_azf3328_io2_inb(chip, IDX_IO2_LEGACY_ADDR) & ~LEGACY_JOY);
1496 1815
1497 pci_set_drvdata(pci, card); 1816 pci_set_drvdata(pci, card);
1498 dev++; 1817 dev++;
1499 1818
1819 err = 0;
1820 goto out;
1821
1822out_err:
1823 snd_card_free(card);
1824
1825out:
1500 snd_azf3328_dbgcallleave(); 1826 snd_azf3328_dbgcallleave();
1501 return 0; 1827 return err;
1502} 1828}
1503 1829
1504static void __devexit snd_azf3328_remove(struct pci_dev *pci) 1830static void __devexit
1831snd_azf3328_remove(struct pci_dev *pci)
1505{ 1832{
1506 snd_azf3328_dbgcallenter(); 1833 snd_azf3328_dbgcallenter();
1507 snd_card_free(pci_get_drvdata(pci)); 1834 snd_card_free(pci_get_drvdata(pci));
@@ -1517,7 +1844,8 @@ static struct pci_driver driver = {
1517 .remove = __devexit_p(snd_azf3328_remove), 1844 .remove = __devexit_p(snd_azf3328_remove),
1518}; 1845};
1519 1846
1520static int __init alsa_card_azf3328_init(void) 1847static int __init
1848alsa_card_azf3328_init(void)
1521{ 1849{
1522 int err; 1850 int err;
1523 snd_azf3328_dbgcallenter(); 1851 snd_azf3328_dbgcallenter();
@@ -1526,7 +1854,8 @@ static int __init alsa_card_azf3328_init(void)
1526 return err; 1854 return err;
1527} 1855}
1528 1856
1529static void __exit alsa_card_azf3328_exit(void) 1857static void __exit
1858alsa_card_azf3328_exit(void)
1530{ 1859{
1531 snd_azf3328_dbgcallenter(); 1860 snd_azf3328_dbgcallenter();
1532 pci_unregister_driver(&driver); 1861 pci_unregister_driver(&driver);
diff --git a/sound/pci/azt3328.h b/sound/pci/azt3328.h
index 7e0e79180977..f489bdaf6d40 100644
--- a/sound/pci/azt3328.h
+++ b/sound/pci/azt3328.h
@@ -1,19 +1,17 @@
1#ifndef __SOUND_AZF3328_H 1#ifndef __SOUND_AZT3328_H
2#define __SOUND_AZF3328_H 2#define __SOUND_AZT3328_H
3 3
4/* type argument to use for the I/O functions */ 4/* "PU" == "power-up value", as tested on PCI168 PCI rev. 10 */
5#define WORD_VALUE 0x1000
6#define DWORD_VALUE 0x2000
7#define BYTE_VALUE 0x4000
8 5
9/*** main I/O area port indices ***/ 6/*** main I/O area port indices ***/
10/* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */ 7/* (only 0x70 of 0x80 bytes saved/restored by Windows driver) */
11/* the driver initialisation suggests a layout of 3 main areas: 8/* the driver initialisation suggests a layout of 4 main areas:
12 * from 0x00 (playback), from 0x20 (recording) and from 0x40 (maybe DirectX 9 * from 0x00 (playback), from 0x20 (recording) and from 0x40 (maybe MPU401??).
13 * timer ???). and probably another area from 0x60 to 0x6f 10 * And another area from 0x60 to 0x6f (DirectX timer, IRQ management,
14 * (IRQ management, power management etc. ???). */ 11 * power management etc.???). */
15/* playback area */ 12
16#define IDX_IO_PLAY_FLAGS 0x00 13/** playback area **/
14#define IDX_IO_PLAY_FLAGS 0x00 /* PU:0x0000 */
17 /* able to reactivate output after output muting due to 8/16bit 15 /* able to reactivate output after output muting due to 8/16bit
18 * output change, just like 0x0002. 16 * output change, just like 0x0002.
19 * 0x0001 is the only bit that's able to start the DMA counter */ 17 * 0x0001 is the only bit that's able to start the DMA counter */
@@ -29,7 +27,7 @@
29 #define DMA_EPILOGUE_SOMETHING 0x0010 27 #define DMA_EPILOGUE_SOMETHING 0x0010
30 #define DMA_SOMETHING_ELSE 0x0020 /* ??? */ 28 #define DMA_SOMETHING_ELSE 0x0020 /* ??? */
31 #define SOMETHING_UNMODIFIABLE 0xffc0 /* unused ? not modifiable */ 29 #define SOMETHING_UNMODIFIABLE 0xffc0 /* unused ? not modifiable */
32#define IDX_IO_PLAY_IRQMASK 0x02 30#define IDX_IO_PLAY_IRQTYPE 0x02 /* PU:0x0001 */
33 /* write back to flags in case flags are set, in order to ACK IRQ in handler 31 /* write back to flags in case flags are set, in order to ACK IRQ in handler
34 * (bit 1 of port 0x64 indicates interrupt for one of these three types) 32 * (bit 1 of port 0x64 indicates interrupt for one of these three types)
35 * sometimes in this case it just writes 0xffff to globally ACK all IRQs 33 * sometimes in this case it just writes 0xffff to globally ACK all IRQs
@@ -41,36 +39,39 @@
41 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */ 39 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
42 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */ 40 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
43 #define IRQMASK_UNMODIFIABLE 0xffe0 /* unused ? not modifiable */ 41 #define IRQMASK_UNMODIFIABLE 0xffe0 /* unused ? not modifiable */
44#define IDX_IO_PLAY_DMA_START_1 0x04 /* start address of 1st DMA play area */ 42#define IDX_IO_PLAY_DMA_START_1 0x04 /* start address of 1st DMA play area, PU:0x00000000 */
45#define IDX_IO_PLAY_DMA_START_2 0x08 /* start address of 2nd DMA play area */ 43#define IDX_IO_PLAY_DMA_START_2 0x08 /* start address of 2nd DMA play area, PU:0x00000000 */
46#define IDX_IO_PLAY_DMA_LEN_1 0x0c /* length of 1st DMA play area */ 44#define IDX_IO_PLAY_DMA_LEN_1 0x0c /* length of 1st DMA play area, PU:0x0000 */
47#define IDX_IO_PLAY_DMA_LEN_2 0x0e /* length of 2nd DMA play area */ 45#define IDX_IO_PLAY_DMA_LEN_2 0x0e /* length of 2nd DMA play area, PU:0x0000 */
48#define IDX_IO_PLAY_DMA_CURRPOS 0x10 /* current DMA position */ 46#define IDX_IO_PLAY_DMA_CURRPOS 0x10 /* current DMA position, PU:0x00000000 */
49#define IDX_IO_PLAY_DMA_CURROFS 0x14 /* offset within current DMA play area */ 47#define IDX_IO_PLAY_DMA_CURROFS 0x14 /* offset within current DMA play area, PU:0x0000 */
50#define IDX_IO_PLAY_SOUNDFORMAT 0x16 48#define IDX_IO_PLAY_SOUNDFORMAT 0x16 /* PU:0x0010 */
51 /* all unspecified bits can't be modified */ 49 /* all unspecified bits can't be modified */
52 #define SOUNDFORMAT_FREQUENCY_MASK 0x000f 50 #define SOUNDFORMAT_FREQUENCY_MASK 0x000f
51 #define SOUNDFORMAT_XTAL1 0x00
52 #define SOUNDFORMAT_XTAL2 0x01
53 /* all _SUSPECTED_ values are not used by Windows drivers, so we don't 53 /* all _SUSPECTED_ values are not used by Windows drivers, so we don't
54 * have any hard facts, only rough measurements */ 54 * have any hard facts, only rough measurements */
55 #define SOUNDFORMAT_FREQ_SUSPECTED_4000 0x0c 55 #define SOUNDFORMAT_FREQ_SUSPECTED_4000 0x0c | SOUNDFORMAT_XTAL1
56 #define SOUNDFORMAT_FREQ_SUSPECTED_4800 0x0a 56 #define SOUNDFORMAT_FREQ_SUSPECTED_4800 0x0a | SOUNDFORMAT_XTAL1
57 #define SOUNDFORMAT_FREQ_5510 0x0d 57 #define SOUNDFORMAT_FREQ_5510 0x0c | SOUNDFORMAT_XTAL2
58 #define SOUNDFORMAT_FREQ_6620 0x0b 58 #define SOUNDFORMAT_FREQ_6620 0x0a | SOUNDFORMAT_XTAL2
59 #define SOUNDFORMAT_FREQ_8000 0x00 /* also 0x0e ? */ 59 #define SOUNDFORMAT_FREQ_8000 0x00 | SOUNDFORMAT_XTAL1 /* also 0x0e | SOUNDFORMAT_XTAL1? */
60 #define SOUNDFORMAT_FREQ_9600 0x08 60 #define SOUNDFORMAT_FREQ_9600 0x08 | SOUNDFORMAT_XTAL1
61 #define SOUNDFORMAT_FREQ_SUSPECTED_12000 0x09 61 #define SOUNDFORMAT_FREQ_11025 0x00 | SOUNDFORMAT_XTAL2 /* also 0x0e | SOUNDFORMAT_XTAL2? */
62 #define SOUNDFORMAT_FREQ_11025 0x01 /* also 0x0f ? */ 62 #define SOUNDFORMAT_FREQ_SUSPECTED_13240 0x08 | SOUNDFORMAT_XTAL2 /* seems to be 6620 *2 */
63 #define SOUNDFORMAT_FREQ_16000 0x02 63 #define SOUNDFORMAT_FREQ_16000 0x02 | SOUNDFORMAT_XTAL1
64 #define SOUNDFORMAT_FREQ_22050 0x03 64 #define SOUNDFORMAT_FREQ_22050 0x02 | SOUNDFORMAT_XTAL2
65 #define SOUNDFORMAT_FREQ_32000 0x04 65 #define SOUNDFORMAT_FREQ_32000 0x04 | SOUNDFORMAT_XTAL1
66 #define SOUNDFORMAT_FREQ_44100 0x05 66 #define SOUNDFORMAT_FREQ_44100 0x04 | SOUNDFORMAT_XTAL2
67 #define SOUNDFORMAT_FREQ_48000 0x06 67 #define SOUNDFORMAT_FREQ_48000 0x06 | SOUNDFORMAT_XTAL1
68 #define SOUNDFORMAT_FREQ_SUSPECTED_64000 0x07 68 #define SOUNDFORMAT_FREQ_SUSPECTED_66200 0x06 | SOUNDFORMAT_XTAL2 /* 66200 (13240 * 5); 64000 may have been nicer :-\ */
69 #define SOUNDFORMAT_FLAG_16BIT 0x0010 69 #define SOUNDFORMAT_FLAG_16BIT 0x0010
70 #define SOUNDFORMAT_FLAG_2CHANNELS 0x0020 70 #define SOUNDFORMAT_FLAG_2CHANNELS 0x0020
71/* recording area (see also: playback bit flag definitions) */ 71
72#define IDX_IO_REC_FLAGS 0x20 /* ?? */ 72/** recording area (see also: playback bit flag definitions) **/
73#define IDX_IO_REC_IRQMASK 0x22 /* ?? */ 73#define IDX_IO_REC_FLAGS 0x20 /* ??, PU:0x0000 */
74#define IDX_IO_REC_IRQTYPE 0x22 /* ??, PU:0x0000 */
74 #define IRQ_REC_SOMETHING 0x0001 /* something & ACK */ 75 #define IRQ_REC_SOMETHING 0x0001 /* something & ACK */
75 #define IRQ_FINISHED_RECBUF_1 0x0002 /* 1st dmabuf finished & ACK */ 76 #define IRQ_FINISHED_RECBUF_1 0x0002 /* 1st dmabuf finished & ACK */
76 #define IRQ_FINISHED_RECBUF_2 0x0004 /* 2nd dmabuf finished & ACK */ 77 #define IRQ_FINISHED_RECBUF_2 0x0004 /* 2nd dmabuf finished & ACK */
@@ -78,39 +79,47 @@
78 * but OTOH they are most likely at port 0x22 instead */ 79 * but OTOH they are most likely at port 0x22 instead */
79 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */ 80 #define IRQMASK_SOME_STATUS_1 0x0008 /* \ related bits */
80 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */ 81 #define IRQMASK_SOME_STATUS_2 0x0010 /* / (checked together in loop) */
81#define IDX_IO_REC_DMA_START_1 0x24 82#define IDX_IO_REC_DMA_START_1 0x24 /* PU:0x00000000 */
82#define IDX_IO_REC_DMA_START_2 0x28 83#define IDX_IO_REC_DMA_START_2 0x28 /* PU:0x00000000 */
83#define IDX_IO_REC_DMA_LEN_1 0x2c 84#define IDX_IO_REC_DMA_LEN_1 0x2c /* PU:0x0000 */
84#define IDX_IO_REC_DMA_LEN_2 0x2e 85#define IDX_IO_REC_DMA_LEN_2 0x2e /* PU:0x0000 */
85#define IDX_IO_REC_DMA_CURRPOS 0x30 86#define IDX_IO_REC_DMA_CURRPOS 0x30 /* PU:0x00000000 */
86#define IDX_IO_REC_DMA_CURROFS 0x34 87#define IDX_IO_REC_DMA_CURROFS 0x34 /* PU:0x00000000 */
87#define IDX_IO_REC_SOUNDFORMAT 0x36 88#define IDX_IO_REC_SOUNDFORMAT 0x36 /* PU:0x0000 */
88/* some third area ? (after playback and recording) */ 89
89#define IDX_IO_SOMETHING_FLAGS 0x40 /* gets set to 0x34 just like port 0x0 and 0x20 on card init */ 90/** hmm, what is this I/O area for? MPU401?? (after playback, recording, ???, timer) **/
91#define IDX_IO_SOMETHING_FLAGS 0x40 /* gets set to 0x34 just like port 0x0 and 0x20 on card init, PU:0x0000 */
90/* general */ 92/* general */
91#define IDX_IO_60H 0x60 /* writing 0xffff returns 0xffff */ 93#define IDX_IO_42H 0x42 /* PU:0x0001 */
92#define IDX_IO_62H 0x62 /* writing to WORD 0x0062 can hang the box ! --> responsible for IRQ management as a whole ?? */ 94
93#define IDX_IO_IRQ63H 0x63 /* FIXME !! */ 95/** DirectX timer, main interrupt area (FIXME: and something else?) **/
94 #define IO_IRQ63H_SOMETHING 0x04 /* being set in IRQ handler in case port 0x00 had 0x0020 set upon IRQ handler */ 96#define IDX_IO_TIMER_VALUE 0x60 /* found this timer area by pure luck :-) */
97 #define TIMER_VALUE_MASK 0x000fffffUL /* timer countdown value; triggers IRQ when timer is finished */
98 #define TIMER_ENABLE_COUNTDOWN 0x01000000UL /* activate the timer countdown */
99 #define TIMER_ENABLE_IRQ 0x02000000UL /* trigger timer IRQ on zero transition */
100 #define TIMER_ACK_IRQ 0x04000000UL /* being set in IRQ handler in case port 0x00 (hmm, not port 0x64!?!?) had 0x0020 set upon IRQ handler */
95#define IDX_IO_IRQSTATUS 0x64 101#define IDX_IO_IRQSTATUS 0x64
96 #define IRQ_PLAYBACK 0x0001 102 #define IRQ_PLAYBACK 0x0001
97 #define IRQ_RECORDING 0x0002 103 #define IRQ_RECORDING 0x0002
98 #define IRQ_MPU401 0x0010 104 #define IRQ_MPU401 0x0010
99 #define IRQ_SOMEIRQ 0x0020 /* ???? */ 105 #define IRQ_TIMER 0x0020 /* DirectX timer */
100 #define IRQ_WHO_KNOWS_UNUSED 0x00e0 /* probably unused */ 106 #define IRQ_UNKNOWN1 0x0040 /* probably unused */
107 #define IRQ_UNKNOWN2 0x0080 /* probably unused */
101#define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */ 108#define IDX_IO_66H 0x66 /* writing 0xffff returns 0x0000 */
102#define IDX_IO_SOME_VALUE 0x68 /* this is always set to 0x3ff, and writable; maybe some buffer limit, but I couldn't find out more */ 109#define IDX_IO_SOME_VALUE 0x68 /* this is set to e.g. 0x3ff or 0x300, and writable; maybe some buffer limit, but I couldn't find out more, PU:0x00ff */
103#define IDX_IO_6AH 0x6A /* this WORD can be set to have bits 0x0028 activated; actually inhibits PCM playback !!! maybe power management ?? */ 110#define IDX_IO_6AH 0x6A /* this WORD can be set to have bits 0x0028 activated; actually inhibits PCM playback!!! maybe power management?? */
104#define IDX_IO_6CH 0x6C /* this WORD can have all its bits activated ? */ 111#define IDX_IO_6CH 0x6C
105#define IDX_IO_6EH 0x6E /* writing 0xffff returns 0x83fe */ 112#define IDX_IO_6EH 0x6E /* writing 0xffff returns 0x83fe */
106/* further I/O indices not saved/restored, so probably not used */ 113/* further I/O indices not saved/restored, so probably not used */
107 114
115
108/*** I/O 2 area port indices ***/ 116/*** I/O 2 area port indices ***/
109/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */ 117/* (only 0x06 of 0x08 bytes saved/restored by Windows driver) */
110#define IDX_IO2_LEGACY_ADDR 0x04 118#define IDX_IO2_LEGACY_ADDR 0x04
111 #define LEGACY_SOMETHING 0x01 /* OPL3 ?? */ 119 #define LEGACY_SOMETHING 0x01 /* OPL3?? */
112 #define LEGACY_JOY 0x08 120 #define LEGACY_JOY 0x08
113 121
122
114/*** mixer I/O area port indices ***/ 123/*** mixer I/O area port indices ***/
115/* (only 0x22 of 0x40 bytes saved/restored by Windows driver) 124/* (only 0x22 of 0x40 bytes saved/restored by Windows driver)
116 * generally spoken: AC97 register index = AZF3328 mixer reg index + 2 125 * generally spoken: AC97 register index = AZF3328 mixer reg index + 2
@@ -148,18 +157,18 @@
148 /* unlisted bits are unmodifiable */ 157 /* unlisted bits are unmodifiable */
149 #define MIXER_ADVCTL1_3DWIDTH_MASK 0x000e 158 #define MIXER_ADVCTL1_3DWIDTH_MASK 0x000e
150 #define MIXER_ADVCTL1_HIFI3D_MASK 0x0300 159 #define MIXER_ADVCTL1_HIFI3D_MASK 0x0300
151#define IDX_MIXER_ADVCTL2 0x20 /* resembles AC97_GENERAL_PURPOSE reg ! */ 160#define IDX_MIXER_ADVCTL2 0x20 /* resembles AC97_GENERAL_PURPOSE reg! */
152 /* unlisted bits are unmodifiable */ 161 /* unlisted bits are unmodifiable */
153 #define MIXER_ADVCTL2_BIT7 0x0080 /* WaveOut 3D Bypass ? mutes WaveOut at LineOut */ 162 #define MIXER_ADVCTL2_BIT7 0x0080 /* WaveOut 3D Bypass? mutes WaveOut at LineOut */
154 #define MIXER_ADVCTL2_BIT8 0x0100 /* is this Modem Out Select ? */ 163 #define MIXER_ADVCTL2_BIT8 0x0100 /* is this Modem Out Select? */
155 #define MIXER_ADVCTL2_BIT9 0x0200 /* Mono Select Source ? */ 164 #define MIXER_ADVCTL2_BIT9 0x0200 /* Mono Select Source? */
156 #define MIXER_ADVCTL2_BIT13 0x2000 /* 3D enable ? */ 165 #define MIXER_ADVCTL2_BIT13 0x2000 /* 3D enable? */
157 #define MIXER_ADVCTL2_BIT15 0x8000 /* unknown */ 166 #define MIXER_ADVCTL2_BIT15 0x8000 /* unknown */
158 167
159#define IDX_MIXER_SOMETHING30H 0x30 /* used, but unknown ??? */ 168#define IDX_MIXER_SOMETHING30H 0x30 /* used, but unknown??? */
160 169
161/* driver internal flags */ 170/* driver internal flags */
162#define SET_CHAN_LEFT 1 171#define SET_CHAN_LEFT 1
163#define SET_CHAN_RIGHT 2 172#define SET_CHAN_RIGHT 2
164 173
165#endif /* __SOUND_AZF3328_H */ 174#endif /* __SOUND_AZT3328_H */
diff --git a/sound/pci/ca0106/Makefile b/sound/pci/ca0106/Makefile
index 89c6ceee21f3..dcbae7b31546 100644
--- a/sound/pci/ca0106/Makefile
+++ b/sound/pci/ca0106/Makefile
@@ -1,3 +1,3 @@
1snd-ca0106-objs := ca0106_main.o ca0106_proc.o ca0106_mixer.o 1snd-ca0106-objs := ca0106_main.o ca0106_proc.o ca0106_mixer.o ca_midi.o
2 2
3obj-$(CONFIG_SND_CA0106) += snd-ca0106.o 3obj-$(CONFIG_SND_CA0106) += snd-ca0106.o
diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h
index da09cab405a9..9a4b6406f7a5 100644
--- a/sound/pci/ca0106/ca0106.h
+++ b/sound/pci/ca0106/ca0106.h
@@ -399,10 +399,24 @@
399#define PLAYBACK_VOLUME2 0x6a /* Playback Analog volume per channel. Does not effect AC3 output */ 399#define PLAYBACK_VOLUME2 0x6a /* Playback Analog volume per channel. Does not effect AC3 output */
400 /* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */ 400 /* Similar to register 0x66, except that the destination is the I2S mixer instead of the SPDIF mixer. I.E. Outputs to the Analog outputs instead of SPDIF. */
401#define UNKNOWN6b 0x6b /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */ 401#define UNKNOWN6b 0x6b /* Unknown. Readonly. Default 00400000 00400000 00400000 00400000 */
402#define UART_A_DATA 0x6c /* Uart, used in setting sample rates, bits per sample etc. */ 402#define MIDI_UART_A_DATA 0x6c /* Midi Uart A Data */
403#define UART_A_CMD 0x6d /* Uart, used in setting sample rates, bits per sample etc. */ 403#define MIDI_UART_A_CMD 0x6d /* Midi Uart A Command/Status */
404#define UART_B_DATA 0x6e /* Uart, Unknown. */ 404#define MIDI_UART_B_DATA 0x6e /* Midi Uart B Data (currently unused) */
405#define UART_B_CMD 0x6f /* Uart, Unknown. */ 405#define MIDI_UART_B_CMD 0x6f /* Midi Uart B Command/Status (currently unused) */
406
407/* unique channel identifier for midi->channel */
408
409#define CA0106_MIDI_CHAN_A 0x1
410#define CA0106_MIDI_CHAN_B 0x2
411
412/* from mpu401 */
413
414#define CA0106_MIDI_INPUT_AVAIL 0x80
415#define CA0106_MIDI_OUTPUT_READY 0x40
416#define CA0106_MPU401_RESET 0xff
417#define CA0106_MPU401_ENTER_UART 0x3f
418#define CA0106_MPU401_ACK 0xfe
419
406#define SAMPLE_RATE_TRACKER_STATUS 0x70 /* Readonly. Default 00108000 00108000 00500000 00500000 */ 420#define SAMPLE_RATE_TRACKER_STATUS 0x70 /* Readonly. Default 00108000 00108000 00500000 00500000 */
407 /* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 = 1.0 421 /* Estimated sample rate [19:0] Relative to 48kHz. 0x8000 = 1.0
408 * Rate Locked [20] 422 * Rate Locked [20]
@@ -538,6 +552,8 @@
538#define CONTROL_CENTER_LFE_CHANNEL 1 552#define CONTROL_CENTER_LFE_CHANNEL 1
539#define CONTROL_UNKNOWN_CHANNEL 2 553#define CONTROL_UNKNOWN_CHANNEL 2
540 554
555#include "ca_midi.h"
556
541typedef struct snd_ca0106_channel ca0106_channel_t; 557typedef struct snd_ca0106_channel ca0106_channel_t;
542typedef struct snd_ca0106 ca0106_t; 558typedef struct snd_ca0106 ca0106_t;
543typedef struct snd_ca0106_pcm ca0106_pcm_t; 559typedef struct snd_ca0106_pcm ca0106_pcm_t;
@@ -592,6 +608,9 @@ struct snd_ca0106 {
592 int capture_mic_line_in; 608 int capture_mic_line_in;
593 609
594 struct snd_dma_buffer buffer; 610 struct snd_dma_buffer buffer;
611
612 ca_midi_t midi;
613 ca_midi_t midi2;
595}; 614};
596 615
597int __devinit snd_ca0106_mixer(ca0106_t *emu); 616int __devinit snd_ca0106_mixer(ca0106_t *emu);
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index ba07960921d8..ee58d16002e5 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -281,7 +281,7 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
281 int retry; 281 int retry;
282 if ((reg > 0x7f) || (value > 0x1ff)) 282 if ((reg > 0x7f) || (value > 0x1ff))
283 { 283 {
284 snd_printk("i2c_write: invalid values.\n"); 284 snd_printk(KERN_ERR "i2c_write: invalid values.\n");
285 return -EINVAL; 285 return -EINVAL;
286 } 286 }
287 287
@@ -319,7 +319,7 @@ int snd_ca0106_i2c_write(ca0106_t *emu,
319 319
320 if(retry==10) 320 if(retry==10)
321 { 321 {
322 snd_printk("Writing to ADC failed!\n"); 322 snd_printk(KERN_ERR "Writing to ADC failed!\n");
323 return -EINVAL; 323 return -EINVAL;
324 } 324 }
325 325
@@ -338,6 +338,18 @@ static void snd_ca0106_intr_enable(ca0106_t *emu, unsigned int intrenb)
338 spin_unlock_irqrestore(&emu->emu_lock, flags); 338 spin_unlock_irqrestore(&emu->emu_lock, flags);
339} 339}
340 340
341static void snd_ca0106_intr_disable(ca0106_t *emu, unsigned int intrenb)
342{
343 unsigned long flags;
344 unsigned int enable;
345
346 spin_lock_irqsave(&emu->emu_lock, flags);
347 enable = inl(emu->port + INTE) & ~intrenb;
348 outl(enable, emu->port + INTE);
349 spin_unlock_irqrestore(&emu->emu_lock, flags);
350}
351
352
341static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime) 353static void snd_ca0106_pcm_free_substream(snd_pcm_runtime_t *runtime)
342{ 354{
343 kfree(runtime->private_data); 355 kfree(runtime->private_data);
@@ -421,7 +433,7 @@ static int snd_ca0106_pcm_open_capture_channel(snd_pcm_substream_t *substream, i
421 433
422 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 434 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
423 if (epcm == NULL) { 435 if (epcm == NULL) {
424 snd_printk("open_capture_channel: failed epcm alloc\n"); 436 snd_printk(KERN_ERR "open_capture_channel: failed epcm alloc\n");
425 return -ENOMEM; 437 return -ENOMEM;
426 } 438 }
427 epcm->emu = chip; 439 epcm->emu = chip;
@@ -969,10 +981,8 @@ static int snd_ca0106_free(ca0106_t *chip)
969#endif 981#endif
970 982
971 // release the i/o port 983 // release the i/o port
972 if (chip->res_port) { 984 release_and_free_resource(chip->res_port);
973 release_resource(chip->res_port); 985
974 kfree_nocheck(chip->res_port);
975 }
976 // release the irq 986 // release the irq
977 if (chip->irq >= 0) 987 if (chip->irq >= 0)
978 free_irq(chip->irq, (void *)chip); 988 free_irq(chip->irq, (void *)chip);
@@ -1042,6 +1052,15 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id,
1042 1052
1043 snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76); 1053 snd_ca0106_ptr_write(chip, EXTENDED_INT, 0, stat76);
1044 spin_lock(&chip->emu_lock); 1054 spin_lock(&chip->emu_lock);
1055
1056 if (chip->midi.dev_id &&
1057 (status & (chip->midi.ipr_tx|chip->midi.ipr_rx))) {
1058 if (chip->midi.interrupt)
1059 chip->midi.interrupt(&chip->midi, status);
1060 else
1061 chip->midi.interrupt_disable(&chip->midi, chip->midi.tx_enable | chip->midi.rx_enable);
1062 }
1063
1045 // acknowledge the interrupt if necessary 1064 // acknowledge the interrupt if necessary
1046 outl(status, chip->port+IPR); 1065 outl(status, chip->port+IPR);
1047 1066
@@ -1311,6 +1330,88 @@ static int __devinit snd_ca0106_create(snd_card_t *card,
1311 return 0; 1330 return 0;
1312} 1331}
1313 1332
1333
1334static void ca0106_midi_interrupt_enable(ca_midi_t *midi, int intr)
1335{
1336 snd_ca0106_intr_enable((ca0106_t *)(midi->dev_id), intr);
1337}
1338
1339static void ca0106_midi_interrupt_disable(ca_midi_t *midi, int intr)
1340{
1341 snd_ca0106_intr_disable((ca0106_t *)(midi->dev_id), intr);
1342}
1343
1344static unsigned char ca0106_midi_read(ca_midi_t *midi, int idx)
1345{
1346 return (unsigned char)snd_ca0106_ptr_read((ca0106_t *)(midi->dev_id), midi->port + idx, 0);
1347}
1348
1349static void ca0106_midi_write(ca_midi_t *midi, int data, int idx)
1350{
1351 snd_ca0106_ptr_write((ca0106_t *)(midi->dev_id), midi->port + idx, 0, data);
1352}
1353
1354static snd_card_t *ca0106_dev_id_card(void *dev_id)
1355{
1356 return ((ca0106_t *)dev_id)->card;
1357}
1358
1359static int ca0106_dev_id_port(void *dev_id)
1360{
1361 return ((ca0106_t *)dev_id)->port;
1362}
1363
1364static int __devinit snd_ca0106_midi(ca0106_t *chip, unsigned int channel)
1365{
1366 ca_midi_t *midi;
1367 char *name;
1368 int err;
1369
1370 if(channel==CA0106_MIDI_CHAN_B) {
1371 name = "CA0106 MPU-401 (UART) B";
1372 midi = &chip->midi2;
1373 midi->tx_enable = INTE_MIDI_TX_B;
1374 midi->rx_enable = INTE_MIDI_RX_B;
1375 midi->ipr_tx = IPR_MIDI_TX_B;
1376 midi->ipr_rx = IPR_MIDI_RX_B;
1377 midi->port = MIDI_UART_B_DATA;
1378 } else {
1379 name = "CA0106 MPU-401 (UART)";
1380 midi = &chip->midi;
1381 midi->tx_enable = INTE_MIDI_TX_A;
1382 midi->rx_enable = INTE_MIDI_TX_B;
1383 midi->ipr_tx = IPR_MIDI_TX_A;
1384 midi->ipr_rx = IPR_MIDI_RX_A;
1385 midi->port = MIDI_UART_A_DATA;
1386 }
1387
1388 midi->reset = CA0106_MPU401_RESET;
1389 midi->enter_uart = CA0106_MPU401_ENTER_UART;
1390 midi->ack = CA0106_MPU401_ACK;
1391
1392 midi->input_avail = CA0106_MIDI_INPUT_AVAIL;
1393 midi->output_ready = CA0106_MIDI_OUTPUT_READY;
1394
1395 midi->channel = channel;
1396
1397 midi->interrupt_enable = ca0106_midi_interrupt_enable;
1398 midi->interrupt_disable = ca0106_midi_interrupt_disable;
1399
1400 midi->read = ca0106_midi_read;
1401 midi->write = ca0106_midi_write;
1402
1403 midi->get_dev_id_card = ca0106_dev_id_card;
1404 midi->get_dev_id_port = ca0106_dev_id_port;
1405
1406 midi->dev_id = chip;
1407
1408 if ((err = ca_midi_init(chip, midi, 0, name)) < 0)
1409 return err;
1410
1411 return 0;
1412}
1413
1414
1314static int __devinit snd_ca0106_probe(struct pci_dev *pci, 1415static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1315 const struct pci_device_id *pci_id) 1416 const struct pci_device_id *pci_id)
1316{ 1417{
@@ -1362,6 +1463,14 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1362 return err; 1463 return err;
1363 } 1464 }
1364 1465
1466 snd_printdd("ca0106: probe for MIDI channel A ...");
1467 if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) {
1468 snd_card_free(card);
1469 snd_printdd(" failed, err=0x%x\n",err);
1470 return err;
1471 }
1472 snd_printdd(" done.\n");
1473
1365 snd_ca0106_proc_init(chip); 1474 snd_ca0106_proc_init(chip);
1366 1475
1367 if ((err = snd_card_register(card)) < 0) { 1476 if ((err = snd_card_register(card)) < 0) {
diff --git a/sound/pci/ca0106/ca_midi.c b/sound/pci/ca0106/ca_midi.c
new file mode 100644
index 000000000000..2e08b27b8349
--- /dev/null
+++ b/sound/pci/ca0106/ca_midi.c
@@ -0,0 +1,306 @@
1/*
2 * Copyright 10/16/2005 Tilman Kranz <tilde@tk-sls.de>
3 * Creative Audio MIDI, for the CA0106 Driver
4 * Version: 0.0.1
5 *
6 * Changelog:
7 * Implementation is based on mpu401 and emu10k1x and
8 * tested with ca0106.
9 * mpu401: Copyright (c) by Jaroslav Kysela <perex@suse.cz>
10 * emu10k1x: Copyright (c) by Francisco Moraes <fmoraes@nc.rr.com>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 *
27 */
28
29#include <linux/spinlock.h>
30#include <sound/driver.h>
31#include <sound/core.h>
32#include <sound/rawmidi.h>
33
34#include "ca_midi.h"
35
36#define ca_midi_write_data(midi, data) midi->write(midi, data, 0)
37#define ca_midi_write_cmd(midi, data) midi->write(midi, data, 1)
38#define ca_midi_read_data(midi) midi->read(midi, 0)
39#define ca_midi_read_stat(midi) midi->read(midi, 1)
40#define ca_midi_input_avail(midi) (!(ca_midi_read_stat(midi) & midi->input_avail))
41#define ca_midi_output_ready(midi) (!(ca_midi_read_stat(midi) & midi->output_ready))
42
43static void ca_midi_clear_rx(ca_midi_t *midi)
44{
45 int timeout = 100000;
46 for (; timeout > 0 && ca_midi_input_avail(midi); timeout--)
47 ca_midi_read_data(midi);
48#ifdef CONFIG_SND_DEBUG
49 if (timeout <= 0)
50 snd_printk(KERN_ERR "ca_midi_clear_rx: timeout (status = 0x%x)\n", ca_midi_read_stat(midi));
51#endif
52}
53
54static void ca_midi_interrupt(ca_midi_t *midi, unsigned int status) {
55 unsigned char byte;
56
57 if (midi->rmidi == NULL) {
58 midi->interrupt_disable(midi,midi->tx_enable | midi->rx_enable);
59 return;
60 }
61
62 spin_lock(&midi->input_lock);
63 if ((status & midi->ipr_rx) && ca_midi_input_avail(midi)) {
64 if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
65 ca_midi_clear_rx(midi);
66 } else {
67 byte = ca_midi_read_data(midi);
68 if(midi->substream_input)
69 snd_rawmidi_receive(midi->substream_input, &byte, 1);
70
71
72 }
73 }
74 spin_unlock(&midi->input_lock);
75
76 spin_lock(&midi->output_lock);
77 if ((status & midi->ipr_tx) && ca_midi_output_ready(midi)) {
78 if (midi->substream_output &&
79 snd_rawmidi_transmit(midi->substream_output, &byte, 1) == 1) {
80 ca_midi_write_data(midi, byte);
81 } else {
82 midi->interrupt_disable(midi,midi->tx_enable);
83 }
84 }
85 spin_unlock(&midi->output_lock);
86
87}
88
89static void ca_midi_cmd(ca_midi_t *midi, unsigned char cmd, int ack)
90{
91 unsigned long flags;
92 int timeout, ok;
93
94 spin_lock_irqsave(&midi->input_lock, flags);
95 ca_midi_write_data(midi, 0x00);
96 /* ca_midi_clear_rx(midi); */
97
98 ca_midi_write_cmd(midi, cmd);
99 if (ack) {
100 ok = 0;
101 timeout = 10000;
102 while (!ok && timeout-- > 0) {
103 if (ca_midi_input_avail(midi)) {
104 if (ca_midi_read_data(midi) == midi->ack)
105 ok = 1;
106 }
107 }
108 if (!ok && ca_midi_read_data(midi) == midi->ack)
109 ok = 1;
110 } else {
111 ok = 1;
112 }
113 spin_unlock_irqrestore(&midi->input_lock, flags);
114 if (!ok)
115 snd_printk(KERN_ERR "ca_midi_cmd: 0x%x failed at 0x%x (status = 0x%x, data = 0x%x)!!!\n",
116 cmd,
117 midi->get_dev_id_port(midi->dev_id),
118 ca_midi_read_stat(midi),
119 ca_midi_read_data(midi));
120}
121
122static int ca_midi_input_open(snd_rawmidi_substream_t * substream)
123{
124 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
125 unsigned long flags;
126
127 snd_assert(midi->dev_id, return -ENXIO);
128 spin_lock_irqsave(&midi->open_lock, flags);
129 midi->midi_mode |= CA_MIDI_MODE_INPUT;
130 midi->substream_input = substream;
131 if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) {
132 spin_unlock_irqrestore(&midi->open_lock, flags);
133 ca_midi_cmd(midi, midi->reset, 1);
134 ca_midi_cmd(midi, midi->enter_uart, 1);
135 } else {
136 spin_unlock_irqrestore(&midi->open_lock, flags);
137 }
138 return 0;
139}
140
141static int ca_midi_output_open(snd_rawmidi_substream_t * substream)
142{
143 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
144 unsigned long flags;
145
146 snd_assert(midi->dev_id, return -ENXIO);
147 spin_lock_irqsave(&midi->open_lock, flags);
148 midi->midi_mode |= CA_MIDI_MODE_OUTPUT;
149 midi->substream_output = substream;
150 if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
151 spin_unlock_irqrestore(&midi->open_lock, flags);
152 ca_midi_cmd(midi, midi->reset, 1);
153 ca_midi_cmd(midi, midi->enter_uart, 1);
154 } else {
155 spin_unlock_irqrestore(&midi->open_lock, flags);
156 }
157 return 0;
158}
159
160static int ca_midi_input_close(snd_rawmidi_substream_t * substream)
161{
162 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
163 unsigned long flags;
164
165 snd_assert(midi->dev_id, return -ENXIO);
166 spin_lock_irqsave(&midi->open_lock, flags);
167 midi->interrupt_disable(midi,midi->rx_enable);
168 midi->midi_mode &= ~CA_MIDI_MODE_INPUT;
169 midi->substream_input = NULL;
170 if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT)) {
171 spin_unlock_irqrestore(&midi->open_lock, flags);
172 ca_midi_cmd(midi, midi->reset, 0);
173 } else {
174 spin_unlock_irqrestore(&midi->open_lock, flags);
175 }
176 return 0;
177}
178
179static int ca_midi_output_close(snd_rawmidi_substream_t * substream)
180{
181 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
182 unsigned long flags;
183 snd_assert(midi->dev_id, return -ENXIO);
184
185 spin_lock_irqsave(&midi->open_lock, flags);
186
187 midi->interrupt_disable(midi,midi->tx_enable);
188 midi->midi_mode &= ~CA_MIDI_MODE_OUTPUT;
189 midi->substream_output = NULL;
190
191 if (!(midi->midi_mode & CA_MIDI_MODE_INPUT)) {
192 spin_unlock_irqrestore(&midi->open_lock, flags);
193 ca_midi_cmd(midi, midi->reset, 0);
194 } else {
195 spin_unlock_irqrestore(&midi->open_lock, flags);
196 }
197 return 0;
198}
199
200static void ca_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
201{
202 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
203 snd_assert(midi->dev_id, return);
204
205 if (up) {
206 midi->interrupt_enable(midi,midi->rx_enable);
207 } else {
208 midi->interrupt_disable(midi, midi->rx_enable);
209 }
210}
211
212static void ca_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
213{
214 ca_midi_t *midi = (ca_midi_t *)substream->rmidi->private_data;
215 unsigned long flags;
216
217 snd_assert(midi->dev_id, return);
218
219 if (up) {
220 int max = 4;
221 unsigned char byte;
222
223 spin_lock_irqsave(&midi->output_lock, flags);
224
225 /* try to send some amount of bytes here before interrupts */
226 while (max > 0) {
227 if (ca_midi_output_ready(midi)) {
228 if (!(midi->midi_mode & CA_MIDI_MODE_OUTPUT) ||
229 snd_rawmidi_transmit(substream, &byte, 1) != 1) {
230 /* no more data */
231 spin_unlock_irqrestore(&midi->output_lock, flags);
232 return;
233 }
234 ca_midi_write_data(midi, byte);
235 max--;
236 } else {
237 break;
238 }
239 }
240
241 spin_unlock_irqrestore(&midi->output_lock, flags);
242 midi->interrupt_enable(midi,midi->tx_enable);
243
244 } else {
245 midi->interrupt_disable(midi,midi->tx_enable);
246 }
247}
248
249static snd_rawmidi_ops_t ca_midi_output =
250{
251 .open = ca_midi_output_open,
252 .close = ca_midi_output_close,
253 .trigger = ca_midi_output_trigger,
254};
255
256static snd_rawmidi_ops_t ca_midi_input =
257{
258 .open = ca_midi_input_open,
259 .close = ca_midi_input_close,
260 .trigger = ca_midi_input_trigger,
261};
262
263static void ca_midi_free(ca_midi_t *midi) {
264 midi->interrupt = NULL;
265 midi->interrupt_enable = NULL;
266 midi->interrupt_disable = NULL;
267 midi->read = NULL;
268 midi->write = NULL;
269 midi->get_dev_id_card = NULL;
270 midi->get_dev_id_port = NULL;
271 midi->rmidi = NULL;
272}
273
274static void ca_rmidi_free(snd_rawmidi_t *rmidi)
275{
276 ca_midi_free((ca_midi_t *)rmidi->private_data);
277}
278
279int __devinit ca_midi_init(void *dev_id, ca_midi_t *midi, int device, char *name)
280{
281 snd_rawmidi_t *rmidi;
282 int err;
283
284 if ((err = snd_rawmidi_new(midi->get_dev_id_card(midi->dev_id), name, device, 1, 1, &rmidi)) < 0)
285 return err;
286
287 midi->dev_id = dev_id;
288 midi->interrupt = ca_midi_interrupt;
289
290 spin_lock_init(&midi->open_lock);
291 spin_lock_init(&midi->input_lock);
292 spin_lock_init(&midi->output_lock);
293
294 strcpy(rmidi->name, name);
295 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &ca_midi_output);
296 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &ca_midi_input);
297 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
298 SNDRV_RAWMIDI_INFO_INPUT |
299 SNDRV_RAWMIDI_INFO_DUPLEX;
300 rmidi->private_data = midi;
301 rmidi->private_free = ca_rmidi_free;
302
303 midi->rmidi = rmidi;
304 return 0;
305}
306
diff --git a/sound/pci/ca0106/ca_midi.h b/sound/pci/ca0106/ca_midi.h
new file mode 100644
index 000000000000..b452cec2bf57
--- /dev/null
+++ b/sound/pci/ca0106/ca_midi.h
@@ -0,0 +1,69 @@
1/*
2 * Copyright 10/16/2005 Tilman Kranz <tilde@tk-sls.de>
3 * Creative Audio MIDI, for the CA0106 Driver
4 * Version: 0.0.1
5 *
6 * Changelog:
7 * See ca_midi.c
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/spinlock.h>
26#include<sound/rawmidi.h>
27#include<sound/mpu401.h>
28
29#define CA_MIDI_MODE_INPUT MPU401_MODE_INPUT
30#define CA_MIDI_MODE_OUTPUT MPU401_MODE_OUTPUT
31
32typedef struct ca_midi ca_midi_t;
33struct ca_midi {
34
35 snd_rawmidi_t *rmidi;
36 snd_rawmidi_substream_t *substream_input;
37 snd_rawmidi_substream_t *substream_output;
38
39 void *dev_id;
40
41 spinlock_t input_lock;
42 spinlock_t output_lock;
43 spinlock_t open_lock;
44
45 unsigned int channel;
46
47 unsigned int midi_mode;
48 int port;
49 int tx_enable, rx_enable;
50 int ipr_tx, ipr_rx;
51
52 int input_avail, output_ready;
53 int ack, reset, enter_uart;
54
55 void (*interrupt)(ca_midi_t *midi, unsigned int status);
56 void (*interrupt_enable)(ca_midi_t *midi, int intr);
57 void (*interrupt_disable)(ca_midi_t *midi, int intr);
58
59 unsigned char (*read)(ca_midi_t *midi, int idx);
60 void (*write)(ca_midi_t *midi, int data, int idx);
61
62 /* get info from dev_id */
63 snd_card_t *(*get_dev_id_card)(void *dev_id);
64 int (*get_dev_id_port)(void *dev_id);
65};
66
67int __devinit ca_midi_init(void *card, ca_midi_t *midi, int device, char *name);
68
69
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1eb3315d136d..57e8e433d56f 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -446,9 +446,6 @@ struct snd_stru_cmipci {
446 snd_kcontrol_t *mixer_res_ctl[CM_SAVED_MIXERS]; 446 snd_kcontrol_t *mixer_res_ctl[CM_SAVED_MIXERS];
447 int mixer_res_status[CM_SAVED_MIXERS]; 447 int mixer_res_status[CM_SAVED_MIXERS];
448 448
449 opl3_t *opl3;
450 snd_hwdep_t *opl3hwdep;
451
452 cmipci_pcm_t channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */ 449 cmipci_pcm_t channel[2]; /* ch0 - DAC, ch1 - ADC or 2nd DAC */
453 450
454 /* external MIDI */ 451 /* external MIDI */
@@ -2686,8 +2683,7 @@ static int __devinit snd_cmipci_create_gameport(cmipci_t *cm, int dev)
2686 cm->gameport = gp = gameport_allocate_port(); 2683 cm->gameport = gp = gameport_allocate_port();
2687 if (!gp) { 2684 if (!gp) {
2688 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n"); 2685 printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n");
2689 release_resource(r); 2686 release_and_free_resource(r);
2690 kfree_nocheck(r);
2691 return -ENOMEM; 2687 return -ENOMEM;
2692 } 2688 }
2693 gameport_set_name(gp, "C-Media Gameport"); 2689 gameport_set_name(gp, "C-Media Gameport");
@@ -2712,8 +2708,7 @@ static void snd_cmipci_free_gameport(cmipci_t *cm)
2712 cm->gameport = NULL; 2708 cm->gameport = NULL;
2713 2709
2714 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN); 2710 snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
2715 release_resource(r); 2711 release_and_free_resource(r);
2716 kfree_nocheck(r);
2717 } 2712 }
2718} 2713}
2719#else 2714#else
@@ -2753,6 +2748,51 @@ static int snd_cmipci_dev_free(snd_device_t *device)
2753 return snd_cmipci_free(cm); 2748 return snd_cmipci_free(cm);
2754} 2749}
2755 2750
2751static int __devinit snd_cmipci_create_fm(cmipci_t *cm, long fm_port)
2752{
2753 long iosynth;
2754 unsigned int val;
2755 opl3_t *opl3;
2756 int err;
2757
2758 /* first try FM regs in PCI port range */
2759 iosynth = cm->iobase + CM_REG_FM_PCI;
2760 err = snd_opl3_create(cm->card, iosynth, iosynth + 2,
2761 OPL3_HW_OPL3, 1, &opl3);
2762 if (err < 0) {
2763 /* then try legacy ports */
2764 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK;
2765 iosynth = fm_port;
2766 switch (iosynth) {
2767 case 0x3E8: val |= CM_FMSEL_3E8; break;
2768 case 0x3E0: val |= CM_FMSEL_3E0; break;
2769 case 0x3C8: val |= CM_FMSEL_3C8; break;
2770 case 0x388: val |= CM_FMSEL_388; break;
2771 default:
2772 return 0;
2773 }
2774 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2775 /* enable FM */
2776 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2777
2778 if (snd_opl3_create(cm->card, iosynth, iosynth + 2,
2779 OPL3_HW_OPL3, 0, &opl3) < 0) {
2780 printk(KERN_ERR "cmipci: no OPL device at %#lx, "
2781 "skipping...\n", iosynth);
2782 /* disable FM */
2783 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL,
2784 val & ~CM_FMSEL_MASK);
2785 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2786 return 0;
2787 }
2788 }
2789 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
2790 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
2791 return err;
2792 }
2793 return 0;
2794}
2795
2756static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci, 2796static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2757 int dev, cmipci_t **rcmipci) 2797 int dev, cmipci_t **rcmipci)
2758{ 2798{
@@ -2762,8 +2802,8 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2762 .dev_free = snd_cmipci_dev_free, 2802 .dev_free = snd_cmipci_dev_free,
2763 }; 2803 };
2764 unsigned int val = 0; 2804 unsigned int val = 0;
2765 long iomidi = mpu_port[dev]; 2805 long iomidi;
2766 long iosynth = fm_port[dev]; 2806 int integrated_midi;
2767 int pcm_index, pcm_spdif_index; 2807 int pcm_index, pcm_spdif_index;
2768 static struct pci_device_id intel_82437vx[] = { 2808 static struct pci_device_id intel_82437vx[] = {
2769 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) }, 2809 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
@@ -2799,7 +2839,7 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2799 cm->iobase = pci_resource_start(pci, 0); 2839 cm->iobase = pci_resource_start(pci, 0);
2800 2840
2801 if (request_irq(pci->irq, snd_cmipci_interrupt, SA_INTERRUPT|SA_SHIRQ, card->driver, (void *)cm)) { 2841 if (request_irq(pci->irq, snd_cmipci_interrupt, SA_INTERRUPT|SA_SHIRQ, card->driver, (void *)cm)) {
2802 snd_printk("unable to grab IRQ %d\n", pci->irq); 2842 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2803 snd_cmipci_free(cm); 2843 snd_cmipci_free(cm);
2804 return -EBUSY; 2844 return -EBUSY;
2805 } 2845 }
@@ -2867,52 +2907,28 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2867 return err; 2907 return err;
2868 } 2908 }
2869 2909
2870 /* set MPU address */ 2910 integrated_midi = snd_cmipci_read_b(cm, CM_REG_MPU_PCI) != 0xff;
2871 switch (iomidi) { 2911 if (integrated_midi)
2872 case 0x320: val = CM_VMPU_320; break; 2912 iomidi = cm->iobase + CM_REG_MPU_PCI;
2873 case 0x310: val = CM_VMPU_310; break; 2913 else {
2874 case 0x300: val = CM_VMPU_300; break; 2914 iomidi = mpu_port[dev];
2875 case 0x330: val = CM_VMPU_330; break; 2915 switch (iomidi) {
2876 default: 2916 case 0x320: val = CM_VMPU_320; break;
2877 iomidi = 0; break; 2917 case 0x310: val = CM_VMPU_310; break;
2878 } 2918 case 0x300: val = CM_VMPU_300; break;
2879 if (iomidi > 0) { 2919 case 0x330: val = CM_VMPU_330; break;
2880 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val); 2920 default:
2881 /* enable UART */ 2921 iomidi = 0; break;
2882 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN); 2922 }
2883 } 2923 if (iomidi > 0) {
2884 2924 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2885 /* set FM address */ 2925 /* enable UART */
2886 val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK; 2926 snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
2887 switch (iosynth) {
2888 case 0x3E8: val |= CM_FMSEL_3E8; break;
2889 case 0x3E0: val |= CM_FMSEL_3E0; break;
2890 case 0x3C8: val |= CM_FMSEL_3C8; break;
2891 case 0x388: val |= CM_FMSEL_388; break;
2892 default:
2893 iosynth = 0; break;
2894 }
2895 if (iosynth > 0) {
2896 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
2897 /* enable FM */
2898 snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2899
2900 if (snd_opl3_create(card, iosynth, iosynth + 2,
2901 OPL3_HW_OPL3, 0, &cm->opl3) < 0) {
2902 printk(KERN_ERR "cmipci: no OPL device at 0x%lx, skipping...\n", iosynth);
2903 iosynth = 0;
2904 } else {
2905 if ((err = snd_opl3_hwdep_new(cm->opl3, 0, 1, &cm->opl3hwdep)) < 0) {
2906 printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
2907 return err;
2908 }
2909 } 2927 }
2910 } 2928 }
2911 if (! iosynth) { 2929
2912 /* disable FM */ 2930 if ((err = snd_cmipci_create_fm(cm, fm_port[dev])) < 0)
2913 snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val & ~CM_FMSEL_MASK); 2931 return err;
2914 snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
2915 }
2916 2932
2917 /* reset mixer */ 2933 /* reset mixer */
2918 snd_cmipci_mixer_write(cm, 0, 0); 2934 snd_cmipci_mixer_write(cm, 0, 0);
@@ -2941,7 +2957,7 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
2941 2957
2942 if (iomidi > 0) { 2958 if (iomidi > 0) {
2943 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 2959 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
2944 iomidi, 0, 2960 iomidi, integrated_midi,
2945 cm->irq, 0, &cm->rmidi)) < 0) { 2961 cm->irq, 0, &cm->rmidi)) < 0) {
2946 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); 2962 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi);
2947 } 2963 }
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index dc87e0144b5a..aea2c47712f9 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -523,8 +523,7 @@ static void snd_cs4281_delay(unsigned int delay)
523 delay = 1; 523 delay = 1;
524 end_time = jiffies + delay; 524 end_time = jiffies + delay;
525 do { 525 do {
526 set_current_state(TASK_UNINTERRUPTIBLE); 526 schedule_timeout_uninterruptible(1);
527 schedule_timeout(1);
528 } while (time_after_eq(end_time, jiffies)); 527 } while (time_after_eq(end_time, jiffies));
529 } else { 528 } else {
530 udelay(delay); 529 udelay(delay);
@@ -533,8 +532,7 @@ static void snd_cs4281_delay(unsigned int delay)
533 532
534static inline void snd_cs4281_delay_long(void) 533static inline void snd_cs4281_delay_long(void)
535{ 534{
536 set_current_state(TASK_UNINTERRUPTIBLE); 535 schedule_timeout_uninterruptible(1);
537 schedule_timeout(1);
538} 536}
539 537
540static inline void snd_cs4281_pokeBA0(cs4281_t *chip, unsigned long offset, unsigned int val) 538static inline void snd_cs4281_pokeBA0(cs4281_t *chip, unsigned long offset, unsigned int val)
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 6e3855b8b33d..9b8af5bcbb04 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -163,7 +163,7 @@ static unsigned short snd_cs46xx_codec_read(cs46xx_t *chip,
163 goto ok1; 163 goto ok1;
164 } 164 }
165 165
166 snd_printk("AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg); 166 snd_printk(KERN_ERR "AC'97 read problem (ACCTL_DCV), reg = 0x%x\n", reg);
167 result = 0xffff; 167 result = 0xffff;
168 goto end; 168 goto end;
169 169
@@ -182,7 +182,7 @@ static unsigned short snd_cs46xx_codec_read(cs46xx_t *chip,
182 udelay(10); 182 udelay(10);
183 } 183 }
184 184
185 snd_printk("AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", codec_index, reg); 185 snd_printk(KERN_ERR "AC'97 read problem (ACSTS_VSTS), codec_index %d, reg = 0x%x\n", codec_index, reg);
186 result = 0xffff; 186 result = 0xffff;
187 goto end; 187 goto end;
188 188
@@ -281,7 +281,7 @@ static void snd_cs46xx_codec_write(cs46xx_t *chip,
281 goto end; 281 goto end;
282 } 282 }
283 } 283 }
284 snd_printk("AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", codec_index, reg, val); 284 snd_printk(KERN_ERR "AC'97 write problem, codec_index = %d, reg = 0x%x, val = 0x%x\n", codec_index, reg, val);
285 end: 285 end:
286 chip->active_ctrl(chip, -1); 286 chip->active_ctrl(chip, -1);
287} 287}
@@ -510,7 +510,7 @@ static void snd_cs46xx_proc_start(cs46xx_t *chip)
510 } 510 }
511 511
512 if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR) 512 if (snd_cs46xx_peek(chip, BA1_SPCR) & SPCR_RUNFR)
513 snd_printk("SPCR_RUNFR never reset\n"); 513 snd_printk(KERN_ERR "SPCR_RUNFR never reset\n");
514} 514}
515 515
516static void snd_cs46xx_proc_stop(cs46xx_t *chip) 516static void snd_cs46xx_proc_stop(cs46xx_t *chip)
@@ -2403,7 +2403,7 @@ static void snd_cs46xx_codec_reset (ac97_t * ac97)
2403 msleep(10); 2403 msleep(10);
2404 } while (time_after_eq(end_time, jiffies)); 2404 } while (time_after_eq(end_time, jiffies));
2405 2405
2406 snd_printk("CS46xx secondary codec dont respond!\n"); 2406 snd_printk(KERN_ERR "CS46xx secondary codec doesn't respond!\n");
2407} 2407}
2408#endif 2408#endif
2409 2409
@@ -2906,10 +2906,7 @@ static int snd_cs46xx_free(cs46xx_t *chip)
2906 snd_cs46xx_region_t *region = &chip->region.idx[idx]; 2906 snd_cs46xx_region_t *region = &chip->region.idx[idx];
2907 if (region->remap_addr) 2907 if (region->remap_addr)
2908 iounmap(region->remap_addr); 2908 iounmap(region->remap_addr);
2909 if (region->resource) { 2909 release_and_free_resource(region->resource);
2910 release_resource(region->resource);
2911 kfree_nocheck(region->resource);
2912 }
2913 } 2910 }
2914 if (chip->irq >= 0) 2911 if (chip->irq >= 0)
2915 free_irq(chip->irq, (void *)chip); 2912 free_irq(chip->irq, (void *)chip);
@@ -3075,8 +3072,8 @@ static int snd_cs46xx_chip_init(cs46xx_t *chip)
3075 } 3072 }
3076 3073
3077 3074
3078 snd_printk("create - never read codec ready from AC'97\n"); 3075 snd_printk(KERN_ERR "create - never read codec ready from AC'97\n");
3079 snd_printk("it is not probably bug, try to use CS4236 driver\n"); 3076 snd_printk(KERN_ERR "it is not probably bug, try to use CS4236 driver\n");
3080 return -EIO; 3077 return -EIO;
3081 ok1: 3078 ok1:
3082#ifdef CONFIG_SND_CS46XX_NEW_DSP 3079#ifdef CONFIG_SND_CS46XX_NEW_DSP
@@ -3124,17 +3121,17 @@ static int snd_cs46xx_chip_init(cs46xx_t *chip)
3124 } 3121 }
3125 3122
3126#ifndef CONFIG_SND_CS46XX_NEW_DSP 3123#ifndef CONFIG_SND_CS46XX_NEW_DSP
3127 snd_printk("create - never read ISV3 & ISV4 from AC'97\n"); 3124 snd_printk(KERN_ERR "create - never read ISV3 & ISV4 from AC'97\n");
3128 return -EIO; 3125 return -EIO;
3129#else 3126#else
3130 /* This may happen on a cold boot with a Terratec SiXPack 5.1. 3127 /* This may happen on a cold boot with a Terratec SiXPack 5.1.
3131 Reloading the driver may help, if there's other soundcards 3128 Reloading the driver may help, if there's other soundcards
3132 with the same problem I would like to know. (Benny) */ 3129 with the same problem I would like to know. (Benny) */
3133 3130
3134 snd_printk("ERROR: snd-cs46xx: never read ISV3 & ISV4 from AC'97\n"); 3131 snd_printk(KERN_ERR "ERROR: snd-cs46xx: never read ISV3 & ISV4 from AC'97\n");
3135 snd_printk(" Try reloading the ALSA driver, if you find something\n"); 3132 snd_printk(KERN_ERR " Try reloading the ALSA driver, if you find something\n");
3136 snd_printk(" broken or not working on your soundcard upon\n"); 3133 snd_printk(KERN_ERR " broken or not working on your soundcard upon\n");
3137 snd_printk(" this message please report to alsa-devel@lists.sourceforge.net\n"); 3134 snd_printk(KERN_ERR " this message please report to alsa-devel@lists.sourceforge.net\n");
3138 3135
3139 return -EIO; 3136 return -EIO;
3140#endif 3137#endif
@@ -3215,7 +3212,7 @@ int __devinit snd_cs46xx_start_dsp(cs46xx_t *chip)
3215#else 3212#else
3216 /* old image */ 3213 /* old image */
3217 if (snd_cs46xx_download_image(chip) < 0) { 3214 if (snd_cs46xx_download_image(chip) < 0) {
3218 snd_printk("image download error\n"); 3215 snd_printk(KERN_ERR "image download error\n");
3219 return -EIO; 3216 return -EIO;
3220 } 3217 }
3221 3218
@@ -3790,7 +3787,7 @@ int __devinit snd_cs46xx_create(snd_card_t * card,
3790 chip->ba1_addr = pci_resource_start(pci, 1); 3787 chip->ba1_addr = pci_resource_start(pci, 1);
3791 if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 || 3788 if (chip->ba0_addr == 0 || chip->ba0_addr == (unsigned long)~0 ||
3792 chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) { 3789 chip->ba1_addr == 0 || chip->ba1_addr == (unsigned long)~0) {
3793 snd_printk("wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", chip->ba0_addr, chip->ba1_addr); 3790 snd_printk(KERN_ERR "wrong address(es) - ba0 = 0x%lx, ba1 = 0x%lx\n", chip->ba0_addr, chip->ba1_addr);
3794 snd_cs46xx_free(chip); 3791 snd_cs46xx_free(chip);
3795 return -ENOMEM; 3792 return -ENOMEM;
3796 } 3793 }
@@ -3839,12 +3836,12 @@ int __devinit snd_cs46xx_create(snd_card_t * card,
3839 } 3836 }
3840 3837
3841 if (external_amp) { 3838 if (external_amp) {
3842 snd_printk("Crystal EAPD support forced on.\n"); 3839 snd_printk(KERN_INFO "Crystal EAPD support forced on.\n");
3843 chip->amplifier_ctrl = amp_voyetra; 3840 chip->amplifier_ctrl = amp_voyetra;
3844 } 3841 }
3845 3842
3846 if (thinkpad) { 3843 if (thinkpad) {
3847 snd_printk("Activating CLKRUN hack for Thinkpad.\n"); 3844 snd_printk(KERN_INFO "Activating CLKRUN hack for Thinkpad.\n");
3848 chip->active_ctrl = clkrun_hack; 3845 chip->active_ctrl = clkrun_hack;
3849 clkrun_init(chip); 3846 clkrun_init(chip);
3850 } 3847 }
@@ -3861,20 +3858,20 @@ int __devinit snd_cs46xx_create(snd_card_t * card,
3861 for (idx = 0; idx < 5; idx++) { 3858 for (idx = 0; idx < 5; idx++) {
3862 region = &chip->region.idx[idx]; 3859 region = &chip->region.idx[idx];
3863 if ((region->resource = request_mem_region(region->base, region->size, region->name)) == NULL) { 3860 if ((region->resource = request_mem_region(region->base, region->size, region->name)) == NULL) {
3864 snd_printk("unable to request memory region 0x%lx-0x%lx\n", region->base, region->base + region->size - 1); 3861 snd_printk(KERN_ERR "unable to request memory region 0x%lx-0x%lx\n", region->base, region->base + region->size - 1);
3865 snd_cs46xx_free(chip); 3862 snd_cs46xx_free(chip);
3866 return -EBUSY; 3863 return -EBUSY;
3867 } 3864 }
3868 region->remap_addr = ioremap_nocache(region->base, region->size); 3865 region->remap_addr = ioremap_nocache(region->base, region->size);
3869 if (region->remap_addr == NULL) { 3866 if (region->remap_addr == NULL) {
3870 snd_printk("%s ioremap problem\n", region->name); 3867 snd_printk(KERN_ERR "%s ioremap problem\n", region->name);
3871 snd_cs46xx_free(chip); 3868 snd_cs46xx_free(chip);
3872 return -ENOMEM; 3869 return -ENOMEM;
3873 } 3870 }
3874 } 3871 }
3875 3872
3876 if (request_irq(pci->irq, snd_cs46xx_interrupt, SA_INTERRUPT|SA_SHIRQ, "CS46XX", (void *) chip)) { 3873 if (request_irq(pci->irq, snd_cs46xx_interrupt, SA_INTERRUPT|SA_SHIRQ, "CS46XX", (void *) chip)) {
3877 snd_printk("unable to grab IRQ %d\n", pci->irq); 3874 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
3878 snd_cs46xx_free(chip); 3875 snd_cs46xx_free(chip);
3879 return -EBUSY; 3876 return -EBUSY;
3880 } 3877 }
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index b0e00f0a7c2f..dd1ea9d3b81a 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -188,7 +188,7 @@ static int __devinit snd_card_emu10k1_probe(struct pci_dev *pci,
188 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, 188 if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
189 sizeof(snd_emu10k1_synth_arg_t), &wave) < 0 || 189 sizeof(snd_emu10k1_synth_arg_t), &wave) < 0 ||
190 wave == NULL) { 190 wave == NULL) {
191 snd_printk("can't initialize Emu10k1 wavetable synth\n"); 191 snd_printk(KERN_WARNING "can't initialize Emu10k1 wavetable synth\n");
192 } else { 192 } else {
193 snd_emu10k1_synth_arg_t *arg; 193 snd_emu10k1_synth_arg_t *arg;
194 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave); 194 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c
index 7cf2f908eed9..6589bf24abcd 100644
--- a/sound/pci/emu10k1/emu10k1_callback.c
+++ b/sound/pci/emu10k1/emu10k1_callback.c
@@ -241,7 +241,7 @@ lookup_voices(snd_emux_t *emu, emu10k1_t *hw, best_voice_t *best, int active_onl
241 else if (state == SNDRV_EMUX_ST_RELEASED || 241 else if (state == SNDRV_EMUX_ST_RELEASED ||
242 state == SNDRV_EMUX_ST_PENDING) { 242 state == SNDRV_EMUX_ST_PENDING) {
243 bp = best + V_RELEASED; 243 bp = best + V_RELEASED;
244#if 0 244#if 1
245 val = snd_emu10k1_ptr_read(hw, CVCF_CURRENTVOL, vp->ch); 245 val = snd_emu10k1_ptr_read(hw, CVCF_CURRENTVOL, vp->ch);
246 if (! val) 246 if (! val)
247 bp = best + V_OFF; 247 bp = best + V_OFF;
@@ -349,7 +349,7 @@ start_voice(snd_emux_voice_t *vp)
349 } 349 }
350 350
351 /* channel to be silent and idle */ 351 /* channel to be silent and idle */
352 snd_emu10k1_ptr_write(hw, DCYSUSV, ch, 0x0080); 352 snd_emu10k1_ptr_write(hw, DCYSUSV, ch, 0x0000);
353 snd_emu10k1_ptr_write(hw, VTFT, ch, 0x0000FFFF); 353 snd_emu10k1_ptr_write(hw, VTFT, ch, 0x0000FFFF);
354 snd_emu10k1_ptr_write(hw, CVCF, ch, 0x0000FFFF); 354 snd_emu10k1_ptr_write(hw, CVCF, ch, 0x0000FFFF);
355 snd_emu10k1_ptr_write(hw, PTRX, ch, 0); 355 snd_emu10k1_ptr_write(hw, PTRX, ch, 0);
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index ad15755a63c3..cbb689474e7d 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -759,10 +759,8 @@ static int snd_emu10k1x_free(emu10k1x_t *chip)
759 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); 759 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
760 760
761 // release the i/o port 761 // release the i/o port
762 if (chip->res_port) { 762 release_and_free_resource(chip->res_port);
763 release_resource(chip->res_port); 763
764 kfree_nocheck(chip->res_port);
765 }
766 // release the irq 764 // release the irq
767 if (chip->irq >= 0) 765 if (chip->irq >= 0)
768 free_irq(chip->irq, (void *)chip); 766 free_irq(chip->irq, (void *)chip);
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 646b5d972e6f..03e8c1678952 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -364,12 +364,18 @@ static int snd_emu10k1_gpr_ctl_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
364 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[i], 0, db_table[val]); 364 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[i], 0, db_table[val]);
365 break; 365 break;
366 case EMU10K1_GPR_TRANSLATION_BASS: 366 case EMU10K1_GPR_TRANSLATION_BASS:
367 snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error); 367 if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
368 change = -EIO;
369 goto __error;
370 }
368 for (j = 0; j < 5; j++) 371 for (j = 0; j < 5; j++)
369 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, bass_table[val][j]); 372 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, bass_table[val][j]);
370 break; 373 break;
371 case EMU10K1_GPR_TRANSLATION_TREBLE: 374 case EMU10K1_GPR_TRANSLATION_TREBLE:
372 snd_runtime_check((ctl->count % 5) == 0 && (ctl->count / 5) == ctl->vcount, change = -EIO; goto __error); 375 if ((ctl->count % 5) != 0 || (ctl->count / 5) != ctl->vcount) {
376 change = -EIO;
377 goto __error;
378 }
373 for (j = 0; j < 5; j++) 379 for (j = 0; j < 5; j++)
374 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, treble_table[val][j]); 380 snd_emu10k1_ptr_write(emu, emu->gpr_base + ctl->gpr[j * ctl->vcount + i], 0, treble_table[val][j]);
375 break; 381 break;
@@ -412,8 +418,6 @@ int snd_emu10k1_fx8010_register_irq_handler(emu10k1_t *emu,
412 snd_emu10k1_fx8010_irq_t *irq; 418 snd_emu10k1_fx8010_irq_t *irq;
413 unsigned long flags; 419 unsigned long flags;
414 420
415 snd_runtime_check(emu, return -EINVAL);
416 snd_runtime_check(handler, return -EINVAL);
417 irq = kmalloc(sizeof(*irq), GFP_ATOMIC); 421 irq = kmalloc(sizeof(*irq), GFP_ATOMIC);
418 if (irq == NULL) 422 if (irq == NULL)
419 return -ENOMEM; 423 return -ENOMEM;
@@ -442,7 +446,6 @@ int snd_emu10k1_fx8010_unregister_irq_handler(emu10k1_t *emu,
442 snd_emu10k1_fx8010_irq_t *tmp; 446 snd_emu10k1_fx8010_irq_t *tmp;
443 unsigned long flags; 447 unsigned long flags;
444 448
445 snd_runtime_check(irq, return -EINVAL);
446 spin_lock_irqsave(&emu->fx8010.irq_lock, flags); 449 spin_lock_irqsave(&emu->fx8010.irq_lock, flags);
447 if ((tmp = emu->fx8010.irq_handlers) == irq) { 450 if ((tmp = emu->fx8010.irq_handlers) == irq) {
448 emu->fx8010.irq_handlers = tmp->next; 451 emu->fx8010.irq_handlers = tmp->next;
@@ -717,9 +720,15 @@ static int snd_emu10k1_add_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode
717 err = -EFAULT; 720 err = -EFAULT;
718 goto __error; 721 goto __error;
719 } 722 }
720 snd_runtime_check(gctl->id.iface == SNDRV_CTL_ELEM_IFACE_MIXER || 723 if (gctl->id.iface != SNDRV_CTL_ELEM_IFACE_MIXER &&
721 gctl->id.iface == SNDRV_CTL_ELEM_IFACE_PCM, err = -EINVAL; goto __error); 724 gctl->id.iface != SNDRV_CTL_ELEM_IFACE_PCM) {
722 snd_runtime_check(gctl->id.name[0] != '\0', err = -EINVAL; goto __error); 725 err = -EINVAL;
726 goto __error;
727 }
728 if (! gctl->id.name[0]) {
729 err = -EINVAL;
730 goto __error;
731 }
723 ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id); 732 ctl = snd_emu10k1_look_for_ctl(emu, &gctl->id);
724 memset(&knew, 0, sizeof(knew)); 733 memset(&knew, 0, sizeof(knew));
725 knew.iface = gctl->id.iface; 734 knew.iface = gctl->id.iface;
@@ -783,7 +792,8 @@ static int snd_emu10k1_del_controls(emu10k1_t *emu, emu10k1_fx8010_code_t *icode
783 792
784 for (i = 0, _id = icode->gpr_del_controls; 793 for (i = 0, _id = icode->gpr_del_controls;
785 i < icode->gpr_del_control_count; i++, _id++) { 794 i < icode->gpr_del_control_count; i++, _id++) {
786 snd_runtime_check(copy_from_user(&id, _id, sizeof(id)) == 0, return -EFAULT); 795 if (copy_from_user(&id, _id, sizeof(id)))
796 return -EFAULT;
787 down_write(&card->controls_rwsem); 797 down_write(&card->controls_rwsem);
788 ctl = snd_emu10k1_look_for_ctl(emu, &id); 798 ctl = snd_emu10k1_look_for_ctl(emu, &id);
789 if (ctl) 799 if (ctl)
@@ -964,8 +974,8 @@ static int snd_emu10k1_ipcm_peek(emu10k1_t *emu, emu10k1_fx8010_pcm_t *ipcm)
964 return err; 974 return err;
965} 975}
966 976
967#define SND_EMU10K1_GPR_CONTROLS 41 977#define SND_EMU10K1_GPR_CONTROLS 44
968#define SND_EMU10K1_INPUTS 10 978#define SND_EMU10K1_INPUTS 12
969#define SND_EMU10K1_PLAYBACK_CHANNELS 8 979#define SND_EMU10K1_PLAYBACK_CHANNELS 8
970#define SND_EMU10K1_CAPTURE_CHANNELS 4 980#define SND_EMU10K1_CAPTURE_CHANNELS 4
971 981
@@ -1382,7 +1392,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1382 A_SWITCH(icode, &ptr, tmp + 1, playback + SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp + 1); 1392 A_SWITCH(icode, &ptr, tmp + 1, playback + SND_EMU10K1_PLAYBACK_CHANNELS + z, tmp + 1);
1383 if ((z==1) && (emu->card_capabilities->spdif_bug)) { 1393 if ((z==1) && (emu->card_capabilities->spdif_bug)) {
1384 /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */ 1394 /* Due to a SPDIF output bug on some Audigy cards, this code delays the Right channel by 1 sample */
1385 snd_printk("Installing spdif_bug patch: %s\n", emu->card_capabilities->name); 1395 snd_printk(KERN_INFO "Installing spdif_bug patch: %s\n", emu->card_capabilities->name);
1386 A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000); 1396 A_OP(icode, &ptr, iACC3, A_EXTOUT(A_EXTOUT_FRONT_L + z), A_GPR(gpr - 3), A_C_00000000, A_C_00000000);
1387 A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000); 1397 A_OP(icode, &ptr, iACC3, A_GPR(gpr - 3), A_GPR(tmp + 0), A_GPR(tmp + 1), A_C_00000000);
1388 } else { 1398 } else {
@@ -1527,7 +1537,7 @@ static int __devinit _snd_emu10k1_init_efx(emu10k1_t *emu)
1527 1537
1528 strcpy(icode->name, "SB Live! FX8010 code for ALSA v1.2 by Jaroslav Kysela"); 1538 strcpy(icode->name, "SB Live! FX8010 code for ALSA v1.2 by Jaroslav Kysela");
1529 ptr = 0; i = 0; 1539 ptr = 0; i = 0;
1530 /* we have 10 inputs */ 1540 /* we have 12 inputs */
1531 playback = SND_EMU10K1_INPUTS; 1541 playback = SND_EMU10K1_INPUTS;
1532 /* we have 6 playback channels and tone control doubles */ 1542 /* we have 6 playback channels and tone control doubles */
1533 capture = playback + (SND_EMU10K1_PLAYBACK_CHANNELS * 2); 1543 capture = playback + (SND_EMU10K1_PLAYBACK_CHANNELS * 2);
@@ -1551,6 +1561,8 @@ static int __devinit _snd_emu10k1_init_efx(emu10k1_t *emu)
1551 OP(icode, &ptr, iMACINT0, GPR(7), C_00000000, FXBUS(FXBUS_PCM_LFE), C_00000004); 1561 OP(icode, &ptr, iMACINT0, GPR(7), C_00000000, FXBUS(FXBUS_PCM_LFE), C_00000004);
1552 OP(icode, &ptr, iMACINT0, GPR(8), C_00000000, C_00000000, C_00000000); /* S/PDIF left */ 1562 OP(icode, &ptr, iMACINT0, GPR(8), C_00000000, C_00000000, C_00000000); /* S/PDIF left */
1553 OP(icode, &ptr, iMACINT0, GPR(9), C_00000000, C_00000000, C_00000000); /* S/PDIF right */ 1563 OP(icode, &ptr, iMACINT0, GPR(9), C_00000000, C_00000000, C_00000000); /* S/PDIF right */
1564 OP(icode, &ptr, iMACINT0, GPR(10), C_00000000, FXBUS(FXBUS_PCM_LEFT_FRONT), C_00000004);
1565 OP(icode, &ptr, iMACINT0, GPR(11), C_00000000, FXBUS(FXBUS_PCM_RIGHT_FRONT), C_00000004);
1554 1566
1555 /* Raw S/PDIF PCM */ 1567 /* Raw S/PDIF PCM */
1556 ipcm->substream = 0; 1568 ipcm->substream = 0;
@@ -1697,6 +1709,21 @@ static int __devinit _snd_emu10k1_init_efx(emu10k1_t *emu)
1697 VOLUME_ADD(icode, &ptr, playback + 5, 7, gpr); 1709 VOLUME_ADD(icode, &ptr, playback + 5, 7, gpr);
1698 snd_emu10k1_init_mono_control(controls + i++, "LFE Digital Playback Volume", gpr++, 100); 1710 snd_emu10k1_init_mono_control(controls + i++, "LFE Digital Playback Volume", gpr++, 100);
1699 1711
1712 /* Front Playback Volume */
1713 for (z = 0; z < 2; z++)
1714 VOLUME_ADD(icode, &ptr, playback + z, 10 + z, gpr + z);
1715 snd_emu10k1_init_stereo_control(controls + i++, "Front Playback Volume", gpr, 100);
1716 gpr += 2;
1717
1718 /* Front Capture Volume + Switch */
1719 for (z = 0; z < 2; z++) {
1720 SWITCH(icode, &ptr, tmp + 0, 10 + z, gpr + 2);
1721 VOLUME_ADD(icode, &ptr, capture + z, tmp + 0, gpr + z);
1722 }
1723 snd_emu10k1_init_stereo_control(controls + i++, "Front Capture Volume", gpr, 0);
1724 snd_emu10k1_init_mono_onoff_control(controls + i++, "Front Capture Switch", gpr + 2, 0);
1725 gpr += 3;
1726
1700 /* 1727 /*
1701 * Process inputs 1728 * Process inputs
1702 */ 1729 */
@@ -2058,14 +2085,16 @@ void snd_emu10k1_free_efx(emu10k1_t *emu)
2058#if 0 // FIXME: who use them? 2085#if 0 // FIXME: who use them?
2059int snd_emu10k1_fx8010_tone_control_activate(emu10k1_t *emu, int output) 2086int snd_emu10k1_fx8010_tone_control_activate(emu10k1_t *emu, int output)
2060{ 2087{
2061 snd_runtime_check(output >= 0 && output < 6, return -EINVAL); 2088 if (output < 0 || output >= 6)
2089 return -EINVAL;
2062 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 1); 2090 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 1);
2063 return 0; 2091 return 0;
2064} 2092}
2065 2093
2066int snd_emu10k1_fx8010_tone_control_deactivate(emu10k1_t *emu, int output) 2094int snd_emu10k1_fx8010_tone_control_deactivate(emu10k1_t *emu, int output)
2067{ 2095{
2068 snd_runtime_check(output >= 0 && output < 6, return -EINVAL); 2096 if (output < 0 || output >= 6)
2097 return -EINVAL;
2069 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 0); 2098 snd_emu10k1_ptr_write(emu, emu->gpr_base + 0x94 + output, 0, 0);
2070 return 0; 2099 return 0;
2071} 2100}
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index 66ba27afe962..bf7490dae09b 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -965,7 +965,8 @@ static void snd_emu10k1_pcm_mixer_notify1(emu10k1_t *emu, snd_kcontrol_t *kctl,
965{ 965{
966 snd_ctl_elem_id_t id; 966 snd_ctl_elem_id_t id;
967 967
968 snd_runtime_check(kctl != NULL, return); 968 if (! kctl)
969 return;
969 if (activate) 970 if (activate)
970 kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 971 kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
971 else 972 else
diff --git a/sound/pci/emu10k1/irq.c b/sound/pci/emu10k1/irq.c
index cd8460d56752..594ea063b140 100644
--- a/sound/pci/emu10k1/irq.c
+++ b/sound/pci/emu10k1/irq.c
@@ -41,7 +41,7 @@ irqreturn_t snd_emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
41 orig_status = status; 41 orig_status = status;
42 handled = 1; 42 handled = 1;
43 if (status & IPR_PCIERROR) { 43 if (status & IPR_PCIERROR) {
44 snd_printk("interrupt: PCI error\n"); 44 snd_printk(KERN_ERR "interrupt: PCI error\n");
45 snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE); 45 snd_emu10k1_intr_disable(emu, INTE_PCIERRORENABLE);
46 status &= ~IPR_PCIERROR; 46 status &= ~IPR_PCIERROR;
47 } 47 }
diff --git a/sound/pci/emu10k1/memory.c b/sound/pci/emu10k1/memory.c
index 6afeaeab3e13..d42e4aeaa73a 100644
--- a/sound/pci/emu10k1/memory.c
+++ b/sound/pci/emu10k1/memory.c
@@ -232,11 +232,11 @@ __found_pages:
232static int is_valid_page(emu10k1_t *emu, dma_addr_t addr) 232static int is_valid_page(emu10k1_t *emu, dma_addr_t addr)
233{ 233{
234 if (addr & ~emu->dma_mask) { 234 if (addr & ~emu->dma_mask) {
235 snd_printk("max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr); 235 snd_printk(KERN_ERR "max memory size is 0x%lx (addr = 0x%lx)!!\n", emu->dma_mask, (unsigned long)addr);
236 return 0; 236 return 0;
237 } 237 }
238 if (addr & (EMUPAGESIZE-1)) { 238 if (addr & (EMUPAGESIZE-1)) {
239 snd_printk("page is not aligned\n"); 239 snd_printk(KERN_ERR "page is not aligned\n");
240 return 0; 240 return 0;
241 } 241 }
242 return 1; 242 return 1;
@@ -501,7 +501,7 @@ static inline void *offset_ptr(emu10k1_t *emu, int page, int offset)
501 snd_assert(page >= 0 && page < emu->max_cache_pages, return NULL); 501 snd_assert(page >= 0 && page < emu->max_cache_pages, return NULL);
502 ptr = emu->page_ptr_table[page]; 502 ptr = emu->page_ptr_table[page];
503 if (! ptr) { 503 if (! ptr) {
504 printk("emu10k1: access to NULL ptr: page = %d\n", page); 504 printk(KERN_ERR "emu10k1: access to NULL ptr: page = %d\n", page);
505 return NULL; 505 return NULL;
506 } 506 }
507 ptr += offset & (PAGE_SIZE - 1); 507 ptr += offset & (PAGE_SIZE - 1);
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index d59c7f345ad6..e27ebb9bb74a 100644
--- a/sound/pci/emu10k1/p16v.c
+++ b/sound/pci/emu10k1/p16v.c
@@ -546,7 +546,7 @@ snd_p16v_pcm_pointer_capture(snd_pcm_substream_t *substream)
546 ptr=ptr2; 546 ptr=ptr2;
547 if (ptr >= runtime->buffer_size) { 547 if (ptr >= runtime->buffer_size) {
548 ptr -= runtime->buffer_size; 548 ptr -= runtime->buffer_size;
549 printk("buffer capture limited!\n"); 549 printk(KERN_WARNING "buffer capture limited!\n");
550 } 550 }
551 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); 551 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate);
552 552
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index bef9a59f46d7..92ff7c510f2b 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -508,7 +508,7 @@ static unsigned int snd_es1371_wait_src_ready(ensoniq_t * ensoniq)
508 return r; 508 return r;
509 cond_resched(); 509 cond_resched();
510 } 510 }
511 snd_printk("wait source ready timeout 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_SMPRATE), r); 511 snd_printk(KERN_ERR "wait source ready timeout 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_SMPRATE), r);
512 return 0; 512 return 0;
513} 513}
514 514
@@ -576,10 +576,9 @@ static void snd_es1370_codec_write(ak4531_t *ak4531,
576 outw(ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC)); 576 outw(ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
577 return; 577 return;
578 } 578 }
579 set_current_state(TASK_UNINTERRUPTIBLE); 579 schedule_timeout_uninterruptible(1);
580 schedule_timeout(1);
581 } while (time_after(end_time, jiffies)); 580 } while (time_after(end_time, jiffies));
582 snd_printk("codec write timeout, status = 0x%x\n", inl(ES_REG(ensoniq, STATUS))); 581 snd_printk(KERN_ERR "codec write timeout, status = 0x%x\n", inl(ES_REG(ensoniq, STATUS)));
583} 582}
584 583
585#endif /* CHIP1370 */ 584#endif /* CHIP1370 */
@@ -620,7 +619,7 @@ static void snd_es1371_codec_write(ac97_t *ac97,
620 } 619 }
621 } 620 }
622 up(&ensoniq->src_mutex); 621 up(&ensoniq->src_mutex);
623 snd_printk("codec write timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC))); 622 snd_printk(KERN_ERR "codec write timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
624} 623}
625 624
626static unsigned short snd_es1371_codec_read(ac97_t *ac97, 625static unsigned short snd_es1371_codec_read(ac97_t *ac97,
@@ -667,14 +666,14 @@ static unsigned short snd_es1371_codec_read(ac97_t *ac97,
667 } 666 }
668 up(&ensoniq->src_mutex); 667 up(&ensoniq->src_mutex);
669 if (++fail > 10) { 668 if (++fail > 10) {
670 snd_printk("codec read timeout (final) at 0x%lx, reg = 0x%x [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), reg, inl(ES_REG(ensoniq, 1371_CODEC))); 669 snd_printk(KERN_ERR "codec read timeout (final) at 0x%lx, reg = 0x%x [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), reg, inl(ES_REG(ensoniq, 1371_CODEC)));
671 return 0; 670 return 0;
672 } 671 }
673 goto __again; 672 goto __again;
674 } 673 }
675 } 674 }
676 up(&ensoniq->src_mutex); 675 up(&ensoniq->src_mutex);
677 snd_printk("es1371: codec read timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC))); 676 snd_printk(KERN_ERR "es1371: codec read timeout at 0x%lx [0x%x]\n", ES_REG(ensoniq, 1371_CODEC), inl(ES_REG(ensoniq, 1371_CODEC)));
678 return 0; 677 return 0;
679} 678}
680 679
@@ -1960,7 +1959,7 @@ static int __devinit snd_ensoniq_create(snd_card_t * card,
1960 } 1959 }
1961 ensoniq->port = pci_resource_start(pci, 0); 1960 ensoniq->port = pci_resource_start(pci, 0);
1962 if (request_irq(pci->irq, snd_audiopci_interrupt, SA_INTERRUPT|SA_SHIRQ, "Ensoniq AudioPCI", (void *)ensoniq)) { 1961 if (request_irq(pci->irq, snd_audiopci_interrupt, SA_INTERRUPT|SA_SHIRQ, "Ensoniq AudioPCI", (void *)ensoniq)) {
1963 snd_printk("unable to grab IRQ %d\n", pci->irq); 1962 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1964 snd_ensoniq_free(ensoniq); 1963 snd_ensoniq_free(ensoniq);
1965 return -EBUSY; 1964 return -EBUSY;
1966 } 1965 }
@@ -1968,7 +1967,7 @@ static int __devinit snd_ensoniq_create(snd_card_t * card,
1968#ifdef CHIP1370 1967#ifdef CHIP1370
1969 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1968 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1970 16, &ensoniq->dma_bug) < 0) { 1969 16, &ensoniq->dma_bug) < 0) {
1971 snd_printk("unable to allocate space for phantom area - dma_bug\n"); 1970 snd_printk(KERN_ERR "unable to allocate space for phantom area - dma_bug\n");
1972 snd_ensoniq_free(ensoniq); 1971 snd_ensoniq_free(ensoniq);
1973 return -EBUSY; 1972 return -EBUSY;
1974 } 1973 }
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 17fa80c23870..78f90defcab1 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -267,7 +267,7 @@ static void snd_es1938_mixer_write(es1938_t *chip, unsigned char reg, unsigned c
267 outb(val, SLSB_REG(chip, MIXERDATA)); 267 outb(val, SLSB_REG(chip, MIXERDATA));
268 spin_unlock_irqrestore(&chip->mixer_lock, flags); 268 spin_unlock_irqrestore(&chip->mixer_lock, flags);
269#ifdef REG_DEBUG 269#ifdef REG_DEBUG
270 snd_printk("Mixer reg %02x set to %02x\n", reg, val); 270 snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, val);
271#endif 271#endif
272} 272}
273 273
@@ -283,7 +283,7 @@ static int snd_es1938_mixer_read(es1938_t *chip, unsigned char reg)
283 data = inb(SLSB_REG(chip, MIXERDATA)); 283 data = inb(SLSB_REG(chip, MIXERDATA));
284 spin_unlock_irqrestore(&chip->mixer_lock, flags); 284 spin_unlock_irqrestore(&chip->mixer_lock, flags);
285#ifdef REG_DEBUG 285#ifdef REG_DEBUG
286 snd_printk("Mixer reg %02x now is %02x\n", reg, data); 286 snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data);
287#endif 287#endif
288 return data; 288 return data;
289} 289}
@@ -303,7 +303,8 @@ static int snd_es1938_mixer_bits(es1938_t *chip, unsigned char reg, unsigned cha
303 new = (old & ~mask) | (val & mask); 303 new = (old & ~mask) | (val & mask);
304 outb(new, SLSB_REG(chip, MIXERDATA)); 304 outb(new, SLSB_REG(chip, MIXERDATA));
305#ifdef REG_DEBUG 305#ifdef REG_DEBUG
306 snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg, old, new); 306 snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n",
307 reg, old, new);
307#endif 308#endif
308 } 309 }
309 spin_unlock_irqrestore(&chip->mixer_lock, flags); 310 spin_unlock_irqrestore(&chip->mixer_lock, flags);
@@ -323,7 +324,7 @@ static void snd_es1938_write_cmd(es1938_t *chip, unsigned char cmd)
323 return; 324 return;
324 } 325 }
325 } 326 }
326 printk("snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v); 327 printk(KERN_ERR "snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v);
327} 328}
328 329
329/* ----------------------------------------------------------------- 330/* -----------------------------------------------------------------
@@ -336,7 +337,7 @@ static int snd_es1938_get_byte(es1938_t *chip)
336 for (i = GET_LOOP_TIMEOUT; i; i--) 337 for (i = GET_LOOP_TIMEOUT; i; i--)
337 if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80) 338 if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80)
338 return inb(SLSB_REG(chip, READDATA)); 339 return inb(SLSB_REG(chip, READDATA));
339 snd_printk("get_byte timeout: status 0x02%x\n", v); 340 snd_printk(KERN_ERR "get_byte timeout: status 0x02%x\n", v);
340 return -ENODEV; 341 return -ENODEV;
341} 342}
342 343
@@ -351,7 +352,7 @@ static void snd_es1938_write(es1938_t *chip, unsigned char reg, unsigned char va
351 snd_es1938_write_cmd(chip, val); 352 snd_es1938_write_cmd(chip, val);
352 spin_unlock_irqrestore(&chip->reg_lock, flags); 353 spin_unlock_irqrestore(&chip->reg_lock, flags);
353#ifdef REG_DEBUG 354#ifdef REG_DEBUG
354 snd_printk("Reg %02x set to %02x\n", reg, val); 355 snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, val);
355#endif 356#endif
356} 357}
357 358
@@ -368,7 +369,7 @@ static unsigned char snd_es1938_read(es1938_t *chip, unsigned char reg)
368 val = snd_es1938_get_byte(chip); 369 val = snd_es1938_get_byte(chip);
369 spin_unlock_irqrestore(&chip->reg_lock, flags); 370 spin_unlock_irqrestore(&chip->reg_lock, flags);
370#ifdef REG_DEBUG 371#ifdef REG_DEBUG
371 snd_printk("Reg %02x now is %02x\n", reg, val); 372 snd_printk(KERN_DEBUG "Reg %02x now is %02x\n", reg, val);
372#endif 373#endif
373 return val; 374 return val;
374} 375}
@@ -390,7 +391,8 @@ static int snd_es1938_bits(es1938_t *chip, unsigned char reg, unsigned char mask
390 new = (old & ~mask) | (val & mask); 391 new = (old & ~mask) | (val & mask);
391 snd_es1938_write_cmd(chip, new); 392 snd_es1938_write_cmd(chip, new);
392#ifdef REG_DEBUG 393#ifdef REG_DEBUG
393 snd_printk("Reg %02x was %02x, set to %02x\n", reg, old, new); 394 snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x\n",
395 reg, old, new);
394#endif 396#endif
395 } 397 }
396 spin_unlock_irqrestore(&chip->reg_lock, flags); 398 spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -413,7 +415,7 @@ static void snd_es1938_reset(es1938_t *chip)
413 goto __next; 415 goto __next;
414 } 416 }
415 } 417 }
416 snd_printk("ESS Solo-1 reset failed\n"); 418 snd_printk(KERN_ERR "ESS Solo-1 reset failed\n");
417 419
418 __next: 420 __next:
419 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT); 421 snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT);
@@ -543,10 +545,12 @@ static int snd_es1938_capture_trigger(snd_pcm_substream_t * substream,
543 int val; 545 int val;
544 switch (cmd) { 546 switch (cmd) {
545 case SNDRV_PCM_TRIGGER_START: 547 case SNDRV_PCM_TRIGGER_START:
548 case SNDRV_PCM_TRIGGER_RESUME:
546 val = 0x0f; 549 val = 0x0f;
547 chip->active |= ADC1; 550 chip->active |= ADC1;
548 break; 551 break;
549 case SNDRV_PCM_TRIGGER_STOP: 552 case SNDRV_PCM_TRIGGER_STOP:
553 case SNDRV_PCM_TRIGGER_SUSPEND:
550 val = 0x00; 554 val = 0x00;
551 chip->active &= ~ADC1; 555 chip->active &= ~ADC1;
552 break; 556 break;
@@ -563,6 +567,7 @@ static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream,
563 es1938_t *chip = snd_pcm_substream_chip(substream); 567 es1938_t *chip = snd_pcm_substream_chip(substream);
564 switch (cmd) { 568 switch (cmd) {
565 case SNDRV_PCM_TRIGGER_START: 569 case SNDRV_PCM_TRIGGER_START:
570 case SNDRV_PCM_TRIGGER_RESUME:
566 /* According to the documentation this should be: 571 /* According to the documentation this should be:
567 0x13 but that value may randomly swap stereo channels */ 572 0x13 but that value may randomly swap stereo channels */
568 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x92); 573 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x92);
@@ -575,6 +580,7 @@ static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream,
575 chip->active |= DAC2; 580 chip->active |= DAC2;
576 break; 581 break;
577 case SNDRV_PCM_TRIGGER_STOP: 582 case SNDRV_PCM_TRIGGER_STOP:
583 case SNDRV_PCM_TRIGGER_SUSPEND:
578 outb(0, SLIO_REG(chip, AUDIO2MODE)); 584 outb(0, SLIO_REG(chip, AUDIO2MODE));
579 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0); 585 snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0);
580 chip->active &= ~DAC2; 586 chip->active &= ~DAC2;
@@ -592,10 +598,12 @@ static int snd_es1938_playback2_trigger(snd_pcm_substream_t * substream,
592 int val; 598 int val;
593 switch (cmd) { 599 switch (cmd) {
594 case SNDRV_PCM_TRIGGER_START: 600 case SNDRV_PCM_TRIGGER_START:
601 case SNDRV_PCM_TRIGGER_RESUME:
595 val = 5; 602 val = 5;
596 chip->active |= DAC1; 603 chip->active |= DAC1;
597 break; 604 break;
598 case SNDRV_PCM_TRIGGER_STOP: 605 case SNDRV_PCM_TRIGGER_STOP:
606 case SNDRV_PCM_TRIGGER_SUSPEND:
599 val = 0; 607 val = 0;
600 chip->active &= ~DAC1; 608 chip->active &= ~DAC1;
601 break; 609 break;
@@ -1390,7 +1398,8 @@ static int es1938_suspend(snd_card_t *card, pm_message_t state)
1390 *d = snd_es1938_reg_read(chip, *s); 1398 *d = snd_es1938_reg_read(chip, *s);
1391 1399
1392 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */ 1400 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
1393 1401 if (chip->irq >= 0)
1402 free_irq(chip->irq, (void *)chip);
1394 pci_disable_device(chip->pci); 1403 pci_disable_device(chip->pci);
1395 return 0; 1404 return 0;
1396} 1405}
@@ -1401,6 +1410,9 @@ static int es1938_resume(snd_card_t *card)
1401 unsigned char *s, *d; 1410 unsigned char *s, *d;
1402 1411
1403 pci_enable_device(chip->pci); 1412 pci_enable_device(chip->pci);
1413 request_irq(chip->pci->irq, snd_es1938_interrupt,
1414 SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip);
1415 chip->irq = chip->pci->irq;
1404 snd_es1938_chip_init(chip); 1416 snd_es1938_chip_init(chip);
1405 1417
1406 /* restore mixer-related registers */ 1418 /* restore mixer-related registers */
@@ -1489,7 +1501,7 @@ static int __devinit snd_es1938_create(snd_card_t * card,
1489 /* check, if we can restrict PCI DMA transfers to 24 bits */ 1501 /* check, if we can restrict PCI DMA transfers to 24 bits */
1490 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 1502 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
1491 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 1503 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
1492 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 1504 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
1493 pci_disable_device(pci); 1505 pci_disable_device(pci);
1494 return -ENXIO; 1506 return -ENXIO;
1495 } 1507 }
@@ -1514,13 +1526,13 @@ static int __devinit snd_es1938_create(snd_card_t * card,
1514 chip->mpu_port = pci_resource_start(pci, 3); 1526 chip->mpu_port = pci_resource_start(pci, 3);
1515 chip->game_port = pci_resource_start(pci, 4); 1527 chip->game_port = pci_resource_start(pci, 4);
1516 if (request_irq(pci->irq, snd_es1938_interrupt, SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip)) { 1528 if (request_irq(pci->irq, snd_es1938_interrupt, SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip)) {
1517 snd_printk("unable to grab IRQ %d\n", pci->irq); 1529 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1518 snd_es1938_free(chip); 1530 snd_es1938_free(chip);
1519 return -EBUSY; 1531 return -EBUSY;
1520 } 1532 }
1521 chip->irq = pci->irq; 1533 chip->irq = pci->irq;
1522#ifdef ES1938_DDEBUG 1534#ifdef ES1938_DDEBUG
1523 snd_printk("create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n", 1535 snd_printk(KERN_DEBUG "create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n",
1524 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port); 1536 chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
1525#endif 1537#endif
1526 1538
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index ecdcada90ca2..ac8294e21cc1 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -1462,13 +1462,13 @@ snd_es1968_init_dmabuf(es1968_t *chip)
1462 snd_dma_pci_data(chip->pci), 1462 snd_dma_pci_data(chip->pci),
1463 chip->total_bufsize, &chip->dma); 1463 chip->total_bufsize, &chip->dma);
1464 if (err < 0 || ! chip->dma.area) { 1464 if (err < 0 || ! chip->dma.area) {
1465 snd_printk("es1968: can't allocate dma pages for size %d\n", 1465 snd_printk(KERN_ERR "es1968: can't allocate dma pages for size %d\n",
1466 chip->total_bufsize); 1466 chip->total_bufsize);
1467 return -ENOMEM; 1467 return -ENOMEM;
1468 } 1468 }
1469 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) { 1469 if ((chip->dma.addr + chip->dma.bytes - 1) & ~((1 << 28) - 1)) {
1470 snd_dma_free_pages(&chip->dma); 1470 snd_dma_free_pages(&chip->dma);
1471 snd_printk("es1968: DMA buffer beyond 256MB.\n"); 1471 snd_printk(KERN_ERR "es1968: DMA buffer beyond 256MB.\n");
1472 return -ENOMEM; 1472 return -ENOMEM;
1473 } 1473 }
1474 } 1474 }
@@ -1741,11 +1741,11 @@ static void __devinit es1968_measure_clock(es1968_t *chip)
1741 1741
1742 /* search 2 APUs (although one apu is enough) */ 1742 /* search 2 APUs (although one apu is enough) */
1743 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) { 1743 if ((apu = snd_es1968_alloc_apu_pair(chip, ESM_APU_PCM_PLAY)) < 0) {
1744 snd_printk("Hmm, cannot find empty APU pair!?\n"); 1744 snd_printk(KERN_ERR "Hmm, cannot find empty APU pair!?\n");
1745 return; 1745 return;
1746 } 1746 }
1747 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) { 1747 if ((memory = snd_es1968_new_memory(chip, CLOCK_MEASURE_BUFSIZE)) == NULL) {
1748 snd_printk("cannot allocate dma buffer - using default clock %d\n", chip->clock); 1748 snd_printk(KERN_ERR "cannot allocate dma buffer - using default clock %d\n", chip->clock);
1749 snd_es1968_free_apu_pair(chip, apu); 1749 snd_es1968_free_apu_pair(chip, apu);
1750 return; 1750 return;
1751 } 1751 }
@@ -1806,7 +1806,7 @@ static void __devinit es1968_measure_clock(es1968_t *chip)
1806 else 1806 else
1807 t += stop_time.tv_usec - start_time.tv_usec; 1807 t += stop_time.tv_usec - start_time.tv_usec;
1808 if (t == 0) { 1808 if (t == 0) {
1809 snd_printk("?? calculation error..\n"); 1809 snd_printk(KERN_ERR "?? calculation error..\n");
1810 } else { 1810 } else {
1811 offset *= 1000; 1811 offset *= 1000;
1812 offset = (offset / t) * 1000 + ((offset % t) * 1000) / t; 1812 offset = (offset / t) * 1000 + ((offset % t) * 1000) / t;
@@ -2090,7 +2090,7 @@ static void snd_es1968_ac97_reset(es1968_t *chip)
2090 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c); 2090 outw(inw(ioaddr + 0x3c) & 0xfffc, ioaddr + 0x3c);
2091 2091
2092#if 0 /* the loop here needs to be much better if we want it.. */ 2092#if 0 /* the loop here needs to be much better if we want it.. */
2093 snd_printk("trying software reset\n"); 2093 snd_printk(KERN_INFO "trying software reset\n");
2094 /* try and do a software reset */ 2094 /* try and do a software reset */
2095 outb(0x80 | 0x7c, ioaddr + 0x30); 2095 outb(0x80 | 0x7c, ioaddr + 0x30);
2096 for (w = 0;; w++) { 2096 for (w = 0;; w++) {
@@ -2461,8 +2461,7 @@ static int __devinit snd_es1968_create_gameport(es1968_t *chip, int dev)
2461 chip->gameport = gp = gameport_allocate_port(); 2461 chip->gameport = gp = gameport_allocate_port();
2462 if (!gp) { 2462 if (!gp) {
2463 printk(KERN_ERR "es1968: cannot allocate memory for gameport\n"); 2463 printk(KERN_ERR "es1968: cannot allocate memory for gameport\n");
2464 release_resource(r); 2464 release_and_free_resource(r);
2465 kfree_nocheck(r);
2466 return -ENOMEM; 2465 return -ENOMEM;
2467 } 2466 }
2468 2467
@@ -2488,8 +2487,7 @@ static void snd_es1968_free_gameport(es1968_t *chip)
2488 gameport_unregister_port(chip->gameport); 2487 gameport_unregister_port(chip->gameport);
2489 chip->gameport = NULL; 2488 chip->gameport = NULL;
2490 2489
2491 release_resource(r); 2490 release_and_free_resource(r);
2492 kfree_nocheck(r);
2493 } 2491 }
2494} 2492}
2495#else 2493#else
@@ -2564,7 +2562,7 @@ static int __devinit snd_es1968_create(snd_card_t * card,
2564 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2562 /* check, if we can restrict PCI DMA transfers to 28 bits */
2565 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 || 2563 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2566 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) { 2564 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2567 snd_printk("architecture does not support 28bit PCI busmaster DMA\n"); 2565 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2568 pci_disable_device(pci); 2566 pci_disable_device(pci);
2569 return -ENXIO; 2567 return -ENXIO;
2570 } 2568 }
@@ -2599,7 +2597,7 @@ static int __devinit snd_es1968_create(snd_card_t * card,
2599 chip->io_port = pci_resource_start(pci, 0); 2597 chip->io_port = pci_resource_start(pci, 0);
2600 if (request_irq(pci->irq, snd_es1968_interrupt, SA_INTERRUPT|SA_SHIRQ, 2598 if (request_irq(pci->irq, snd_es1968_interrupt, SA_INTERRUPT|SA_SHIRQ,
2601 "ESS Maestro", (void*)chip)) { 2599 "ESS Maestro", (void*)chip)) {
2602 snd_printk("unable to grab IRQ %d\n", pci->irq); 2600 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2603 snd_es1968_free(chip); 2601 snd_es1968_free(chip);
2604 return -EBUSY; 2602 return -EBUSY;
2605 } 2603 }
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index e5cfa2a0c246..4c7c8d225c7f 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -237,7 +237,7 @@ static void snd_fm801_codec_write(ac97_t *ac97,
237 goto ok1; 237 goto ok1;
238 udelay(10); 238 udelay(10);
239 } 239 }
240 snd_printk("AC'97 interface is busy (1)\n"); 240 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
241 return; 241 return;
242 242
243 ok1: 243 ok1:
@@ -252,7 +252,7 @@ static void snd_fm801_codec_write(ac97_t *ac97,
252 return; 252 return;
253 udelay(10); 253 udelay(10);
254 } 254 }
255 snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num); 255 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
256} 256}
257 257
258static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg) 258static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
@@ -268,7 +268,7 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
268 goto ok1; 268 goto ok1;
269 udelay(10); 269 udelay(10);
270 } 270 }
271 snd_printk("AC'97 interface is busy (1)\n"); 271 snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
272 return 0; 272 return 0;
273 273
274 ok1: 274 ok1:
@@ -279,7 +279,7 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
279 goto ok2; 279 goto ok2;
280 udelay(10); 280 udelay(10);
281 } 281 }
282 snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num); 282 snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
283 return 0; 283 return 0;
284 284
285 ok2: 285 ok2:
@@ -288,7 +288,7 @@ static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
288 goto ok3; 288 goto ok3;
289 udelay(10); 289 udelay(10);
290 } 290 }
291 snd_printk("AC'97 interface #%d is not valid (2)\n", ac97->num); 291 snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num);
292 return 0; 292 return 0;
293 293
294 ok3: 294 ok3:
@@ -1279,7 +1279,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1279 } 1279 }
1280 chip->port = pci_resource_start(pci, 0); 1280 chip->port = pci_resource_start(pci, 0);
1281 if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) { 1281 if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) {
1282 snd_printk("unable to grab IRQ %d\n", chip->irq); 1282 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
1283 snd_fm801_free(chip); 1283 snd_fm801_free(chip);
1284 return -EBUSY; 1284 return -EBUSY;
1285 } 1285 }
@@ -1303,10 +1303,9 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1303 do { 1303 do {
1304 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) 1304 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
1305 goto __ac97_secondary; 1305 goto __ac97_secondary;
1306 set_current_state(TASK_UNINTERRUPTIBLE); 1306 schedule_timeout_uninterruptible(1);
1307 schedule_timeout(1);
1308 } while (time_after(timeout, jiffies)); 1307 } while (time_after(timeout, jiffies));
1309 snd_printk("Primary AC'97 codec not found\n"); 1308 snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
1310 snd_fm801_free(chip); 1309 snd_fm801_free(chip);
1311 return -EIO; 1310 return -EIO;
1312 1311
@@ -1329,8 +1328,7 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1329 goto __ac97_ok; 1328 goto __ac97_ok;
1330 } 1329 }
1331 } 1330 }
1332 set_current_state(TASK_UNINTERRUPTIBLE); 1331 schedule_timeout_uninterruptible(1);
1333 schedule_timeout(1);
1334 } while (time_after(timeout, jiffies)); 1332 } while (time_after(timeout, jiffies));
1335 } 1333 }
1336 1334
@@ -1343,10 +1341,9 @@ static int __devinit snd_fm801_create(snd_card_t * card,
1343 do { 1341 do {
1344 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) 1342 if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
1345 goto __ac97_ok; 1343 goto __ac97_ok;
1346 set_current_state(TASK_UNINTERRUPTIBLE); 1344 schedule_timeout_uninterruptible(1);
1347 schedule_timeout(1);
1348 } while (time_after(timeout, jiffies)); 1345 } while (time_after(timeout, jiffies));
1349 snd_printk("Primary AC'97 codec not responding\n"); 1346 snd_printk(KERN_ERR "Primary AC'97 codec not responding\n");
1350 snd_fm801_free(chip); 1347 snd_fm801_free(chip);
1351 return -EIO; 1348 return -EIO;
1352 1349
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 3815403ed095..0dbeeaf6113a 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -518,6 +518,13 @@ int snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
518 return -ENODEV; 518 return -ENODEV;
519 } 519 }
520 520
521 if (! codec->subsystem_id) {
522 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
523 codec->subsystem_id = snd_hda_codec_read(codec, nid, 0,
524 AC_VERB_GET_SUBSYSTEM_ID,
525 0);
526 }
527
521 codec->preset = find_codec_preset(codec); 528 codec->preset = find_codec_preset(codec);
522 if (! *bus->card->mixername) 529 if (! *bus->card->mixername)
523 snd_hda_get_codec_name(codec, bus->card->mixername, 530 snd_hda_get_codec_name(codec, bus->card->mixername,
@@ -814,6 +821,51 @@ int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t
814} 821}
815 822
816/* 823/*
824 * bound volume controls
825 *
826 * bind multiple volumes (# indices, from 0)
827 */
828
829#define AMP_VAL_IDX_SHIFT 19
830#define AMP_VAL_IDX_MASK (0x0f<<19)
831
832int snd_hda_mixer_bind_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
833{
834 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
835 unsigned long pval;
836 int err;
837
838 down(&codec->spdif_mutex); /* reuse spdif_mutex */
839 pval = kcontrol->private_value;
840 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
841 err = snd_hda_mixer_amp_switch_get(kcontrol, ucontrol);
842 kcontrol->private_value = pval;
843 up(&codec->spdif_mutex);
844 return err;
845}
846
847int snd_hda_mixer_bind_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
848{
849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 unsigned long pval;
851 int i, indices, err = 0, change = 0;
852
853 down(&codec->spdif_mutex); /* reuse spdif_mutex */
854 pval = kcontrol->private_value;
855 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT;
856 for (i = 0; i < indices; i++) {
857 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | (i << AMP_VAL_IDX_SHIFT);
858 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
859 if (err < 0)
860 break;
861 change |= err;
862 }
863 kcontrol->private_value = pval;
864 up(&codec->spdif_mutex);
865 return err < 0 ? err : change;
866}
867
868/*
817 * SPDIF out controls 869 * SPDIF out controls
818 */ 870 */
819 871
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index bb53bcf76742..1179d6cfa82a 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -79,6 +79,8 @@ enum {
79#define AC_VERB_GET_GPIO_MASK 0x0f16 79#define AC_VERB_GET_GPIO_MASK 0x0f16
80#define AC_VERB_GET_GPIO_DIRECTION 0x0f17 80#define AC_VERB_GET_GPIO_DIRECTION 0x0f17
81#define AC_VERB_GET_CONFIG_DEFAULT 0x0f1c 81#define AC_VERB_GET_CONFIG_DEFAULT 0x0f1c
82/* f20: AFG/MFG */
83#define AC_VERB_GET_SUBSYSTEM_ID 0x0f20
82 84
83/* 85/*
84 * SET verbs 86 * SET verbs
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 6fe696e53ea6..9d1412a9f2f8 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -47,23 +47,24 @@
47#include "hda_codec.h" 47#include "hda_codec.h"
48 48
49 49
50static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 50static int index = SNDRV_DEFAULT_IDX1;
51static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 51static char *id = SNDRV_DEFAULT_STR1;
52static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 52static char *model;
53static char *model[SNDRV_CARDS]; 53static int position_fix;
54static int position_fix[SNDRV_CARDS];
55 54
56module_param_array(index, int, NULL, 0444); 55module_param(index, int, 0444);
57MODULE_PARM_DESC(index, "Index value for Intel HD audio interface."); 56MODULE_PARM_DESC(index, "Index value for Intel HD audio interface.");
58module_param_array(id, charp, NULL, 0444); 57module_param(id, charp, 0444);
59MODULE_PARM_DESC(id, "ID string for Intel HD audio interface."); 58MODULE_PARM_DESC(id, "ID string for Intel HD audio interface.");
60module_param_array(enable, bool, NULL, 0444); 59module_param(model, charp, 0444);
61MODULE_PARM_DESC(enable, "Enable Intel HD audio interface.");
62module_param_array(model, charp, NULL, 0444);
63MODULE_PARM_DESC(model, "Use the given board model."); 60MODULE_PARM_DESC(model, "Use the given board model.");
64module_param_array(position_fix, int, NULL, 0444); 61module_param(position_fix, int, 0444);
65MODULE_PARM_DESC(position_fix, "Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size)."); 62MODULE_PARM_DESC(position_fix, "Fix DMA pointer (0 = auto, 1 = none, 2 = POSBUF, 3 = FIFO size).");
66 63
64/* just for backward compatibility */
65static int enable;
66module_param(enable, bool, 0444);
67
67MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
68MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," 69MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
69 "{Intel, ICH6M}," 70 "{Intel, ICH6M},"
@@ -223,6 +224,9 @@ enum {
223#define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42 224#define ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR 0x42
224#define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02 225#define ATI_SB450_HDAUDIO_ENABLE_SNOOP 0x02
225 226
227/* Defines for Nvidia HDA support */
228#define NVIDIA_HDA_TRANSREG_ADDR 0x4e
229#define NVIDIA_HDA_ENABLE_COHBITS 0x0f
226 230
227/* 231/*
228 * Use CORB/RIRB for communication from/to codecs. 232 * Use CORB/RIRB for communication from/to codecs.
@@ -328,6 +332,7 @@ enum {
328 AZX_DRIVER_VIA, 332 AZX_DRIVER_VIA,
329 AZX_DRIVER_SIS, 333 AZX_DRIVER_SIS,
330 AZX_DRIVER_ULI, 334 AZX_DRIVER_ULI,
335 AZX_DRIVER_NVIDIA,
331}; 336};
332 337
333static char *driver_short_names[] __devinitdata = { 338static char *driver_short_names[] __devinitdata = {
@@ -335,7 +340,8 @@ static char *driver_short_names[] __devinitdata = {
335 [AZX_DRIVER_ATI] = "HDA ATI SB", 340 [AZX_DRIVER_ATI] = "HDA ATI SB",
336 [AZX_DRIVER_VIA] = "HDA VIA VT82xx", 341 [AZX_DRIVER_VIA] = "HDA VIA VT82xx",
337 [AZX_DRIVER_SIS] = "HDA SIS966", 342 [AZX_DRIVER_SIS] = "HDA SIS966",
338 [AZX_DRIVER_ULI] = "HDA ULI M5461" 343 [AZX_DRIVER_ULI] = "HDA ULI M5461",
344 [AZX_DRIVER_NVIDIA] = "HDA NVidia",
339}; 345};
340 346
341/* 347/*
@@ -710,14 +716,14 @@ static void azx_stream_stop(azx_t *chip, azx_dev_t *azx_dev)
710 */ 716 */
711static void azx_init_chip(azx_t *chip) 717static void azx_init_chip(azx_t *chip)
712{ 718{
713 unsigned char tcsel_reg, ati_misc_cntl2; 719 unsigned char reg;
714 720
715 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) 721 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
716 * TCSEL == Traffic Class Select Register, which sets PCI express QOS 722 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
717 * Ensuring these bits are 0 clears playback static on some HD Audio codecs 723 * Ensuring these bits are 0 clears playback static on some HD Audio codecs
718 */ 724 */
719 pci_read_config_byte (chip->pci, ICH6_PCIREG_TCSEL, &tcsel_reg); 725 pci_read_config_byte (chip->pci, ICH6_PCIREG_TCSEL, &reg);
720 pci_write_config_byte(chip->pci, ICH6_PCIREG_TCSEL, tcsel_reg & 0xf8); 726 pci_write_config_byte(chip->pci, ICH6_PCIREG_TCSEL, reg & 0xf8);
721 727
722 /* reset controller */ 728 /* reset controller */
723 azx_reset(chip); 729 azx_reset(chip);
@@ -733,13 +739,21 @@ static void azx_init_chip(azx_t *chip)
733 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr); 739 azx_writel(chip, DPLBASE, (u32)chip->posbuf.addr);
734 azx_writel(chip, DPUBASE, upper_32bit(chip->posbuf.addr)); 740 azx_writel(chip, DPUBASE, upper_32bit(chip->posbuf.addr));
735 741
736 /* For ATI SB450 azalia HD audio, we need to enable snoop */ 742 switch (chip->driver_type) {
737 if (chip->driver_type == AZX_DRIVER_ATI) { 743 case AZX_DRIVER_ATI:
744 /* For ATI SB450 azalia HD audio, we need to enable snoop */
738 pci_read_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 745 pci_read_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
739 &ati_misc_cntl2); 746 &reg);
740 pci_write_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 747 pci_write_config_byte(chip->pci, ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR,
741 (ati_misc_cntl2 & 0xf8) | ATI_SB450_HDAUDIO_ENABLE_SNOOP); 748 (reg & 0xf8) | ATI_SB450_HDAUDIO_ENABLE_SNOOP);
742 } 749 break;
750 case AZX_DRIVER_NVIDIA:
751 /* For NVIDIA HDA, enable snoop */
752 pci_read_config_byte(chip->pci,NVIDIA_HDA_TRANSREG_ADDR, &reg);
753 pci_write_config_byte(chip->pci,NVIDIA_HDA_TRANSREG_ADDR,
754 (reg & 0xf0) | NVIDIA_HDA_ENABLE_COHBITS);
755 break;
756 }
743} 757}
744 758
745 759
@@ -1264,6 +1278,7 @@ static int __devinit azx_pcm_create(azx_t *chip)
1264 err = create_codec_pcm(chip, codec, &codec->pcm_info[c], pcm_dev); 1278 err = create_codec_pcm(chip, codec, &codec->pcm_info[c], pcm_dev);
1265 if (err < 0) 1279 if (err < 0)
1266 return err; 1280 return err;
1281 chip->pcm[pcm_dev]->dev_class = SNDRV_PCM_CLASS_MODEM;
1267 pcm_dev++; 1282 pcm_dev++;
1268 } 1283 }
1269 } 1284 }
@@ -1530,32 +1545,24 @@ static int __devinit azx_create(snd_card_t *card, struct pci_dev *pci,
1530 1545
1531static int __devinit azx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) 1546static int __devinit azx_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1532{ 1547{
1533 static int dev;
1534 snd_card_t *card; 1548 snd_card_t *card;
1535 azx_t *chip; 1549 azx_t *chip;
1536 int err = 0; 1550 int err = 0;
1537 1551
1538 if (dev >= SNDRV_CARDS) 1552 card = snd_card_new(index, id, THIS_MODULE, 0);
1539 return -ENODEV;
1540 if (! enable[dev]) {
1541 dev++;
1542 return -ENOENT;
1543 }
1544
1545 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1546 if (NULL == card) { 1553 if (NULL == card) {
1547 snd_printk(KERN_ERR SFX "Error creating card!\n"); 1554 snd_printk(KERN_ERR SFX "Error creating card!\n");
1548 return -ENOMEM; 1555 return -ENOMEM;
1549 } 1556 }
1550 1557
1551 if ((err = azx_create(card, pci, position_fix[dev], pci_id->driver_data, 1558 if ((err = azx_create(card, pci, position_fix, pci_id->driver_data,
1552 &chip)) < 0) { 1559 &chip)) < 0) {
1553 snd_card_free(card); 1560 snd_card_free(card);
1554 return err; 1561 return err;
1555 } 1562 }
1556 1563
1557 /* create codec instances */ 1564 /* create codec instances */
1558 if ((err = azx_codec_create(chip, model[dev])) < 0) { 1565 if ((err = azx_codec_create(chip, model)) < 0) {
1559 snd_card_free(card); 1566 snd_card_free(card);
1560 return err; 1567 return err;
1561 } 1568 }
@@ -1581,7 +1588,6 @@ static int __devinit azx_probe(struct pci_dev *pci, const struct pci_device_id *
1581 } 1588 }
1582 1589
1583 pci_set_drvdata(pci, card); 1590 pci_set_drvdata(pci, card);
1584 dev++;
1585 1591
1586 return err; 1592 return err;
1587} 1593}
@@ -1601,6 +1607,8 @@ static struct pci_device_id azx_ids[] = {
1601 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ 1607 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */
1602 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ 1608 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */
1603 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */ 1609 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */
1610 { 0x10de, 0x026c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA 026c */
1611 { 0x10de, 0x0371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA 0371 */
1604 { 0, } 1612 { 0, }
1605}; 1613};
1606MODULE_DEVICE_TABLE(pci, azx_ids); 1614MODULE_DEVICE_TABLE(pci, azx_ids);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 810cfd2d9bba..f51a56f813c8 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -27,28 +27,36 @@
27 * for mixer controls 27 * for mixer controls
28 */ 28 */
29#define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19)) 29#define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19))
30/* mono volume with index (index=0,1,...) (channel=1,2) */
30#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 31#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
31 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 32 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
32 .info = snd_hda_mixer_amp_volume_info, \ 33 .info = snd_hda_mixer_amp_volume_info, \
33 .get = snd_hda_mixer_amp_volume_get, \ 34 .get = snd_hda_mixer_amp_volume_get, \
34 .put = snd_hda_mixer_amp_volume_put, \ 35 .put = snd_hda_mixer_amp_volume_put, \
35 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) } 36 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
37/* stereo volume with index */
36#define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \ 38#define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
37 HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction) 39 HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
40/* mono volume */
38#define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \ 41#define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
39 HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction) 42 HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction)
43/* stereo volume */
40#define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \ 44#define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
41 HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction) 45 HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
46/* mono mute switch with index (index=0,1,...) (channel=1,2) */
42#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 47#define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
43 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 48 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
44 .info = snd_hda_mixer_amp_switch_info, \ 49 .info = snd_hda_mixer_amp_switch_info, \
45 .get = snd_hda_mixer_amp_switch_get, \ 50 .get = snd_hda_mixer_amp_switch_get, \
46 .put = snd_hda_mixer_amp_switch_put, \ 51 .put = snd_hda_mixer_amp_switch_put, \
47 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) } 52 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
53/* stereo mute switch with index */
48#define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \ 54#define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
49 HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction) 55 HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
56/* mono mute switch */
50#define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \ 57#define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
51 HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction) 58 HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
59/* stereo mute switch */
52#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \ 60#define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
53 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction) 61 HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
54 62
@@ -59,6 +67,20 @@ int snd_hda_mixer_amp_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
59int snd_hda_mixer_amp_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol); 67int snd_hda_mixer_amp_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
60int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol); 68int snd_hda_mixer_amp_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
61 69
70/* mono switch binding multiple inputs */
71#define HDA_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \
72 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
73 .info = snd_hda_mixer_amp_switch_info, \
74 .get = snd_hda_mixer_bind_switch_get, \
75 .put = snd_hda_mixer_bind_switch_put, \
76 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) }
77
78/* stereo switch binding multiple inputs */
79#define HDA_BIND_MUTE(xname,nid,indices,dir) HDA_BIND_MUTE_MONO(xname,nid,3,indices,dir)
80
81int snd_hda_mixer_bind_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
82int snd_hda_mixer_bind_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol);
83
62int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid); 84int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid);
63int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid); 85int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
64 86
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 08f6a6efc5e6..39ddf1cd9019 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -281,6 +281,11 @@ static void print_codec_info(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
281 print_pcm_caps(buffer, codec, nid); 281 print_pcm_caps(buffer, codec, nid);
282 } 282 }
283 283
284 if (wid_caps & AC_WCAP_POWER)
285 snd_iprintf(buffer, " Power: 0x%x\n",
286 snd_hda_codec_read(codec, nid, 0,
287 AC_VERB_GET_POWER_STATE, 0));
288
284 if (wid_caps & AC_WCAP_CONN_LIST) { 289 if (wid_caps & AC_WCAP_CONN_LIST) {
285 int c, curr = -1; 290 int c, curr = -1;
286 if (conn_len > 1 && wid_type != AC_WID_AUD_MIX) 291 if (conn_len > 1 && wid_type != AC_WID_AUD_MIX)
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index da6874d3988c..d7d636decef8 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -28,15 +28,38 @@
28#include "hda_local.h" 28#include "hda_local.h"
29 29
30struct ad198x_spec { 30struct ad198x_spec {
31 struct semaphore amp_mutex; /* PCM volume/mute control mutex */ 31 snd_kcontrol_new_t *mixers[5];
32 struct hda_multi_out multiout; /* playback */ 32 int num_mixers;
33 hda_nid_t adc_nid; 33
34 const struct hda_verb *init_verbs[3]; /* initialization verbs
35 * don't forget NULL termination!
36 */
37 unsigned int num_init_verbs;
38
39 /* playback */
40 struct hda_multi_out multiout; /* playback set-up
41 * max_channels, dacs must be set
42 * dig_out_nid and hp_nid are optional
43 */
44
45 /* capture */
46 unsigned int num_adc_nids;
47 hda_nid_t *adc_nids;
48 hda_nid_t dig_in_nid; /* digital-in NID; optional */
49
50 /* capture source */
34 const struct hda_input_mux *input_mux; 51 const struct hda_input_mux *input_mux;
35 unsigned int cur_mux; /* capture source */ 52 unsigned int cur_mux[3];
53
54 /* channel model */
55 const struct alc_channel_mode *channel_mode;
56 int num_channel_mode;
57
58 /* PCM information */
59 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
60
61 struct semaphore amp_mutex; /* PCM volume/mute control mutex */
36 unsigned int spdif_route; 62 unsigned int spdif_route;
37 snd_kcontrol_new_t *mixers;
38 const struct hda_verb *init_verbs;
39 struct hda_pcm pcm_rec[2]; /* PCM information */
40}; 63};
41 64
42/* 65/*
@@ -54,8 +77,9 @@ static int ad198x_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
54{ 77{
55 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 78 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
56 struct ad198x_spec *spec = codec->spec; 79 struct ad198x_spec *spec = codec->spec;
80 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
57 81
58 ucontrol->value.enumerated.item[0] = spec->cur_mux; 82 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
59 return 0; 83 return 0;
60} 84}
61 85
@@ -63,9 +87,10 @@ static int ad198x_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
63{ 87{
64 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 88 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
65 struct ad198x_spec *spec = codec->spec; 89 struct ad198x_spec *spec = codec->spec;
90 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
66 91
67 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol, 92 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
68 spec->adc_nid, &spec->cur_mux); 93 spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
69} 94}
70 95
71/* 96/*
@@ -74,22 +99,34 @@ static int ad198x_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
74static int ad198x_init(struct hda_codec *codec) 99static int ad198x_init(struct hda_codec *codec)
75{ 100{
76 struct ad198x_spec *spec = codec->spec; 101 struct ad198x_spec *spec = codec->spec;
77 snd_hda_sequence_write(codec, spec->init_verbs); 102 int i;
103
104 for (i = 0; i < spec->num_init_verbs; i++)
105 snd_hda_sequence_write(codec, spec->init_verbs[i]);
78 return 0; 106 return 0;
79} 107}
80 108
81static int ad198x_build_controls(struct hda_codec *codec) 109static int ad198x_build_controls(struct hda_codec *codec)
82{ 110{
83 struct ad198x_spec *spec = codec->spec; 111 struct ad198x_spec *spec = codec->spec;
112 unsigned int i;
84 int err; 113 int err;
85 114
86 err = snd_hda_add_new_ctls(codec, spec->mixers); 115 for (i = 0; i < spec->num_mixers; i++) {
87 if (err < 0) 116 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
88 return err; 117 if (err < 0)
89 if (spec->multiout.dig_out_nid) 118 return err;
119 }
120 if (spec->multiout.dig_out_nid) {
90 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 121 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
91 if (err < 0) 122 if (err < 0)
92 return err; 123 return err;
124 }
125 if (spec->dig_in_nid) {
126 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
127 if (err < 0)
128 return err;
129 }
93 return 0; 130 return 0;
94} 131}
95 132
@@ -152,7 +189,8 @@ static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
152 snd_pcm_substream_t *substream) 189 snd_pcm_substream_t *substream)
153{ 190{
154 struct ad198x_spec *spec = codec->spec; 191 struct ad198x_spec *spec = codec->spec;
155 snd_hda_codec_setup_stream(codec, spec->adc_nid, stream_tag, 0, format); 192 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
193 stream_tag, 0, format);
156 return 0; 194 return 0;
157} 195}
158 196
@@ -161,7 +199,8 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
161 snd_pcm_substream_t *substream) 199 snd_pcm_substream_t *substream)
162{ 200{
163 struct ad198x_spec *spec = codec->spec; 201 struct ad198x_spec *spec = codec->spec;
164 snd_hda_codec_setup_stream(codec, spec->adc_nid, 0, 0, 0); 202 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
203 0, 0, 0);
165 return 0; 204 return 0;
166} 205}
167 206
@@ -171,7 +210,7 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
171static struct hda_pcm_stream ad198x_pcm_analog_playback = { 210static struct hda_pcm_stream ad198x_pcm_analog_playback = {
172 .substreams = 1, 211 .substreams = 1,
173 .channels_min = 2, 212 .channels_min = 2,
174 .channels_max = 6, 213 .channels_max = 6, /* changed later */
175 .nid = 0, /* fill later */ 214 .nid = 0, /* fill later */
176 .ops = { 215 .ops = {
177 .open = ad198x_playback_pcm_open, 216 .open = ad198x_playback_pcm_open,
@@ -181,7 +220,7 @@ static struct hda_pcm_stream ad198x_pcm_analog_playback = {
181}; 220};
182 221
183static struct hda_pcm_stream ad198x_pcm_analog_capture = { 222static struct hda_pcm_stream ad198x_pcm_analog_capture = {
184 .substreams = 2, 223 .substreams = 1,
185 .channels_min = 2, 224 .channels_min = 2,
186 .channels_max = 2, 225 .channels_max = 2,
187 .nid = 0, /* fill later */ 226 .nid = 0, /* fill later */
@@ -202,6 +241,13 @@ static struct hda_pcm_stream ad198x_pcm_digital_playback = {
202 }, 241 },
203}; 242};
204 243
244static struct hda_pcm_stream ad198x_pcm_digital_capture = {
245 .substreams = 1,
246 .channels_min = 2,
247 .channels_max = 2,
248 /* NID is set in alc_build_pcms */
249};
250
205static int ad198x_build_pcms(struct hda_codec *codec) 251static int ad198x_build_pcms(struct hda_codec *codec)
206{ 252{
207 struct ad198x_spec *spec = codec->spec; 253 struct ad198x_spec *spec = codec->spec;
@@ -215,7 +261,8 @@ static int ad198x_build_pcms(struct hda_codec *codec)
215 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels; 261 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
216 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0]; 262 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
217 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture; 263 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
218 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nid; 264 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
265 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
219 266
220 if (spec->multiout.dig_out_nid) { 267 if (spec->multiout.dig_out_nid) {
221 info++; 268 info++;
@@ -223,6 +270,10 @@ static int ad198x_build_pcms(struct hda_codec *codec)
223 info->name = "AD198x Digital"; 270 info->name = "AD198x Digital";
224 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback; 271 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
225 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 272 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
273 if (spec->dig_in_nid) {
274 info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
275 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
276 }
226 } 277 }
227 278
228 return 0; 279 return 0;
@@ -237,10 +288,15 @@ static void ad198x_free(struct hda_codec *codec)
237static int ad198x_resume(struct hda_codec *codec) 288static int ad198x_resume(struct hda_codec *codec)
238{ 289{
239 struct ad198x_spec *spec = codec->spec; 290 struct ad198x_spec *spec = codec->spec;
291 int i;
240 292
241 ad198x_init(codec); 293 ad198x_init(codec);
242 snd_hda_resume_ctls(codec, spec->mixers); 294 for (i = 0; i < spec->num_mixers; i++)
243 snd_hda_resume_spdif_out(codec); 295 snd_hda_resume_ctls(codec, spec->mixers[i]);
296 if (spec->multiout.dig_out_nid)
297 snd_hda_resume_spdif_out(codec);
298 if (spec->dig_in_nid)
299 snd_hda_resume_spdif_in(codec);
244 return 0; 300 return 0;
245} 301}
246#endif 302#endif
@@ -269,6 +325,7 @@ static struct hda_codec_ops ad198x_patch_ops = {
269static hda_nid_t ad1986a_dac_nids[3] = { 325static hda_nid_t ad1986a_dac_nids[3] = {
270 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC 326 AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
271}; 327};
328static hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
272 329
273static struct hda_input_mux ad1986a_capture_source = { 330static struct hda_input_mux ad1986a_capture_source = {
274 .num_items = 7, 331 .num_items = 7,
@@ -476,10 +533,13 @@ static int patch_ad1986a(struct hda_codec *codec)
476 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids); 533 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
477 spec->multiout.dac_nids = ad1986a_dac_nids; 534 spec->multiout.dac_nids = ad1986a_dac_nids;
478 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT; 535 spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
479 spec->adc_nid = AD1986A_ADC; 536 spec->num_adc_nids = 1;
537 spec->adc_nids = ad1986a_adc_nids;
480 spec->input_mux = &ad1986a_capture_source; 538 spec->input_mux = &ad1986a_capture_source;
481 spec->mixers = ad1986a_mixers; 539 spec->num_mixers = 1;
482 spec->init_verbs = ad1986a_init_verbs; 540 spec->mixers[0] = ad1986a_mixers;
541 spec->num_init_verbs = 1;
542 spec->init_verbs[0] = ad1986a_init_verbs;
483 543
484 codec->patch_ops = ad198x_patch_ops; 544 codec->patch_ops = ad198x_patch_ops;
485 545
@@ -495,6 +555,7 @@ static int patch_ad1986a(struct hda_codec *codec)
495#define AD1983_ADC 0x04 555#define AD1983_ADC 0x04
496 556
497static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC }; 557static hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
558static hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
498 559
499static struct hda_input_mux ad1983_capture_source = { 560static struct hda_input_mux ad1983_capture_source = {
500 .num_items = 4, 561 .num_items = 4,
@@ -619,6 +680,7 @@ static struct hda_verb ad1983_init_verbs[] = {
619 { } /* end */ 680 { } /* end */
620}; 681};
621 682
683
622static int patch_ad1983(struct hda_codec *codec) 684static int patch_ad1983(struct hda_codec *codec)
623{ 685{
624 struct ad198x_spec *spec; 686 struct ad198x_spec *spec;
@@ -634,10 +696,13 @@ static int patch_ad1983(struct hda_codec *codec)
634 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids); 696 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
635 spec->multiout.dac_nids = ad1983_dac_nids; 697 spec->multiout.dac_nids = ad1983_dac_nids;
636 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT; 698 spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
637 spec->adc_nid = AD1983_ADC; 699 spec->num_adc_nids = 1;
700 spec->adc_nids = ad1983_adc_nids;
638 spec->input_mux = &ad1983_capture_source; 701 spec->input_mux = &ad1983_capture_source;
639 spec->mixers = ad1983_mixers; 702 spec->num_mixers = 1;
640 spec->init_verbs = ad1983_init_verbs; 703 spec->mixers[0] = ad1983_mixers;
704 spec->num_init_verbs = 1;
705 spec->init_verbs[0] = ad1983_init_verbs;
641 spec->spdif_route = 0; 706 spec->spdif_route = 0;
642 707
643 codec->patch_ops = ad198x_patch_ops; 708 codec->patch_ops = ad198x_patch_ops;
@@ -655,6 +720,7 @@ static int patch_ad1983(struct hda_codec *codec)
655#define AD1981_ADC 0x04 720#define AD1981_ADC 0x04
656 721
657static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC }; 722static hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
723static hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
658 724
659/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */ 725/* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
660static struct hda_input_mux ad1981_capture_source = { 726static struct hda_input_mux ad1981_capture_source = {
@@ -775,10 +841,13 @@ static int patch_ad1981(struct hda_codec *codec)
775 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids); 841 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
776 spec->multiout.dac_nids = ad1981_dac_nids; 842 spec->multiout.dac_nids = ad1981_dac_nids;
777 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT; 843 spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
778 spec->adc_nid = AD1981_ADC; 844 spec->num_adc_nids = 1;
845 spec->adc_nids = ad1981_adc_nids;
779 spec->input_mux = &ad1981_capture_source; 846 spec->input_mux = &ad1981_capture_source;
780 spec->mixers = ad1981_mixers; 847 spec->num_mixers = 1;
781 spec->init_verbs = ad1981_init_verbs; 848 spec->mixers[0] = ad1981_mixers;
849 spec->num_init_verbs = 1;
850 spec->init_verbs[0] = ad1981_init_verbs;
782 spec->spdif_route = 0; 851 spec->spdif_route = 0;
783 852
784 codec->patch_ops = ad198x_patch_ops; 853 codec->patch_ops = ad198x_patch_ops;
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 7327deb6df9f..cffb83fdcff7 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -57,6 +57,7 @@ enum {
57enum { 57enum {
58 ALC260_BASIC, 58 ALC260_BASIC,
59 ALC260_HP, 59 ALC260_HP,
60 ALC260_FUJITSU_S702x,
60 ALC260_MODEL_LAST /* last tag */ 61 ALC260_MODEL_LAST /* last tag */
61}; 62};
62 63
@@ -72,6 +73,7 @@ enum {
72#define PIN_VREF50 0x21 73#define PIN_VREF50 0x21
73#define PIN_OUT 0x40 74#define PIN_OUT 0x40
74#define PIN_HP 0xc0 75#define PIN_HP 0xc0
76#define PIN_HP_AMP 0x80
75 77
76struct alc_spec { 78struct alc_spec {
77 /* codec parameterization */ 79 /* codec parameterization */
@@ -113,8 +115,6 @@ struct alc_spec {
113 /* PCM information */ 115 /* PCM information */
114 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */ 116 struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
115 117
116 struct semaphore bind_mutex; /* for bound controls */
117
118 /* dynamic controls, init_verbs and input_mux */ 118 /* dynamic controls, init_verbs and input_mux */
119 struct auto_pin_cfg autocfg; 119 struct auto_pin_cfg autocfg;
120 unsigned int num_kctl_alloc, num_kctl_used; 120 unsigned int num_kctl_alloc, num_kctl_used;
@@ -218,72 +218,53 @@ static int alc880_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *uc
218 218
219 219
220/* 220/*
221 * bound volume controls 221 * Control of pin widget settings via the mixer. Only boolean settings are
222 * 222 * supported, so VrefEn can't be controlled using these functions as they
223 * bind multiple volumes (# indices, from 0) 223 * stand.
224 */ 224 */
225 225static int alc_pinctl_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
226#define AMP_VAL_IDX_SHIFT 19
227#define AMP_VAL_IDX_MASK (0x0f<<19)
228
229static int alc_bind_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
230{ 226{
231 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 227 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
232 struct alc_spec *spec = codec->spec; 228 uinfo->count = 1;
233 unsigned long pval; 229 uinfo->value.integer.min = 0;
234 230 uinfo->value.integer.max = 1;
235 down(&spec->bind_mutex);
236 pval = kcontrol->private_value;
237 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */
238 snd_hda_mixer_amp_switch_info(kcontrol, uinfo);
239 kcontrol->private_value = pval;
240 up(&spec->bind_mutex);
241 return 0; 231 return 0;
242} 232}
243 233
244static int alc_bind_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 234static int alc_pinctl_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
245{ 235{
246 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
247 struct alc_spec *spec = codec->spec; 237 hda_nid_t nid = kcontrol->private_value & 0xffff;
248 unsigned long pval; 238 long mask = (kcontrol->private_value >> 16) & 0xff;
249 239 long *valp = ucontrol->value.integer.value;
250 down(&spec->bind_mutex); 240
251 pval = kcontrol->private_value; 241 *valp = 0;
252 kcontrol->private_value = pval & ~AMP_VAL_IDX_MASK; /* index 0 */ 242 if (snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00) & mask)
253 snd_hda_mixer_amp_switch_get(kcontrol, ucontrol); 243 *valp = 1;
254 kcontrol->private_value = pval;
255 up(&spec->bind_mutex);
256 return 0; 244 return 0;
257} 245}
258 246
259static int alc_bind_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 247static int alc_pinctl_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
260{ 248{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct alc_spec *spec = codec->spec; 250 hda_nid_t nid = kcontrol->private_value & 0xffff;
263 unsigned long pval; 251 long mask = (kcontrol->private_value >> 16) & 0xff;
264 int i, indices, change = 0; 252 long *valp = ucontrol->value.integer.value;
265 253 unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
266 down(&spec->bind_mutex); 254 int change = ((pinctl & mask)!=0) != *valp;
267 pval = kcontrol->private_value; 255
268 indices = (pval & AMP_VAL_IDX_MASK) >> AMP_VAL_IDX_SHIFT; 256 if (change)
269 for (i = 0; i < indices; i++) { 257 snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
270 kcontrol->private_value = (pval & ~AMP_VAL_IDX_MASK) | (i << AMP_VAL_IDX_SHIFT); 258 *valp?(pinctl|mask):(pinctl&~mask));
271 change |= snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
272 }
273 kcontrol->private_value = pval;
274 up(&spec->bind_mutex);
275 return change; 259 return change;
276} 260}
277 261
278#define ALC_BIND_MUTE_MONO(xname, nid, channel, indices, direction) \ 262#define ALC_PINCTL_SWITCH(xname, nid, mask) \
279 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \ 263 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
280 .info = alc_bind_switch_info, \ 264 .info = alc_pinctl_switch_info, \
281 .get = alc_bind_switch_get, \ 265 .get = alc_pinctl_switch_get, \
282 .put = alc_bind_switch_put, \ 266 .put = alc_pinctl_switch_put, \
283 .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, indices, direction) } 267 .private_value = (nid) | (mask<<16) }
284
285#define ALC_BIND_MUTE(xname,nid,indices,dir) ALC_BIND_MUTE_MONO(xname,nid,3,indices,dir)
286
287 268
288/* 269/*
289 * ALC880 3-stack model 270 * ALC880 3-stack model
@@ -354,13 +335,13 @@ static struct alc_channel_mode alc880_threestack_modes[2] = {
354 335
355static snd_kcontrol_new_t alc880_three_stack_mixer[] = { 336static snd_kcontrol_new_t alc880_three_stack_mixer[] = {
356 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 337 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
357 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 338 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
358 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 339 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
359 ALC_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT), 340 HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
360 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 341 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
361 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 342 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
362 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 343 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
363 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 344 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
364 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 345 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
365 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 346 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
366 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 347 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
@@ -441,7 +422,7 @@ static snd_kcontrol_new_t alc880_capture_alt_mixer[] = {
441/* additional mixers to alc880_three_stack_mixer */ 422/* additional mixers to alc880_three_stack_mixer */
442static snd_kcontrol_new_t alc880_five_stack_mixer[] = { 423static snd_kcontrol_new_t alc880_five_stack_mixer[] = {
443 HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 424 HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
444 ALC_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT), 425 HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
445 { } /* end */ 426 { } /* end */
446}; 427};
447 428
@@ -498,15 +479,15 @@ static struct alc_channel_mode alc880_sixstack_modes[1] = {
498 479
499static snd_kcontrol_new_t alc880_six_stack_mixer[] = { 480static snd_kcontrol_new_t alc880_six_stack_mixer[] = {
500 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 481 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
501 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 482 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
502 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 483 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
503 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 484 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
504 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 485 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
505 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 486 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
506 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 487 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
507 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 488 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
508 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 489 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
509 ALC_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT), 490 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
510 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 491 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
511 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 492 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
512 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 493 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
@@ -566,13 +547,13 @@ static struct alc_channel_mode alc880_w810_modes[1] = {
566/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */ 547/* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
567static snd_kcontrol_new_t alc880_w810_base_mixer[] = { 548static snd_kcontrol_new_t alc880_w810_base_mixer[] = {
568 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 549 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
569 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 550 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
570 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 551 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
571 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 552 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
572 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 553 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
573 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 554 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
574 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 555 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
575 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 556 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
576 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 557 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
577 { } /* end */ 558 { } /* end */
578}; 559};
@@ -597,9 +578,9 @@ static struct alc_channel_mode alc880_2_jack_modes[1] = {
597 578
598static snd_kcontrol_new_t alc880_z71v_mixer[] = { 579static snd_kcontrol_new_t alc880_z71v_mixer[] = {
599 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 580 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
600 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 581 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
601 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 582 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
602 ALC_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT), 583 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
603 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 584 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
604 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 585 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
605 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 586 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -623,9 +604,9 @@ static hda_nid_t alc880_f1734_dac_nids[1] = {
623 604
624static snd_kcontrol_new_t alc880_f1734_mixer[] = { 605static snd_kcontrol_new_t alc880_f1734_mixer[] = {
625 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 606 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
626 ALC_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT), 607 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
627 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 608 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
628 ALC_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 609 HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
629 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 610 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
630 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 611 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
631 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 612 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
@@ -648,13 +629,13 @@ static snd_kcontrol_new_t alc880_f1734_mixer[] = {
648 629
649static snd_kcontrol_new_t alc880_asus_mixer[] = { 630static snd_kcontrol_new_t alc880_asus_mixer[] = {
650 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 631 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
651 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 632 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
652 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 633 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
653 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 634 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
654 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 635 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
655 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 636 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
656 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 637 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
657 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 638 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
658 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 639 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
659 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 640 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
660 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT), 641 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
@@ -1383,10 +1364,10 @@ static snd_kcontrol_new_t alc880_test_mixer[] = {
1383 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 1364 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
1384 HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT), 1365 HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
1385 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 1366 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
1386 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 1367 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
1387 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 1368 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
1388 ALC_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT), 1369 HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
1389 ALC_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT), 1370 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
1390 PIN_CTL_TEST("Front Pin Mode", 0x14), 1371 PIN_CTL_TEST("Front Pin Mode", 0x14),
1391 PIN_CTL_TEST("Surround Pin Mode", 0x15), 1372 PIN_CTL_TEST("Surround Pin Mode", 0x15),
1392 PIN_CTL_TEST("CLFE Pin Mode", 0x16), 1373 PIN_CTL_TEST("CLFE Pin Mode", 0x16),
@@ -1769,7 +1750,7 @@ enum {
1769static snd_kcontrol_new_t alc880_control_templates[] = { 1750static snd_kcontrol_new_t alc880_control_templates[] = {
1770 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 1751 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1771 HDA_CODEC_MUTE(NULL, 0, 0, 0), 1752 HDA_CODEC_MUTE(NULL, 0, 0, 0),
1772 ALC_BIND_MUTE(NULL, 0, 0, 0), 1753 HDA_BIND_MUTE(NULL, 0, 0, 0),
1773}; 1754};
1774 1755
1775/* add dynamic controls */ 1756/* add dynamic controls */
@@ -2087,7 +2068,6 @@ static int patch_alc880(struct hda_codec *codec)
2087 if (spec == NULL) 2068 if (spec == NULL)
2088 return -ENOMEM; 2069 return -ENOMEM;
2089 2070
2090 init_MUTEX(&spec->bind_mutex);
2091 codec->spec = spec; 2071 codec->spec = spec;
2092 2072
2093 board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl); 2073 board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl);
@@ -2205,6 +2185,17 @@ static struct hda_input_mux alc260_capture_source = {
2205 }, 2185 },
2206}; 2186};
2207 2187
2188/* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack
2189 * and the internal CD lines.
2190 */
2191static struct hda_input_mux alc260_fujitsu_capture_source = {
2192 .num_items = 2,
2193 .items = {
2194 { "Mic/Line", 0x0 },
2195 { "CD", 0x4 },
2196 },
2197};
2198
2208/* 2199/*
2209 * This is just place-holder, so there's something for alc_build_pcms to look 2200 * This is just place-holder, so there's something for alc_build_pcms to look
2210 * at when it calculates the maximum number of channels. ALC260 has no mixer 2201 * at when it calculates the maximum number of channels. ALC260 has no mixer
@@ -2217,7 +2208,7 @@ static struct alc_channel_mode alc260_modes[1] = {
2217 2208
2218static snd_kcontrol_new_t alc260_base_mixer[] = { 2209static snd_kcontrol_new_t alc260_base_mixer[] = {
2219 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2210 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2220 ALC_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT), 2211 HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
2221 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 2212 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2222 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 2213 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2223 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT), 2214 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
@@ -2229,9 +2220,9 @@ static snd_kcontrol_new_t alc260_base_mixer[] = {
2229 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT), 2220 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
2230 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT), 2221 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
2231 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT), 2222 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2232 ALC_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT), 2223 HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2233 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT), 2224 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2234 ALC_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT), 2225 HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
2235 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT), 2226 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
2236 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT), 2227 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
2237 { 2228 {
@@ -2246,7 +2237,7 @@ static snd_kcontrol_new_t alc260_base_mixer[] = {
2246 2237
2247static snd_kcontrol_new_t alc260_hp_mixer[] = { 2238static snd_kcontrol_new_t alc260_hp_mixer[] = {
2248 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT), 2239 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2249 ALC_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT), 2240 HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
2250 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 2241 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2251 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 2242 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2252 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT), 2243 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
@@ -2256,9 +2247,9 @@ static snd_kcontrol_new_t alc260_hp_mixer[] = {
2256 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT), 2247 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
2257 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT), 2248 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
2258 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT), 2249 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2259 ALC_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT), 2250 HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
2260 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT), 2251 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
2261 ALC_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT), 2252 HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
2262 HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT), 2253 HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
2263 HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT), 2254 HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
2264 { 2255 {
@@ -2271,6 +2262,30 @@ static snd_kcontrol_new_t alc260_hp_mixer[] = {
2271 { } /* end */ 2262 { } /* end */
2272}; 2263};
2273 2264
2265static snd_kcontrol_new_t alc260_fujitsu_mixer[] = {
2266 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
2267 HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
2268 ALC_PINCTL_SWITCH("Headphone Amp Switch", 0x14, PIN_HP_AMP),
2269 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
2270 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
2271 HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
2272 HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
2273 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
2274 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
2275 HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
2276 HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
2277 HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
2278 HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
2279 {
2280 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2281 .name = "Capture Source",
2282 .info = alc_mux_enum_info,
2283 .get = alc_mux_enum_get,
2284 .put = alc_mux_enum_put,
2285 },
2286 { } /* end */
2287};
2288
2274static struct hda_verb alc260_init_verbs[] = { 2289static struct hda_verb alc260_init_verbs[] = {
2275 /* Line In pin widget for input */ 2290 /* Line In pin widget for input */
2276 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 2291 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
@@ -2332,6 +2347,60 @@ static struct hda_verb alc260_init_verbs[] = {
2332 { } 2347 { }
2333}; 2348};
2334 2349
2350/* Initialisation sequence for ALC260 as configured in Fujitsu S702x
2351 * laptops.
2352 */
2353static struct hda_verb alc260_fujitsu_init_verbs[] = {
2354 /* Disable all GPIOs */
2355 {0x01, AC_VERB_SET_GPIO_MASK, 0},
2356 /* Internal speaker is connected to headphone pin */
2357 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
2358 /* Headphone/Line-out jack connects to Line1 pin; make it an output */
2359 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
2360 /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
2361 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
2362 /* Ensure all other unused pins are disabled and muted.
2363 * Note: trying to set widget 0x15 to anything blocks all audio
2364 * output for some reason, so just leave that at the default.
2365 */
2366 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2367 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2368 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2369 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2370 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
2371 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2372 /* Disable digital (SPDIF) pins */
2373 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
2374 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
2375
2376 /* Start with mixer outputs muted */
2377 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2378 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2379 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2380
2381 /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
2382 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2383 /* Unmute Line1 pin widget amp left and right (no equiv mixer ctrl) */
2384 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2385 /* Unmute pin widget used for Line-in (no equiv mixer ctrl) */
2386 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
2387
2388 /* Mute capture amp left and right */
2389 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2390 /* Set ADC connection select to line in (on mic1 pin) */
2391 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
2392
2393 /* Mute all inputs to mixer widget (even unconnected ones) */
2394 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
2395 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
2396 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
2397 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
2398 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
2399 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
2400 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
2401 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
2402};
2403
2335static struct hda_pcm_stream alc260_pcm_analog_playback = { 2404static struct hda_pcm_stream alc260_pcm_analog_playback = {
2336 .substreams = 1, 2405 .substreams = 1,
2337 .channels_min = 2, 2406 .channels_min = 2,
@@ -2347,6 +2416,8 @@ static struct hda_pcm_stream alc260_pcm_analog_capture = {
2347static struct hda_board_config alc260_cfg_tbl[] = { 2416static struct hda_board_config alc260_cfg_tbl[] = {
2348 { .modelname = "hp", .config = ALC260_HP }, 2417 { .modelname = "hp", .config = ALC260_HP },
2349 { .pci_subvendor = 0x103c, .config = ALC260_HP }, 2418 { .pci_subvendor = 0x103c, .config = ALC260_HP },
2419 { .modelname = "fujitsu", .config = ALC260_FUJITSU_S702x },
2420 { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1326, .config = ALC260_FUJITSU_S702x },
2350 {} 2421 {}
2351}; 2422};
2352 2423
@@ -2359,7 +2430,6 @@ static int patch_alc260(struct hda_codec *codec)
2359 if (spec == NULL) 2430 if (spec == NULL)
2360 return -ENOMEM; 2431 return -ENOMEM;
2361 2432
2362 init_MUTEX(&spec->bind_mutex);
2363 codec->spec = spec; 2433 codec->spec = spec;
2364 2434
2365 board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl); 2435 board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl);
@@ -2373,14 +2443,23 @@ static int patch_alc260(struct hda_codec *codec)
2373 spec->mixers[spec->num_mixers] = alc260_hp_mixer; 2443 spec->mixers[spec->num_mixers] = alc260_hp_mixer;
2374 spec->num_mixers++; 2444 spec->num_mixers++;
2375 break; 2445 break;
2446 case ALC260_FUJITSU_S702x:
2447 spec->mixers[spec->num_mixers] = alc260_fujitsu_mixer;
2448 spec->num_mixers++;
2449 break;
2376 default: 2450 default:
2377 spec->mixers[spec->num_mixers] = alc260_base_mixer; 2451 spec->mixers[spec->num_mixers] = alc260_base_mixer;
2378 spec->num_mixers++; 2452 spec->num_mixers++;
2379 break; 2453 break;
2380 } 2454 }
2381 2455
2382 spec->init_verbs[0] = alc260_init_verbs; 2456 if (board_config != ALC260_FUJITSU_S702x) {
2383 spec->num_init_verbs = 1; 2457 spec->init_verbs[0] = alc260_init_verbs;
2458 spec->num_init_verbs = 1;
2459 } else {
2460 spec->init_verbs[0] = alc260_fujitsu_init_verbs;
2461 spec->num_init_verbs = 1;
2462 }
2384 2463
2385 spec->channel_mode = alc260_modes; 2464 spec->channel_mode = alc260_modes;
2386 spec->num_channel_mode = ARRAY_SIZE(alc260_modes); 2465 spec->num_channel_mode = ARRAY_SIZE(alc260_modes);
@@ -2393,7 +2472,11 @@ static int patch_alc260(struct hda_codec *codec)
2393 spec->multiout.num_dacs = ARRAY_SIZE(alc260_dac_nids); 2472 spec->multiout.num_dacs = ARRAY_SIZE(alc260_dac_nids);
2394 spec->multiout.dac_nids = alc260_dac_nids; 2473 spec->multiout.dac_nids = alc260_dac_nids;
2395 2474
2396 spec->input_mux = &alc260_capture_source; 2475 if (board_config != ALC260_FUJITSU_S702x) {
2476 spec->input_mux = &alc260_capture_source;
2477 } else {
2478 spec->input_mux = &alc260_fujitsu_capture_source;
2479 }
2397 switch (board_config) { 2480 switch (board_config) {
2398 case ALC260_HP: 2481 case ALC260_HP:
2399 spec->num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids); 2482 spec->num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids);
@@ -2483,15 +2566,15 @@ static int alc882_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u
2483 */ 2566 */
2484static snd_kcontrol_new_t alc882_base_mixer[] = { 2567static snd_kcontrol_new_t alc882_base_mixer[] = {
2485 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 2568 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
2486 ALC_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 2569 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
2487 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT), 2570 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
2488 ALC_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT), 2571 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
2489 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT), 2572 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
2490 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 2573 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
2491 ALC_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT), 2574 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
2492 ALC_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT), 2575 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
2493 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT), 2576 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
2494 ALC_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT), 2577 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
2495 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 2578 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
2496 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 2579 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
2497 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 2580 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -2609,7 +2692,6 @@ static int patch_alc882(struct hda_codec *codec)
2609 if (spec == NULL) 2692 if (spec == NULL)
2610 return -ENOMEM; 2693 return -ENOMEM;
2611 2694
2612 init_MUTEX(&spec->bind_mutex);
2613 codec->spec = spec; 2695 codec->spec = spec;
2614 2696
2615 spec->mixers[spec->num_mixers] = alc882_base_mixer; 2697 spec->mixers[spec->num_mixers] = alc882_base_mixer;
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index d014b7bb70df..9c7fe0b3200a 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * HD audio interface patch for Silicon Labs 3054/5 modem codec 4 * HD audio interface patch for Silicon Labs 3054/5 modem codec
5 * 5 *
6 * Copyright (c) 2005 Sasha Khapyorsky <sashak@smlink.com> 6 * Copyright (c) 2005 Sasha Khapyorsky <sashak@alsa-project.org>
7 * Takashi Iwai <tiwai@suse.de> 7 * Takashi Iwai <tiwai@suse.de>
8 * 8 *
9 * 9 *
diff --git a/sound/pci/ice1712/aureon.c b/sound/pci/ice1712/aureon.c
index 2e0a31613ee6..db12b038286b 100644
--- a/sound/pci/ice1712/aureon.c
+++ b/sound/pci/ice1712/aureon.c
@@ -960,7 +960,7 @@ static int wm_adc_mux_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *ucont
960 if (change) 960 if (change)
961 wm_put(ice, WM_ADC_MUX, nval); 961 wm_put(ice, WM_ADC_MUX, nval);
962 snd_ice1712_restore_gpio_status(ice); 962 snd_ice1712_restore_gpio_status(ice);
963 return 0; 963 return change;
964} 964}
965 965
966/* 966/*
@@ -1672,9 +1672,9 @@ static int __devinit aureon_add_controls(ice1712_t *ice)
1672 snd_ice1712_save_gpio_status(ice); 1672 snd_ice1712_save_gpio_status(ice);
1673 id = aureon_cs8415_get(ice, CS8415_ID); 1673 id = aureon_cs8415_get(ice, CS8415_ID);
1674 if (id != 0x41) 1674 if (id != 0x41)
1675 snd_printk("No CS8415 chip. Skipping CS8415 controls.\n"); 1675 snd_printk(KERN_INFO "No CS8415 chip. Skipping CS8415 controls.\n");
1676 else if ((id & 0x0F) != 0x01) 1676 else if ((id & 0x0F) != 0x01)
1677 snd_printk("Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1)); 1677 snd_printk(KERN_INFO "Detected unsupported CS8415 rev. (%c)\n", (char)((id & 0x0F) + 'A' - 1));
1678 else { 1678 else {
1679 for (i = 0; i< ARRAY_SIZE(cs8415_controls); i++) { 1679 for (i = 0; i< ARRAY_SIZE(cs8415_controls); i++) {
1680 snd_kcontrol_t *kctl; 1680 snd_kcontrol_t *kctl;
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index 39fbe662965d..576f69d482c9 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -546,7 +546,7 @@ static int __devinit snd_ice1712_delta_init(ice1712_t *ice)
546 case ICE1712_SUBDEVICE_DELTA1010LT: 546 case ICE1712_SUBDEVICE_DELTA1010LT:
547 case ICE1712_SUBDEVICE_VX442: 547 case ICE1712_SUBDEVICE_VX442:
548 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 548 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
549 snd_printk("unable to create I2C bus\n"); 549 snd_printk(KERN_ERR "unable to create I2C bus\n");
550 return err; 550 return err;
551 } 551 }
552 ice->i2c->private_data = ice; 552 ice->i2c->private_data = ice;
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index e36efa1bdac3..c8ec5cac3c17 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -438,7 +438,7 @@ static int __devinit snd_ice1712_ews_init(ice1712_t *ice)
438 438
439 /* create i2c */ 439 /* create i2c */
440 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 440 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
441 snd_printk("unable to create I2C bus\n"); 441 snd_printk(KERN_ERR "unable to create I2C bus\n");
442 return err; 442 return err;
443 } 443 }
444 ice->i2c->private_data = ice; 444 ice->i2c->private_data = ice;
@@ -448,7 +448,7 @@ static int __devinit snd_ice1712_ews_init(ice1712_t *ice)
448 switch (ice->eeprom.subvendor) { 448 switch (ice->eeprom.subvendor) {
449 case ICE1712_SUBDEVICE_DMX6FIRE: 449 case ICE1712_SUBDEVICE_DMX6FIRE:
450 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->spec.i2cdevs[EWS_I2C_6FIRE])) < 0) { 450 if ((err = snd_i2c_device_create(ice->i2c, "PCF9554", ICE1712_6FIRE_PCF9554_ADDR, &ice->spec.i2cdevs[EWS_I2C_6FIRE])) < 0) {
451 snd_printk("PCF9554 initialization failed\n"); 451 snd_printk(KERN_ERR "PCF9554 initialization failed\n");
452 return err; 452 return err;
453 } 453 }
454 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80); 454 snd_ice1712_6fire_write_pca(ice, PCF9554_REG_CONFIG, 0x80);
@@ -791,7 +791,7 @@ static int snd_ice1712_6fire_read_pca(ice1712_t *ice, unsigned char reg)
791 byte = 0; 791 byte = 0;
792 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) { 792 if (snd_i2c_readbytes(ice->spec.i2cdevs[EWS_I2C_6FIRE], &byte, 1) != 1) {
793 snd_i2c_unlock(ice->i2c); 793 snd_i2c_unlock(ice->i2c);
794 printk("cannot read pca\n"); 794 printk(KERN_ERR "cannot read pca\n");
795 return -EIO; 795 return -EIO;
796 } 796 }
797 snd_i2c_unlock(ice->i2c); 797 snd_i2c_unlock(ice->i2c);
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index a6d98013c331..5aca37798c32 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -387,7 +387,7 @@ int __devinit snd_ice1712_init_cs8427(ice1712_t *ice, int addr)
387 if ((err = snd_cs8427_create(ice->i2c, addr, 387 if ((err = snd_cs8427_create(ice->i2c, addr,
388 (ice->cs8427_timeout * HZ) / 1000, 388 (ice->cs8427_timeout * HZ) / 1000,
389 &ice->cs8427)) < 0) { 389 &ice->cs8427)) < 0) {
390 snd_printk("CS8427 initialization failed\n"); 390 snd_printk(KERN_ERR "CS8427 initialization failed\n");
391 return err; 391 return err;
392 } 392 }
393 ice->spdif.ops.open = open_cs8427; 393 ice->spdif.ops.open = open_cs8427;
@@ -2348,12 +2348,12 @@ static int __devinit snd_ice1712_read_eeprom(ice1712_t *ice, const char *modelna
2348 if (ice->eeprom.size < 6) 2348 if (ice->eeprom.size < 6)
2349 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */ 2349 ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */
2350 else if (ice->eeprom.size > 32) { 2350 else if (ice->eeprom.size > 32) {
2351 snd_printk("invalid EEPROM (size = %i)\n", ice->eeprom.size); 2351 snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size);
2352 return -EIO; 2352 return -EIO;
2353 } 2353 }
2354 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05); 2354 ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05);
2355 if (ice->eeprom.version != 1) { 2355 if (ice->eeprom.version != 1) {
2356 snd_printk("invalid EEPROM version %i\n", ice->eeprom.version); 2356 snd_printk(KERN_ERR "invalid EEPROM version %i\n", ice->eeprom.version);
2357 /* return -EIO; */ 2357 /* return -EIO; */
2358 } 2358 }
2359 size = ice->eeprom.size - 6; 2359 size = ice->eeprom.size - 6;
@@ -2524,7 +2524,7 @@ static int __devinit snd_ice1712_create(snd_card_t * card,
2524 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2524 /* check, if we can restrict PCI DMA transfers to 28 bits */
2525 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 || 2525 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2526 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) { 2526 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2527 snd_printk("architecture does not support 28bit PCI busmaster DMA\n"); 2527 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2528 pci_disable_device(pci); 2528 pci_disable_device(pci);
2529 return -ENXIO; 2529 return -ENXIO;
2530 } 2530 }
@@ -2573,7 +2573,7 @@ static int __devinit snd_ice1712_create(snd_card_t * card,
2573 ice->profi_port = pci_resource_start(pci, 3); 2573 ice->profi_port = pci_resource_start(pci, 3);
2574 2574
2575 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) { 2575 if (request_irq(pci->irq, snd_ice1712_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1712", (void *) ice)) {
2576 snd_printk("unable to grab IRQ %d\n", pci->irq); 2576 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2577 snd_ice1712_free(ice); 2577 snd_ice1712_free(ice);
2578 return -EIO; 2578 return -EIO;
2579 } 2579 }
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index c3ce8f93740b..5b4293f5a652 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -675,9 +675,12 @@ static snd_pcm_hardware_t snd_vt1724_spdif =
675 SNDRV_PCM_INFO_MMAP_VALID | 675 SNDRV_PCM_INFO_MMAP_VALID |
676 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START), 676 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START),
677 .formats = SNDRV_PCM_FMTBIT_S32_LE, 677 .formats = SNDRV_PCM_FMTBIT_S32_LE,
678 .rates = SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|SNDRV_PCM_RATE_48000, 678 .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100|
679 SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200|
680 SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400|
681 SNDRV_PCM_RATE_192000),
679 .rate_min = 32000, 682 .rate_min = 32000,
680 .rate_max = 48000, 683 .rate_max = 192000,
681 .channels_min = 2, 684 .channels_min = 2,
682 .channels_max = 2, 685 .channels_max = 2,
683 .buffer_bytes_max = (1UL << 18), /* 16bits dword */ 686 .buffer_bytes_max = (1UL << 18), /* 16bits dword */
@@ -905,6 +908,10 @@ static void update_spdif_rate(ice1712_t *ice, unsigned int rate)
905 case 44100: break; 908 case 44100: break;
906 case 48000: nval |= 2 << 12; break; 909 case 48000: nval |= 2 << 12; break;
907 case 32000: nval |= 3 << 12; break; 910 case 32000: nval |= 3 << 12; break;
911 case 88200: nval |= 4 << 12; break;
912 case 96000: nval |= 5 << 12; break;
913 case 192000: nval |= 6 << 12; break;
914 case 176400: nval |= 7 << 12; break;
908 } 915 }
909 if (val != nval) 916 if (val != nval)
910 update_spdif_bits(ice, nval); 917 update_spdif_bits(ice, nval);
@@ -1292,22 +1299,32 @@ static int snd_vt1724_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *
1292 1299
1293static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga) 1300static unsigned int encode_spdif_bits(snd_aes_iec958_t *diga)
1294{ 1301{
1295 unsigned int val; 1302 unsigned int val, rbits;
1296 1303
1297 val = diga->status[0] & 0x03; /* professional, non-audio */ 1304 val = diga->status[0] & 0x03; /* professional, non-audio */
1298 if (val & 0x01) { 1305 if (val & 0x01) {
1299 /* professional */ 1306 /* professional */
1300 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015) 1307 if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == IEC958_AES0_PRO_EMPHASIS_5015)
1301 val |= 1U << 3; 1308 val |= 1U << 3;
1302 switch (diga->status[0] & IEC958_AES0_PRO_FS) { 1309 rbits = (diga->status[4] >> 3) & 0x0f;
1303 case IEC958_AES0_PRO_FS_44100: 1310 if (rbits) {
1304 break; 1311 switch (rbits) {
1305 case IEC958_AES0_PRO_FS_32000: 1312 case 2: val |= 5 << 12; break; /* 96k */
1306 val |= 3U << 12; 1313 case 3: val |= 6 << 12; break; /* 192k */
1307 break; 1314 case 10: val |= 4 << 12; break; /* 88.2k */
1308 default: 1315 case 11: val |= 7 << 12; break; /* 176.4k */
1309 val |= 2U << 12; 1316 }
1310 break; 1317 } else {
1318 switch (diga->status[0] & IEC958_AES0_PRO_FS) {
1319 case IEC958_AES0_PRO_FS_44100:
1320 break;
1321 case IEC958_AES0_PRO_FS_32000:
1322 val |= 3U << 12;
1323 break;
1324 default:
1325 val |= 2U << 12;
1326 break;
1327 }
1311 } 1328 }
1312 } else { 1329 } else {
1313 /* consumer */ 1330 /* consumer */
@@ -2154,7 +2171,7 @@ static int __devinit snd_vt1724_create(snd_card_t * card,
2154 ice->profi_port = pci_resource_start(pci, 1); 2171 ice->profi_port = pci_resource_start(pci, 1);
2155 2172
2156 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) { 2173 if (request_irq(pci->irq, snd_vt1724_interrupt, SA_INTERRUPT|SA_SHIRQ, "ICE1724", (void *) ice)) {
2157 snd_printk("unable to grab IRQ %d\n", pci->irq); 2174 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2158 snd_vt1724_free(ice); 2175 snd_vt1724_free(ice);
2159 return -EIO; 2176 return -EIO;
2160 } 2177 }
diff --git a/sound/pci/ice1712/pontis.c b/sound/pci/ice1712/pontis.c
index a5f852b1f575..773a1ecb75ce 100644
--- a/sound/pci/ice1712/pontis.c
+++ b/sound/pci/ice1712/pontis.c
@@ -794,8 +794,7 @@ static int __devinit pontis_init(ice1712_t *ice)
794 /* initialize WM8776 codec */ 794 /* initialize WM8776 codec */
795 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2) 795 for (i = 0; i < ARRAY_SIZE(wm_inits); i += 2)
796 wm_put(ice, wm_inits[i], wm_inits[i+1]); 796 wm_put(ice, wm_inits[i], wm_inits[i+1]);
797 set_current_state(TASK_UNINTERRUPTIBLE); 797 schedule_timeout_uninterruptible(1);
798 schedule_timeout(1);
799 for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2) 798 for (i = 0; i < ARRAY_SIZE(wm_inits2); i += 2)
800 wm_put(ice, wm_inits2[i], wm_inits2[i+1]); 799 wm_put(ice, wm_inits2[i], wm_inits2[i+1]);
801 800
diff --git a/sound/pci/ice1712/revo.c b/sound/pci/ice1712/revo.c
index d48d42524ac5..1fe21009ca84 100644
--- a/sound/pci/ice1712/revo.c
+++ b/sound/pci/ice1712/revo.c
@@ -128,17 +128,6 @@ static struct snd_ak4xxx_private akm_revo_surround_priv __devinitdata = {
128 .mask_flags = 0, 128 .mask_flags = 0,
129}; 129};
130 130
131static unsigned int rates[] = {
132 32000, 44100, 48000, 64000, 88200, 96000,
133 176400, 192000,
134};
135
136static snd_pcm_hw_constraint_list_t revo_rates = {
137 .count = ARRAY_SIZE(rates),
138 .list = rates,
139 .mask = 0,
140};
141
142static int __devinit revo_init(ice1712_t *ice) 131static int __devinit revo_init(ice1712_t *ice)
143{ 132{
144 akm4xxx_t *ak; 133 akm4xxx_t *ak;
@@ -173,8 +162,6 @@ static int __devinit revo_init(ice1712_t *ice)
173 break; 162 break;
174 } 163 }
175 164
176 ice->hw_rates = &revo_rates; /* AK codecs don't support lower than 32k */
177
178 return 0; 165 return 0;
179} 166}
180 167
diff --git a/sound/pci/ice1712/vt1720_mobo.c b/sound/pci/ice1712/vt1720_mobo.c
index ab61e383024f..90c85cd95479 100644
--- a/sound/pci/ice1712/vt1720_mobo.c
+++ b/sound/pci/ice1712/vt1720_mobo.c
@@ -71,6 +71,22 @@ static unsigned char k8x800_eeprom[] __devinitdata = {
71 0x00, /* - */ 71 0x00, /* - */
72}; 72};
73 73
74static unsigned char sn25p_eeprom[] __devinitdata = {
75 0x01, /* SYSCONF: clock 256, 1ADC, 2DACs */
76 0x02, /* ACLINK: ACLINK, packed */
77 0x00, /* I2S: - */
78 0x41, /* SPDIF: - */
79 0xff, /* GPIO_DIR */
80 0xff, /* GPIO_DIR1 */
81 0x00, /* - */
82 0xff, /* GPIO_MASK */
83 0xff, /* GPIO_MASK1 */
84 0x00, /* - */
85 0x00, /* GPIO_STATE */
86 0x00, /* GPIO_STATE1 */
87 0x00, /* - */
88};
89
74 90
75/* entry point */ 91/* entry point */
76struct snd_ice1712_card_info snd_vt1720_mobo_cards[] __devinitdata = { 92struct snd_ice1712_card_info snd_vt1720_mobo_cards[] __devinitdata = {
@@ -113,11 +129,11 @@ struct snd_ice1712_card_info snd_vt1720_mobo_cards[] __devinitdata = {
113 { 129 {
114 .subvendor = VT1720_SUBDEVICE_SN25P, 130 .subvendor = VT1720_SUBDEVICE_SN25P,
115 .name = "Shuttle SN25P", 131 .name = "Shuttle SN25P",
116 /* identical with k8x800 */ 132 .model = "sn25p",
117 .chip_init = k8x800_init, 133 .chip_init = k8x800_init,
118 .build_controls = k8x800_add_controls, 134 .build_controls = k8x800_add_controls,
119 .eeprom_size = sizeof(k8x800_eeprom), 135 .eeprom_size = sizeof(k8x800_eeprom),
120 .eeprom_data = k8x800_eeprom, 136 .eeprom_data = sn25p_eeprom,
121 }, 137 },
122 { } /* terminator */ 138 { } /* terminator */
123}; 139};
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 1a96198a17ae..0801083f32dd 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -64,36 +64,35 @@ MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
64 "{AMD,AMD8111}," 64 "{AMD,AMD8111},"
65 "{ALI,M5455}}"); 65 "{ALI,M5455}}");
66 66
67static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 67static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
68static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 68static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
69static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 69static int ac97_clock = 0;
70static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; 70static char *ac97_quirk;
71static char *ac97_quirk[SNDRV_CARDS]; 71static int buggy_semaphore;
72static int buggy_semaphore[SNDRV_CARDS]; 72static int buggy_irq = -1; /* auto-check */
73static int buggy_irq[SNDRV_CARDS]; 73static int xbox;
74static int xbox[SNDRV_CARDS]; 74
75 75module_param(index, int, 0444);
76#ifdef SUPPORT_MIDI
77static int mpu_port[SNDRV_CARDS]; /* disabled */
78#endif
79
80module_param_array(index, int, NULL, 0444);
81MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard."); 76MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
82module_param_array(id, charp, NULL, 0444); 77module_param(id, charp, 0444);
83MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard."); 78MODULE_PARM_DESC(id, "ID string for Intel i8x0 soundcard.");
84module_param_array(enable, bool, NULL, 0444); 79module_param(ac97_clock, int, 0444);
85MODULE_PARM_DESC(enable, "Enable Intel i8x0 soundcard.");
86module_param_array(ac97_clock, int, NULL, 0444);
87MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect)."); 80MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
88module_param_array(ac97_quirk, charp, NULL, 0444); 81module_param(ac97_quirk, charp, 0444);
89MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 82MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
90module_param_array(buggy_semaphore, bool, NULL, 0444); 83module_param(buggy_semaphore, bool, 0444);
91MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores."); 84MODULE_PARM_DESC(buggy_semaphore, "Enable workaround for hardwares with problematic codec semaphores.");
92module_param_array(buggy_irq, bool, NULL, 0444); 85module_param(buggy_irq, bool, 0444);
93MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards."); 86MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
94module_param_array(xbox, bool, NULL, 0444); 87module_param(xbox, bool, 0444);
95MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection."); 88MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
96 89
90/* just for backward compatibility */
91static int enable;
92module_param(enable, bool, 0444);
93static int joystick;
94module_param(joystick, int, 0444);
95
97/* 96/*
98 * Direct registers 97 * Direct registers
99 */ 98 */
@@ -539,7 +538,7 @@ static int snd_intel8x0_codec_semaphore(intel8x0_t *chip, unsigned int codec)
539 /* access to some forbidden (non existant) ac97 registers will not 538 /* access to some forbidden (non existant) ac97 registers will not
540 * reset the semaphore. So even if you don't get the semaphore, still 539 * reset the semaphore. So even if you don't get the semaphore, still
541 * continue the access. We don't need the semaphore anyway. */ 540 * continue the access. We don't need the semaphore anyway. */
542 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n", 541 snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
543 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA))); 542 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
544 iagetword(chip, 0); /* clear semaphore flag */ 543 iagetword(chip, 0); /* clear semaphore flag */
545 /* I don't care about the semaphore */ 544 /* I don't care about the semaphore */
@@ -554,7 +553,7 @@ static void snd_intel8x0_codec_write(ac97_t *ac97,
554 553
555 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) { 554 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
556 if (! chip->in_ac97_init) 555 if (! chip->in_ac97_init)
557 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 556 snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
558 } 557 }
559 iaputword(chip, reg + ac97->num * 0x80, val); 558 iaputword(chip, reg + ac97->num * 0x80, val);
560} 559}
@@ -568,7 +567,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
568 567
569 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) { 568 if (snd_intel8x0_codec_semaphore(chip, ac97->num) < 0) {
570 if (! chip->in_ac97_init) 569 if (! chip->in_ac97_init)
571 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 570 snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
572 res = 0xffff; 571 res = 0xffff;
573 } else { 572 } else {
574 res = iagetword(chip, reg + ac97->num * 0x80); 573 res = iagetword(chip, reg + ac97->num * 0x80);
@@ -576,7 +575,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
576 /* reset RCS and preserve other R/WC bits */ 575 /* reset RCS and preserve other R/WC bits */
577 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI)); 576 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
578 if (! chip->in_ac97_init) 577 if (! chip->in_ac97_init)
579 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg); 578 snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
580 res = 0xffff; 579 res = 0xffff;
581 } 580 }
582 } 581 }
@@ -607,16 +606,19 @@ static int snd_intel8x0_ali_codec_ready(intel8x0_t *chip, int mask)
607 if (val & mask) 606 if (val & mask)
608 return 0; 607 return 0;
609 } 608 }
610 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n"); 609 if (! chip->in_ac97_init)
610 snd_printd(KERN_WARNING "intel8x0: AC97 codec ready timeout.\n");
611 return -EBUSY; 611 return -EBUSY;
612} 612}
613 613
614static int snd_intel8x0_ali_codec_semaphore(intel8x0_t *chip) 614static int snd_intel8x0_ali_codec_semaphore(intel8x0_t *chip)
615{ 615{
616 int time = 100; 616 int time = 100;
617 if (chip->buggy_semaphore)
618 return 0; /* just ignore ... */
617 while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY)) 619 while (time-- && (igetdword(chip, ICHREG(ALI_CAS)) & ALI_CAS_SEM_BUSY))
618 udelay(1); 620 udelay(1);
619 if (! time) 621 if (! time && ! chip->in_ac97_init)
620 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n"); 622 snd_printk(KERN_WARNING "ali_codec_semaphore timeout\n");
621 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY); 623 return snd_intel8x0_ali_codec_ready(chip, ALI_CSPSR_CODEC_READY);
622} 624}
@@ -1716,6 +1718,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1716 .type = AC97_TUNE_HP_ONLY 1718 .type = AC97_TUNE_HP_ONLY
1717 }, 1719 },
1718 { 1720 {
1721 .subvendor = 0x1025,
1722 .subdevice = 0x0083,
1723 .name = "Acer Aspire 3003LCi",
1724 .type = AC97_TUNE_HP_ONLY
1725 },
1726 {
1719 .subvendor = 0x1028, 1727 .subvendor = 0x1028,
1720 .subdevice = 0x00d8, 1728 .subdevice = 0x00d8,
1721 .name = "Dell Precision 530", /* AD1885 */ 1729 .name = "Dell Precision 530", /* AD1885 */
@@ -1758,6 +1766,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
1758 .type = AC97_TUNE_HP_ONLY 1766 .type = AC97_TUNE_HP_ONLY
1759 }, 1767 },
1760 { 1768 {
1769 .subvendor = 0x1028,
1770 .subdevice = 0x0191,
1771 .name = "Dell Inspiron 8600",
1772 .type = AC97_TUNE_HP_ONLY
1773 },
1774 {
1761 .subvendor = 0x103c, 1775 .subvendor = 0x103c,
1762 .subdevice = 0x006d, 1776 .subdevice = 0x006d,
1763 .name = "HP zv5000", 1777 .name = "HP zv5000",
@@ -2022,7 +2036,6 @@ static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock, const
2022 if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0) 2036 if ((err = snd_ac97_bus(chip->card, 0, ops, chip, &pbus)) < 0)
2023 goto __err; 2037 goto __err;
2024 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus; 2038 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
2025 pbus->shared_type = AC97_SHARED_TYPE_ICH; /* shared with modem driver */
2026 if (ac97_clock >= 8000 && ac97_clock <= 48000) 2039 if (ac97_clock >= 8000 && ac97_clock <= 48000)
2027 pbus->clock = ac97_clock; 2040 pbus->clock = ac97_clock;
2028 /* FIXME: my test board doesn't work well with VRA... */ 2041 /* FIXME: my test board doesn't work well with VRA... */
@@ -2131,14 +2144,13 @@ static void do_ali_reset(intel8x0_t *chip)
2131 iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383); 2144 iputdword(chip, ICHREG(ALI_FIFOCR2), 0x83838383);
2132 iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383); 2145 iputdword(chip, ICHREG(ALI_FIFOCR3), 0x83838383);
2133 iputdword(chip, ICHREG(ALI_INTERFACECR), 2146 iputdword(chip, ICHREG(ALI_INTERFACECR),
2134 ICH_ALI_IF_MC|ICH_ALI_IF_PI|ICH_ALI_IF_PO); 2147 ICH_ALI_IF_PI|ICH_ALI_IF_PO);
2135 iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000); 2148 iputdword(chip, ICHREG(ALI_INTERRUPTCR), 0x00000000);
2136 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000); 2149 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
2137} 2150}
2138 2151
2139#define do_delay(chip) do {\ 2152#define do_delay(chip) do {\
2140 set_current_state(TASK_UNINTERRUPTIBLE);\ 2153 schedule_timeout_uninterruptible(1);\
2141 schedule_timeout(1);\
2142} while (0) 2154} while (0)
2143 2155
2144static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing) 2156static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
@@ -2166,7 +2178,7 @@ static int snd_intel8x0_ich_chip_init(intel8x0_t *chip, int probing)
2166 goto __ok; 2178 goto __ok;
2167 do_delay(chip); 2179 do_delay(chip);
2168 } while (time_after_eq(end_time, jiffies)); 2180 } while (time_after_eq(end_time, jiffies));
2169 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT))); 2181 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
2170 return -EIO; 2182 return -EIO;
2171 2183
2172 __ok: 2184 __ok:
@@ -2441,7 +2453,7 @@ static void __devinit intel8x0_measure_ac97_clock(intel8x0_t *chip)
2441 2453
2442 subs = chip->pcm[0]->streams[0].substream; 2454 subs = chip->pcm[0]->streams[0].substream;
2443 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) { 2455 if (! subs || subs->dma_buffer.bytes < INTEL8X0_TESTBUF_SIZE) {
2444 snd_printk("no playback buffer allocated - aborting measure ac97 clock\n"); 2456 snd_printk(KERN_WARNING "no playback buffer allocated - aborting measure ac97 clock\n");
2445 return; 2457 return;
2446 } 2458 }
2447 ichdev = &chip->ichd[ICHD_PCMOUT]; 2459 ichdev = &chip->ichd[ICHD_PCMOUT];
@@ -2477,7 +2489,7 @@ static void __devinit intel8x0_measure_ac97_clock(intel8x0_t *chip)
2477 do_gettimeofday(&stop_time); 2489 do_gettimeofday(&stop_time);
2478 /* stop */ 2490 /* stop */
2479 if (chip->device_type == DEVICE_ALI) { 2491 if (chip->device_type == DEVICE_ALI) {
2480 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 8)); 2492 iputdword(chip, ICHREG(ALI_DMACR), 1 << (ichdev->ali_slot + 16));
2481 iputbyte(chip, port + ICH_REG_OFF_CR, 0); 2493 iputbyte(chip, port + ICH_REG_OFF_CR, 0);
2482 while (igetbyte(chip, port + ICH_REG_OFF_CR)) 2494 while (igetbyte(chip, port + ICH_REG_OFF_CR))
2483 ; 2495 ;
@@ -2556,7 +2568,6 @@ struct ich_reg_info {
2556static int __devinit snd_intel8x0_create(snd_card_t * card, 2568static int __devinit snd_intel8x0_create(snd_card_t * card,
2557 struct pci_dev *pci, 2569 struct pci_dev *pci,
2558 unsigned long device_type, 2570 unsigned long device_type,
2559 int buggy_sem,
2560 intel8x0_t ** r_intel8x0) 2571 intel8x0_t ** r_intel8x0)
2561{ 2572{
2562 intel8x0_t *chip; 2573 intel8x0_t *chip;
@@ -2614,18 +2625,17 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2614 chip->card = card; 2625 chip->card = card;
2615 chip->pci = pci; 2626 chip->pci = pci;
2616 chip->irq = -1; 2627 chip->irq = -1;
2617 chip->buggy_semaphore = buggy_sem; 2628
2629 /* module parameters */
2630 chip->buggy_irq = buggy_irq;
2631 chip->buggy_semaphore = buggy_semaphore;
2632 if (xbox)
2633 chip->xbox = 1;
2618 2634
2619 if (pci->vendor == PCI_VENDOR_ID_INTEL && 2635 if (pci->vendor == PCI_VENDOR_ID_INTEL &&
2620 pci->device == PCI_DEVICE_ID_INTEL_440MX) 2636 pci->device == PCI_DEVICE_ID_INTEL_440MX)
2621 chip->fix_nocache = 1; /* enable workaround */ 2637 chip->fix_nocache = 1; /* enable workaround */
2622 2638
2623 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2624 * Needs to return IRQ_HANDLED for unknown irqs.
2625 */
2626 if (device_type == DEVICE_NFORCE)
2627 chip->buggy_irq = 1;
2628
2629 if ((err = pci_request_regions(pci, card->shortname)) < 0) { 2639 if ((err = pci_request_regions(pci, card->shortname)) < 0) {
2630 kfree(chip); 2640 kfree(chip);
2631 pci_disable_device(pci); 2641 pci_disable_device(pci);
@@ -2644,7 +2654,7 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2644 chip->remap_addr = ioremap_nocache(chip->addr, 2654 chip->remap_addr = ioremap_nocache(chip->addr,
2645 pci_resource_len(pci, 2)); 2655 pci_resource_len(pci, 2));
2646 if (chip->remap_addr == NULL) { 2656 if (chip->remap_addr == NULL) {
2647 snd_printk("AC'97 space ioremap problem\n"); 2657 snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
2648 snd_intel8x0_free(chip); 2658 snd_intel8x0_free(chip);
2649 return -EIO; 2659 return -EIO;
2650 } 2660 }
@@ -2657,7 +2667,7 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2657 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr, 2667 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
2658 pci_resource_len(pci, 3)); 2668 pci_resource_len(pci, 3));
2659 if (chip->remap_bmaddr == NULL) { 2669 if (chip->remap_bmaddr == NULL) {
2660 snd_printk("Controller space ioremap problem\n"); 2670 snd_printk(KERN_ERR "Controller space ioremap problem\n");
2661 snd_intel8x0_free(chip); 2671 snd_intel8x0_free(chip);
2662 return -EIO; 2672 return -EIO;
2663 } 2673 }
@@ -2666,15 +2676,6 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2666 } 2676 }
2667 2677
2668 port_inited: 2678 port_inited:
2669 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
2670 snd_printk("unable to grab IRQ %d\n", pci->irq);
2671 snd_intel8x0_free(chip);
2672 return -EBUSY;
2673 }
2674 chip->irq = pci->irq;
2675 pci_set_master(pci);
2676 synchronize_irq(chip->irq);
2677
2678 chip->bdbars_count = bdbars[device_type]; 2679 chip->bdbars_count = bdbars[device_type];
2679 2680
2680 /* initialize offsets */ 2681 /* initialize offsets */
@@ -2725,13 +2726,27 @@ static int __devinit snd_intel8x0_create(snd_card_t * card,
2725 int_sta_masks = 0; 2726 int_sta_masks = 0;
2726 for (i = 0; i < chip->bdbars_count; i++) { 2727 for (i = 0; i < chip->bdbars_count; i++) {
2727 ichdev = &chip->ichd[i]; 2728 ichdev = &chip->ichd[i];
2728 ichdev->bdbar = ((u32 *)chip->bdbars.area) + (i * ICH_MAX_FRAGS * 2); 2729 ichdev->bdbar = ((u32 *)chip->bdbars.area) +
2729 ichdev->bdbar_addr = chip->bdbars.addr + (i * sizeof(u32) * ICH_MAX_FRAGS * 2); 2730 (i * ICH_MAX_FRAGS * 2);
2731 ichdev->bdbar_addr = chip->bdbars.addr +
2732 (i * sizeof(u32) * ICH_MAX_FRAGS * 2);
2730 int_sta_masks |= ichdev->int_sta_mask; 2733 int_sta_masks |= ichdev->int_sta_mask;
2731 } 2734 }
2732 chip->int_sta_reg = device_type == DEVICE_ALI ? ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA; 2735 chip->int_sta_reg = device_type == DEVICE_ALI ?
2736 ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
2733 chip->int_sta_mask = int_sta_masks; 2737 chip->int_sta_mask = int_sta_masks;
2734 2738
2739 /* request irq after initializaing int_sta_mask, etc */
2740 if (request_irq(pci->irq, snd_intel8x0_interrupt,
2741 SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
2742 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2743 snd_intel8x0_free(chip);
2744 return -EBUSY;
2745 }
2746 chip->irq = pci->irq;
2747 pci_set_master(pci);
2748 synchronize_irq(chip->irq);
2749
2735 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) { 2750 if ((err = snd_intel8x0_chip_init(chip, 1)) < 0) {
2736 snd_intel8x0_free(chip); 2751 snd_intel8x0_free(chip);
2737 return err; 2752 return err;
@@ -2782,20 +2797,12 @@ static struct shortname_table {
2782static int __devinit snd_intel8x0_probe(struct pci_dev *pci, 2797static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2783 const struct pci_device_id *pci_id) 2798 const struct pci_device_id *pci_id)
2784{ 2799{
2785 static int dev;
2786 snd_card_t *card; 2800 snd_card_t *card;
2787 intel8x0_t *chip; 2801 intel8x0_t *chip;
2788 int err; 2802 int err;
2789 struct shortname_table *name; 2803 struct shortname_table *name;
2790 2804
2791 if (dev >= SNDRV_CARDS) 2805 card = snd_card_new(index, id, THIS_MODULE, 0);
2792 return -ENODEV;
2793 if (!enable[dev]) {
2794 dev++;
2795 return -ENOENT;
2796 }
2797
2798 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2799 if (card == NULL) 2806 if (card == NULL)
2800 return -ENOMEM; 2807 return -ENOMEM;
2801 2808
@@ -2819,17 +2826,23 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2819 } 2826 }
2820 } 2827 }
2821 2828
2829 if (buggy_irq < 0) {
2830 /* some Nforce[2] and ICH boards have problems with IRQ handling.
2831 * Needs to return IRQ_HANDLED for unknown irqs.
2832 */
2833 if (pci_id->driver_data == DEVICE_NFORCE)
2834 buggy_irq = 1;
2835 else
2836 buggy_irq = 0;
2837 }
2838
2822 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, 2839 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data,
2823 buggy_semaphore[dev], &chip)) < 0) { 2840 &chip)) < 0) {
2824 snd_card_free(card); 2841 snd_card_free(card);
2825 return err; 2842 return err;
2826 } 2843 }
2827 if (buggy_irq[dev])
2828 chip->buggy_irq = 1;
2829 if (xbox[dev])
2830 chip->xbox = 1;
2831 2844
2832 if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev], ac97_quirk[dev])) < 0) { 2845 if ((err = snd_intel8x0_mixer(chip, ac97_clock, ac97_quirk)) < 0) {
2833 snd_card_free(card); 2846 snd_card_free(card);
2834 return err; 2847 return err;
2835 } 2848 }
@@ -2844,7 +2857,7 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2844 "%s with %s at %#lx, irq %i", card->shortname, 2857 "%s with %s at %#lx, irq %i", card->shortname,
2845 snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq); 2858 snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq);
2846 2859
2847 if (! ac97_clock[dev]) 2860 if (! ac97_clock)
2848 intel8x0_measure_ac97_clock(chip); 2861 intel8x0_measure_ac97_clock(chip);
2849 2862
2850 if ((err = snd_card_register(card)) < 0) { 2863 if ((err = snd_card_register(card)) < 0) {
@@ -2852,7 +2865,6 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
2852 return err; 2865 return err;
2853 } 2866 }
2854 pci_set_drvdata(pci, card); 2867 pci_set_drvdata(pci, card);
2855 dev++;
2856 return 0; 2868 return 0;
2857} 2869}
2858 2870
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 9e2060d56c24..acfb197a833c 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz> 4 * Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
5 * 5 *
6 * This is modified (by Sasha Khapyorsky <sashak@smlink.com>) version 6 * This is modified (by Sasha Khapyorsky <sashak@alsa-project.org>) version
7 * of ALSA ICH sound driver intel8x0.c . 7 * of ALSA ICH sound driver intel8x0.c .
8 * 8 *
9 * 9 *
@@ -56,20 +56,21 @@ MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
56 "{NVidia,NForce3 Modem}," 56 "{NVidia,NForce3 Modem},"
57 "{AMD,AMD768}}"); 57 "{AMD,AMD768}}");
58 58
59static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */ 59static int index = -2; /* Exclude the first card */
60static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 60static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
61static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 61static int ac97_clock = 0;
62static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
63 62
64module_param_array(index, int, NULL, 0444); 63module_param(index, int, 0444);
65MODULE_PARM_DESC(index, "Index value for Intel i8x0 modemcard."); 64MODULE_PARM_DESC(index, "Index value for Intel i8x0 modemcard.");
66module_param_array(id, charp, NULL, 0444); 65module_param(id, charp, 0444);
67MODULE_PARM_DESC(id, "ID string for Intel i8x0 modemcard."); 66MODULE_PARM_DESC(id, "ID string for Intel i8x0 modemcard.");
68module_param_array(enable, bool, NULL, 0444); 67module_param(ac97_clock, int, 0444);
69MODULE_PARM_DESC(enable, "Enable Intel i8x0 modemcard.");
70module_param_array(ac97_clock, int, NULL, 0444);
71MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect)."); 68MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (0 = auto-detect).");
72 69
70/* just for backward compatibility */
71static int enable;
72module_param(enable, bool, 0444);
73
73/* 74/*
74 * Direct registers 75 * Direct registers
75 */ 76 */
@@ -362,7 +363,7 @@ static int snd_intel8x0m_codec_semaphore(intel8x0_t *chip, unsigned int codec)
362 /* access to some forbidden (non existant) ac97 registers will not 363 /* access to some forbidden (non existant) ac97 registers will not
363 * reset the semaphore. So even if you don't get the semaphore, still 364 * reset the semaphore. So even if you don't get the semaphore, still
364 * continue the access. We don't need the semaphore anyway. */ 365 * continue the access. We don't need the semaphore anyway. */
365 snd_printk("codec_semaphore: semaphore is not ready [0x%x][0x%x]\n", 366 snd_printk(KERN_ERR "codec_semaphore: semaphore is not ready [0x%x][0x%x]\n",
366 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA))); 367 igetbyte(chip, ICHREG(ACC_SEMA)), igetdword(chip, ICHREG(GLOB_STA)));
367 iagetword(chip, 0); /* clear semaphore flag */ 368 iagetword(chip, 0); /* clear semaphore flag */
368 /* I don't care about the semaphore */ 369 /* I don't care about the semaphore */
@@ -377,7 +378,7 @@ static void snd_intel8x0_codec_write(ac97_t *ac97,
377 378
378 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) { 379 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
379 if (! chip->in_ac97_init) 380 if (! chip->in_ac97_init)
380 snd_printk("codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 381 snd_printk(KERN_ERR "codec_write %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
381 } 382 }
382 iaputword(chip, reg + ac97->num * 0x80, val); 383 iaputword(chip, reg + ac97->num * 0x80, val);
383} 384}
@@ -391,7 +392,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
391 392
392 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) { 393 if (snd_intel8x0m_codec_semaphore(chip, ac97->num) < 0) {
393 if (! chip->in_ac97_init) 394 if (! chip->in_ac97_init)
394 snd_printk("codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg); 395 snd_printk(KERN_ERR "codec_read %d: semaphore is not ready for register 0x%x\n", ac97->num, reg);
395 res = 0xffff; 396 res = 0xffff;
396 } else { 397 } else {
397 res = iagetword(chip, reg + ac97->num * 0x80); 398 res = iagetword(chip, reg + ac97->num * 0x80);
@@ -399,7 +400,7 @@ static unsigned short snd_intel8x0_codec_read(ac97_t *ac97,
399 /* reset RCS and preserve other R/WC bits */ 400 /* reset RCS and preserve other R/WC bits */
400 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI)); 401 iputdword(chip, ICHREG(GLOB_STA), tmp & ~(ICH_SRI|ICH_PRI|ICH_TRI|ICH_GSCI));
401 if (! chip->in_ac97_init) 402 if (! chip->in_ac97_init)
402 snd_printk("codec_read %d: read timeout for register 0x%x\n", ac97->num, reg); 403 snd_printk(KERN_ERR "codec_read %d: read timeout for register 0x%x\n", ac97->num, reg);
403 res = 0xffff; 404 res = 0xffff;
404 } 405 }
405 } 406 }
@@ -746,6 +747,7 @@ static int __devinit snd_intel8x0_pcm1(intel8x0_t *chip, int device, struct ich_
746 747
747 pcm->private_data = chip; 748 pcm->private_data = chip;
748 pcm->info_flags = 0; 749 pcm->info_flags = 0;
750 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
749 if (rec->suffix) 751 if (rec->suffix)
750 sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix); 752 sprintf(pcm->name, "%s - %s", chip->card->shortname, rec->suffix);
751 else 753 else
@@ -854,7 +856,6 @@ static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock)
854 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0) 856 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
855 goto __err; 857 goto __err;
856 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus; 858 pbus->private_free = snd_intel8x0_mixer_free_ac97_bus;
857 pbus->shared_type = AC97_SHARED_TYPE_ICH; /* shared with audio driver */
858 if (ac97_clock >= 8000 && ac97_clock <= 48000) 859 if (ac97_clock >= 8000 && ac97_clock <= 48000)
859 pbus->clock = ac97_clock; 860 pbus->clock = ac97_clock;
860 chip->ac97_bus = pbus; 861 chip->ac97_bus = pbus;
@@ -889,8 +890,7 @@ static int __devinit snd_intel8x0_mixer(intel8x0_t *chip, int ac97_clock)
889 */ 890 */
890 891
891#define do_delay(chip) do {\ 892#define do_delay(chip) do {\
892 set_current_state(TASK_UNINTERRUPTIBLE);\ 893 schedule_timeout_uninterruptible(1);\
893 schedule_timeout(1);\
894} while (0) 894} while (0)
895 895
896static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing) 896static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing)
@@ -916,7 +916,7 @@ static int snd_intel8x0m_ich_chip_init(intel8x0_t *chip, int probing)
916 goto __ok; 916 goto __ok;
917 do_delay(chip); 917 do_delay(chip);
918 } while (time_after_eq(end_time, jiffies)); 918 } while (time_after_eq(end_time, jiffies));
919 snd_printk("AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT))); 919 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n", igetdword(chip, ICHREG(GLOB_CNT)));
920 return -EIO; 920 return -EIO;
921 921
922 __ok: 922 __ok:
@@ -1142,7 +1142,7 @@ static int __devinit snd_intel8x0m_create(snd_card_t * card,
1142 chip->remap_addr = ioremap_nocache(chip->addr, 1142 chip->remap_addr = ioremap_nocache(chip->addr,
1143 pci_resource_len(pci, 2)); 1143 pci_resource_len(pci, 2));
1144 if (chip->remap_addr == NULL) { 1144 if (chip->remap_addr == NULL) {
1145 snd_printk("AC'97 space ioremap problem\n"); 1145 snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
1146 snd_intel8x0_free(chip); 1146 snd_intel8x0_free(chip);
1147 return -EIO; 1147 return -EIO;
1148 } 1148 }
@@ -1155,7 +1155,7 @@ static int __devinit snd_intel8x0m_create(snd_card_t * card,
1155 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr, 1155 chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
1156 pci_resource_len(pci, 3)); 1156 pci_resource_len(pci, 3));
1157 if (chip->remap_bmaddr == NULL) { 1157 if (chip->remap_bmaddr == NULL) {
1158 snd_printk("Controller space ioremap problem\n"); 1158 snd_printk(KERN_ERR "Controller space ioremap problem\n");
1159 snd_intel8x0_free(chip); 1159 snd_intel8x0_free(chip);
1160 return -EIO; 1160 return -EIO;
1161 } 1161 }
@@ -1165,7 +1165,7 @@ static int __devinit snd_intel8x0m_create(snd_card_t * card,
1165 1165
1166 port_inited: 1166 port_inited:
1167 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) { 1167 if (request_irq(pci->irq, snd_intel8x0_interrupt, SA_INTERRUPT|SA_SHIRQ, card->shortname, (void *)chip)) {
1168 snd_printk("unable to grab IRQ %d\n", pci->irq); 1168 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1169 snd_intel8x0_free(chip); 1169 snd_intel8x0_free(chip);
1170 return -EBUSY; 1170 return -EBUSY;
1171 } 1171 }
@@ -1263,20 +1263,12 @@ static struct shortname_table {
1263static int __devinit snd_intel8x0m_probe(struct pci_dev *pci, 1263static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1264 const struct pci_device_id *pci_id) 1264 const struct pci_device_id *pci_id)
1265{ 1265{
1266 static int dev;
1267 snd_card_t *card; 1266 snd_card_t *card;
1268 intel8x0_t *chip; 1267 intel8x0_t *chip;
1269 int err; 1268 int err;
1270 struct shortname_table *name; 1269 struct shortname_table *name;
1271 1270
1272 if (dev >= SNDRV_CARDS) 1271 card = snd_card_new(index, id, THIS_MODULE, 0);
1273 return -ENODEV;
1274 if (!enable[dev]) {
1275 dev++;
1276 return -ENOENT;
1277 }
1278
1279 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1280 if (card == NULL) 1272 if (card == NULL)
1281 return -ENOMEM; 1273 return -ENOMEM;
1282 1274
@@ -1295,7 +1287,7 @@ static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1295 return err; 1287 return err;
1296 } 1288 }
1297 1289
1298 if ((err = snd_intel8x0_mixer(chip, ac97_clock[dev])) < 0) { 1290 if ((err = snd_intel8x0_mixer(chip, ac97_clock)) < 0) {
1299 snd_card_free(card); 1291 snd_card_free(card);
1300 return err; 1292 return err;
1301 } 1293 }
@@ -1314,7 +1306,6 @@ static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1314 return err; 1306 return err;
1315 } 1307 }
1316 pci_set_drvdata(pci, card); 1308 pci_set_drvdata(pci, card);
1317 dev++;
1318 return 0; 1309 return 0;
1319} 1310}
1320 1311
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 2693b6f731f3..99eb76c56f81 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -1492,7 +1492,7 @@ static int snd_m3_pcm_hw_params(snd_pcm_substream_t * substream,
1492 /* set buffer address */ 1492 /* set buffer address */
1493 s->buffer_addr = substream->runtime->dma_addr; 1493 s->buffer_addr = substream->runtime->dma_addr;
1494 if (s->buffer_addr & 0x3) { 1494 if (s->buffer_addr & 0x3) {
1495 snd_printk("oh my, not aligned\n"); 1495 snd_printk(KERN_ERR "oh my, not aligned\n");
1496 s->buffer_addr = s->buffer_addr & ~0x3; 1496 s->buffer_addr = s->buffer_addr & ~0x3;
1497 } 1497 }
1498 return 0; 1498 return 0;
@@ -1942,7 +1942,7 @@ static int snd_m3_ac97_wait(m3_t *chip)
1942 return 0; 1942 return 0;
1943 } while (i-- > 0); 1943 } while (i-- > 0);
1944 1944
1945 snd_printk("ac97 serial bus busy\n"); 1945 snd_printk(KERN_ERR "ac97 serial bus busy\n");
1946 return 1; 1946 return 1;
1947} 1947}
1948 1948
@@ -2046,8 +2046,7 @@ static void snd_m3_ac97_reset(m3_t *chip)
2046 outw(0, io + GPIO_DATA); 2046 outw(0, io + GPIO_DATA);
2047 outw(dir | GPO_PRIMARY_AC97, io + GPIO_DIRECTION); 2047 outw(dir | GPO_PRIMARY_AC97, io + GPIO_DIRECTION);
2048 2048
2049 set_current_state(TASK_UNINTERRUPTIBLE); 2049 schedule_timeout_uninterruptible(msecs_to_jiffies(delay1));
2050 schedule_timeout((delay1 * HZ) / 1000);
2051 2050
2052 outw(GPO_PRIMARY_AC97, io + GPIO_DATA); 2051 outw(GPO_PRIMARY_AC97, io + GPIO_DATA);
2053 udelay(5); 2052 udelay(5);
@@ -2055,8 +2054,7 @@ static void snd_m3_ac97_reset(m3_t *chip)
2055 outw(IO_SRAM_ENABLE | SERIAL_AC_LINK_ENABLE, io + RING_BUS_CTRL_A); 2054 outw(IO_SRAM_ENABLE | SERIAL_AC_LINK_ENABLE, io + RING_BUS_CTRL_A);
2056 outw(~0, io + GPIO_MASK); 2055 outw(~0, io + GPIO_MASK);
2057 2056
2058 set_current_state(TASK_UNINTERRUPTIBLE); 2057 schedule_timeout_uninterruptible(msecs_to_jiffies(delay2));
2059 schedule_timeout((delay2 * HZ) / 1000);
2060 2058
2061 if (! snd_m3_try_read_vendor(chip)) 2059 if (! snd_m3_try_read_vendor(chip))
2062 break; 2060 break;
@@ -2101,8 +2099,7 @@ static int __devinit snd_m3_mixer(m3_t *chip)
2101 2099
2102 /* seems ac97 PCM needs initialization.. hack hack.. */ 2100 /* seems ac97 PCM needs initialization.. hack hack.. */
2103 snd_ac97_write(chip->ac97, AC97_PCM, 0x8000 | (15 << 8) | 15); 2101 snd_ac97_write(chip->ac97, AC97_PCM, 0x8000 | (15 << 8) | 15);
2104 set_current_state(TASK_UNINTERRUPTIBLE); 2102 schedule_timeout_uninterruptible(msecs_to_jiffies(100));
2105 schedule_timeout(HZ / 10);
2106 snd_ac97_write(chip->ac97, AC97_PCM, 0); 2103 snd_ac97_write(chip->ac97, AC97_PCM, 0);
2107 2104
2108 memset(&id, 0, sizeof(id)); 2105 memset(&id, 0, sizeof(id));
@@ -2367,7 +2364,7 @@ static int __devinit snd_m3_assp_client_init(m3_t *chip, m3_dma_t *s, int index)
2367 address = 0x1100 + ((data_bytes/2) * index); 2364 address = 0x1100 + ((data_bytes/2) * index);
2368 2365
2369 if ((address + (data_bytes/2)) >= 0x1c00) { 2366 if ((address + (data_bytes/2)) >= 0x1c00) {
2370 snd_printk("no memory for %d bytes at ind %d (addr 0x%x)\n", 2367 snd_printk(KERN_ERR "no memory for %d bytes at ind %d (addr 0x%x)\n",
2371 data_bytes, index, address); 2368 data_bytes, index, address);
2372 return -ENOMEM; 2369 return -ENOMEM;
2373 } 2370 }
@@ -2476,6 +2473,7 @@ snd_m3_chip_init(m3_t *chip)
2476 t |= ASSP_0_WS_ENABLE; 2473 t |= ASSP_0_WS_ENABLE;
2477 outb(t, chip->iobase + ASSP_CONTROL_A); 2474 outb(t, chip->iobase + ASSP_CONTROL_A);
2478 2475
2476 snd_m3_assp_init(chip); /* download DSP code before starting ASSP below */
2479 outb(RUN_ASSP, chip->iobase + ASSP_CONTROL_B); 2477 outb(RUN_ASSP, chip->iobase + ASSP_CONTROL_B);
2480 2478
2481 outb(0x00, io + HARDWARE_VOL_CTRL); 2479 outb(0x00, io + HARDWARE_VOL_CTRL);
@@ -2655,7 +2653,7 @@ snd_m3_create(snd_card_t *card, struct pci_dev *pci,
2655 /* check, if we can restrict PCI DMA transfers to 28 bits */ 2653 /* check, if we can restrict PCI DMA transfers to 28 bits */
2656 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 || 2654 if (pci_set_dma_mask(pci, 0x0fffffff) < 0 ||
2657 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) { 2655 pci_set_consistent_dma_mask(pci, 0x0fffffff) < 0) {
2658 snd_printk("architecture does not support 28bit PCI busmaster DMA\n"); 2656 snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n");
2659 pci_disable_device(pci); 2657 pci_disable_device(pci);
2660 return -ENXIO; 2658 return -ENXIO;
2661 } 2659 }
@@ -2734,14 +2732,13 @@ snd_m3_create(snd_card_t *card, struct pci_dev *pci,
2734 2732
2735 snd_m3_ac97_reset(chip); 2733 snd_m3_ac97_reset(chip);
2736 2734
2737 snd_m3_assp_init(chip);
2738 snd_m3_amp_enable(chip, 1); 2735 snd_m3_amp_enable(chip, 1);
2739 2736
2740 tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip); 2737 tasklet_init(&chip->hwvol_tq, snd_m3_update_hw_volume, (unsigned long)chip);
2741 2738
2742 if (request_irq(pci->irq, snd_m3_interrupt, SA_INTERRUPT|SA_SHIRQ, 2739 if (request_irq(pci->irq, snd_m3_interrupt, SA_INTERRUPT|SA_SHIRQ,
2743 card->driver, (void *)chip)) { 2740 card->driver, (void *)chip)) {
2744 snd_printk("unable to grab IRQ %d\n", pci->irq); 2741 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2745 snd_m3_free(chip); 2742 snd_m3_free(chip);
2746 return -ENOMEM; 2743 return -ENOMEM;
2747 } 2744 }
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index 1a62c7f6c52b..c341c99ec783 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -451,8 +451,7 @@ static int mixart_sync_nonblock_events(mixart_mgr_t *mgr)
451 snd_printk(KERN_ERR "mixart: cannot process nonblock events!\n"); 451 snd_printk(KERN_ERR "mixart: cannot process nonblock events!\n");
452 return -EBUSY; 452 return -EBUSY;
453 } 453 }
454 set_current_state(TASK_UNINTERRUPTIBLE); 454 schedule_timeout_uninterruptible(1);
455 schedule_timeout(1);
456 } 455 }
457 return 0; 456 return 0;
458} 457}
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 5c55a3b1d121..e7aa15178453 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -52,37 +52,43 @@ MODULE_SUPPORTED_DEVICE("{{NeoMagic,NM256AV},"
52 * some compile conditions. 52 * some compile conditions.
53 */ 53 */
54 54
55static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 55static int index = SNDRV_DEFAULT_IDX1; /* Index */
56static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 56static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
57static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; 57static int playback_bufsize = 16;
58static int playback_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 16}; 58static int capture_bufsize = 16;
59static int capture_bufsize[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 16}; 59static int force_ac97; /* disabled as default */
60static int force_ac97[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled as default */ 60static int buffer_top; /* not specified */
61static int buffer_top[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* not specified */ 61static int use_cache; /* disabled */
62static int use_cache[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled */ 62static int vaio_hack; /* disabled */
63static int vaio_hack[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; /* disabled */ 63static int reset_workaround;
64static int reset_workaround[SNDRV_CARDS]; 64static int reset_workaround_2;
65 65
66module_param_array(index, int, NULL, 0444); 66module_param(index, int, 0444);
67MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard."); 67MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
68module_param_array(id, charp, NULL, 0444); 68module_param(id, charp, 0444);
69MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard."); 69MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
70module_param_array(enable, bool, NULL, 0444); 70module_param(playback_bufsize, int, 0444);
71MODULE_PARM_DESC(enable, "Enable this soundcard.");
72module_param_array(playback_bufsize, int, NULL, 0444);
73MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard."); 71MODULE_PARM_DESC(playback_bufsize, "DAC frame size in kB for " CARD_NAME " soundcard.");
74module_param_array(capture_bufsize, int, NULL, 0444); 72module_param(capture_bufsize, int, 0444);
75MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard."); 73MODULE_PARM_DESC(capture_bufsize, "ADC frame size in kB for " CARD_NAME " soundcard.");
76module_param_array(force_ac97, bool, NULL, 0444); 74module_param(force_ac97, bool, 0444);
77MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard."); 75MODULE_PARM_DESC(force_ac97, "Force to use AC97 codec for " CARD_NAME " soundcard.");
78module_param_array(buffer_top, int, NULL, 0444); 76module_param(buffer_top, int, 0444);
79MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard."); 77MODULE_PARM_DESC(buffer_top, "Set the top address of audio buffer for " CARD_NAME " soundcard.");
80module_param_array(use_cache, bool, NULL, 0444); 78module_param(use_cache, bool, 0444);
81MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access."); 79MODULE_PARM_DESC(use_cache, "Enable the cache for coefficient table access.");
82module_param_array(vaio_hack, bool, NULL, 0444); 80module_param(vaio_hack, bool, 0444);
83MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks."); 81MODULE_PARM_DESC(vaio_hack, "Enable workaround for Sony VAIO notebooks.");
84module_param_array(reset_workaround, bool, NULL, 0444); 82module_param(reset_workaround, bool, 0444);
85MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops."); 83MODULE_PARM_DESC(reset_workaround, "Enable AC97 RESET workaround for some laptops.");
84module_param(reset_workaround_2, bool, 0444);
85MODULE_PARM_DESC(reset_workaround_2, "Enable extended AC97 RESET workaround for some other laptops.");
86
87/* just for backward compatibility */
88static int enable;
89module_param(enable, bool, 0444);
90
91
86 92
87/* 93/*
88 * hw definitions 94 * hw definitions
@@ -226,6 +232,7 @@ struct snd_nm256 {
226 unsigned int coeffs_current: 1; /* coeff. table is loaded? */ 232 unsigned int coeffs_current: 1; /* coeff. table is loaded? */
227 unsigned int use_cache: 1; /* use one big coef. table */ 233 unsigned int use_cache: 1; /* use one big coef. table */
228 unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */ 234 unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */
235 unsigned int reset_workaround_2: 1; /* Extended workaround for some other laptops to avoid freeze */
229 236
230 int mixer_base; /* register offset of ac97 mixer */ 237 int mixer_base; /* register offset of ac97 mixer */
231 int mixer_status_offset; /* offset of mixer status reg. */ 238 int mixer_status_offset; /* offset of mixer status reg. */
@@ -313,9 +320,9 @@ static inline void
313snd_nm256_write_buffer(nm256_t *chip, void *src, int offset, int size) 320snd_nm256_write_buffer(nm256_t *chip, void *src, int offset, int size)
314{ 321{
315 offset -= chip->buffer_start; 322 offset -= chip->buffer_start;
316#ifdef SNDRV_CONFIG_DEBUG 323#ifdef CONFIG_SND_DEBUG
317 if (offset < 0 || offset >= chip->buffer_size) { 324 if (offset < 0 || offset >= chip->buffer_size) {
318 snd_printk("write_buffer invalid offset = %d size = %d\n", offset, size); 325 snd_printk(KERN_ERR "write_buffer invalid offset = %d size = %d\n", offset, size);
319 return; 326 return;
320 } 327 }
321#endif 328#endif
@@ -459,7 +466,7 @@ static int snd_nm256_acquire_irq(nm256_t *chip)
459 if (chip->irq < 0) { 466 if (chip->irq < 0) {
460 if (request_irq(chip->pci->irq, chip->interrupt, SA_INTERRUPT|SA_SHIRQ, 467 if (request_irq(chip->pci->irq, chip->interrupt, SA_INTERRUPT|SA_SHIRQ,
461 chip->card->driver, (void*)chip)) { 468 chip->card->driver, (void*)chip)) {
462 snd_printk("unable to grab IRQ %d\n", chip->pci->irq); 469 snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->pci->irq);
463 up(&chip->irq_mutex); 470 up(&chip->irq_mutex);
464 return -EBUSY; 471 return -EBUSY;
465 } 472 }
@@ -1199,8 +1206,11 @@ snd_nm256_ac97_reset(ac97_t *ac97)
1199 /* Dell latitude LS will lock up by this */ 1206 /* Dell latitude LS will lock up by this */
1200 snd_nm256_writeb(chip, 0x6cc, 0x87); 1207 snd_nm256_writeb(chip, 0x6cc, 0x87);
1201 } 1208 }
1202 snd_nm256_writeb(chip, 0x6cc, 0x80); 1209 if (! chip->reset_workaround_2) {
1203 snd_nm256_writeb(chip, 0x6cc, 0x0); 1210 /* Dell latitude CSx will lock up by this */
1211 snd_nm256_writeb(chip, 0x6cc, 0x80);
1212 snd_nm256_writeb(chip, 0x6cc, 0x0);
1213 }
1204} 1214}
1205 1215
1206/* create an ac97 mixer interface */ 1216/* create an ac97 mixer interface */
@@ -1263,7 +1273,7 @@ snd_nm256_peek_for_sig(nm256_t *chip)
1263 1273
1264 temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16); 1274 temp = ioremap_nocache(chip->buffer_addr + chip->buffer_end - 0x400, 16);
1265 if (temp == NULL) { 1275 if (temp == NULL) {
1266 snd_printk("Unable to scan for card signature in video RAM\n"); 1276 snd_printk(KERN_ERR "Unable to scan for card signature in video RAM\n");
1267 return -EBUSY; 1277 return -EBUSY;
1268 } 1278 }
1269 1279
@@ -1277,7 +1287,7 @@ snd_nm256_peek_for_sig(nm256_t *chip)
1277 if (pointer == 0xffffffff || 1287 if (pointer == 0xffffffff ||
1278 pointer < chip->buffer_size || 1288 pointer < chip->buffer_size ||
1279 pointer > chip->buffer_end) { 1289 pointer > chip->buffer_end) {
1280 snd_printk("invalid signature found: 0x%x\n", pointer); 1290 snd_printk(KERN_ERR "invalid signature found: 0x%x\n", pointer);
1281 iounmap(temp); 1291 iounmap(temp);
1282 return -ENODEV; 1292 return -ENODEV;
1283 } else { 1293 } else {
@@ -1347,14 +1357,8 @@ static int snd_nm256_free(nm256_t *chip)
1347 iounmap(chip->cport); 1357 iounmap(chip->cport);
1348 if (chip->buffer) 1358 if (chip->buffer)
1349 iounmap(chip->buffer); 1359 iounmap(chip->buffer);
1350 if (chip->res_cport) { 1360 release_and_free_resource(chip->res_cport);
1351 release_resource(chip->res_cport); 1361 release_and_free_resource(chip->res_buffer);
1352 kfree_nocheck(chip->res_cport);
1353 }
1354 if (chip->res_buffer) {
1355 release_resource(chip->res_buffer);
1356 kfree_nocheck(chip->res_buffer);
1357 }
1358 if (chip->irq >= 0) 1362 if (chip->irq >= 0)
1359 free_irq(chip->irq, (void*)chip); 1363 free_irq(chip->irq, (void*)chip);
1360 1364
@@ -1420,14 +1424,14 @@ snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
1420 chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE, 1424 chip->res_cport = request_mem_region(chip->cport_addr, NM_PORT2_SIZE,
1421 card->driver); 1425 card->driver);
1422 if (chip->res_cport == NULL) { 1426 if (chip->res_cport == NULL) {
1423 snd_printk("memory region 0x%lx (size 0x%x) busy\n", 1427 snd_printk(KERN_ERR "memory region 0x%lx (size 0x%x) busy\n",
1424 chip->cport_addr, NM_PORT2_SIZE); 1428 chip->cport_addr, NM_PORT2_SIZE);
1425 err = -EBUSY; 1429 err = -EBUSY;
1426 goto __error; 1430 goto __error;
1427 } 1431 }
1428 chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE); 1432 chip->cport = ioremap_nocache(chip->cport_addr, NM_PORT2_SIZE);
1429 if (chip->cport == NULL) { 1433 if (chip->cport == NULL) {
1430 snd_printk("unable to map control port %lx\n", chip->cport_addr); 1434 snd_printk(KERN_ERR "unable to map control port %lx\n", chip->cport_addr);
1431 err = -ENOMEM; 1435 err = -ENOMEM;
1432 goto __error; 1436 goto __error;
1433 } 1437 }
@@ -1485,7 +1489,7 @@ snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
1485 chip->buffer_size, 1489 chip->buffer_size,
1486 card->driver); 1490 card->driver);
1487 if (chip->res_buffer == NULL) { 1491 if (chip->res_buffer == NULL) {
1488 snd_printk("nm256: buffer 0x%lx (size 0x%x) busy\n", 1492 snd_printk(KERN_ERR "nm256: buffer 0x%lx (size 0x%x) busy\n",
1489 chip->buffer_addr, chip->buffer_size); 1493 chip->buffer_addr, chip->buffer_size);
1490 err = -EBUSY; 1494 err = -EBUSY;
1491 goto __error; 1495 goto __error;
@@ -1493,7 +1497,7 @@ snd_nm256_create(snd_card_t *card, struct pci_dev *pci,
1493 chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size); 1497 chip->buffer = ioremap_nocache(chip->buffer_addr, chip->buffer_size);
1494 if (chip->buffer == NULL) { 1498 if (chip->buffer == NULL) {
1495 err = -ENOMEM; 1499 err = -ENOMEM;
1496 snd_printk("unable to map ring buffer at %lx\n", chip->buffer_addr); 1500 snd_printk(KERN_ERR "unable to map ring buffer at %lx\n", chip->buffer_addr);
1497 goto __error; 1501 goto __error;
1498 } 1502 }
1499 1503
@@ -1542,7 +1546,7 @@ struct nm256_quirk {
1542 int type; 1546 int type;
1543}; 1547};
1544 1548
1545enum { NM_BLACKLISTED, NM_RESET_WORKAROUND }; 1549enum { NM_BLACKLISTED, NM_RESET_WORKAROUND, NM_RESET_WORKAROUND_2 };
1546 1550
1547static struct nm256_quirk nm256_quirks[] __devinitdata = { 1551static struct nm256_quirk nm256_quirks[] __devinitdata = {
1548 /* HP omnibook 4150 has cs4232 codec internally */ 1552 /* HP omnibook 4150 has cs4232 codec internally */
@@ -1551,6 +1555,8 @@ static struct nm256_quirk nm256_quirks[] __devinitdata = {
1551 { .vendor = 0x104d, .device = 0x8041, .type = NM_RESET_WORKAROUND }, 1555 { .vendor = 0x104d, .device = 0x8041, .type = NM_RESET_WORKAROUND },
1552 /* Dell Latitude LS */ 1556 /* Dell Latitude LS */
1553 { .vendor = 0x1028, .device = 0x0080, .type = NM_RESET_WORKAROUND }, 1557 { .vendor = 0x1028, .device = 0x0080, .type = NM_RESET_WORKAROUND },
1558 /* Dell Latitude CSx */
1559 { .vendor = 0x1028, .device = 0x0091, .type = NM_RESET_WORKAROUND_2 },
1554 { } /* terminator */ 1560 { } /* terminator */
1555}; 1561};
1556 1562
@@ -1558,7 +1564,6 @@ static struct nm256_quirk nm256_quirks[] __devinitdata = {
1558static int __devinit snd_nm256_probe(struct pci_dev *pci, 1564static int __devinit snd_nm256_probe(struct pci_dev *pci,
1559 const struct pci_device_id *pci_id) 1565 const struct pci_device_id *pci_id)
1560{ 1566{
1561 static int dev;
1562 snd_card_t *card; 1567 snd_card_t *card;
1563 nm256_t *chip; 1568 nm256_t *chip;
1564 int err; 1569 int err;
@@ -1566,13 +1571,6 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1566 struct nm256_quirk *q; 1571 struct nm256_quirk *q;
1567 u16 subsystem_vendor, subsystem_device; 1572 u16 subsystem_vendor, subsystem_device;
1568 1573
1569 if (dev >= SNDRV_CARDS)
1570 return -ENODEV;
1571 if (!enable[dev]) {
1572 dev++;
1573 return -ENOENT;
1574 }
1575
1576 pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor); 1574 pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
1577 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device); 1575 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
1578 1576
@@ -1582,14 +1580,17 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1582 case NM_BLACKLISTED: 1580 case NM_BLACKLISTED:
1583 printk(KERN_INFO "nm256: The device is blacklisted. Loading stopped\n"); 1581 printk(KERN_INFO "nm256: The device is blacklisted. Loading stopped\n");
1584 return -ENODEV; 1582 return -ENODEV;
1583 case NM_RESET_WORKAROUND_2:
1584 reset_workaround_2 = 1;
1585 /* Fall-through */
1585 case NM_RESET_WORKAROUND: 1586 case NM_RESET_WORKAROUND:
1586 reset_workaround[dev] = 1; 1587 reset_workaround = 1;
1587 break; 1588 break;
1588 } 1589 }
1589 } 1590 }
1590 } 1591 }
1591 1592
1592 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1593 card = snd_card_new(index, id, THIS_MODULE, 0);
1593 if (card == NULL) 1594 if (card == NULL)
1594 return -ENOMEM; 1595 return -ENOMEM;
1595 1596
@@ -1604,40 +1605,45 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1604 strcpy(card->driver, "NM256XL+"); 1605 strcpy(card->driver, "NM256XL+");
1605 break; 1606 break;
1606 default: 1607 default:
1607 snd_printk("invalid device id 0x%x\n", pci->device); 1608 snd_printk(KERN_ERR "invalid device id 0x%x\n", pci->device);
1608 snd_card_free(card); 1609 snd_card_free(card);
1609 return -EINVAL; 1610 return -EINVAL;
1610 } 1611 }
1611 1612
1612 if (vaio_hack[dev]) 1613 if (vaio_hack)
1613 xbuffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */ 1614 xbuffer_top = 0x25a800; /* this avoids conflicts with XFree86 server */
1614 else 1615 else
1615 xbuffer_top = buffer_top[dev]; 1616 xbuffer_top = buffer_top;
1616 1617
1617 if (playback_bufsize[dev] < 4) 1618 if (playback_bufsize < 4)
1618 playback_bufsize[dev] = 4; 1619 playback_bufsize = 4;
1619 if (playback_bufsize[dev] > 128) 1620 if (playback_bufsize > 128)
1620 playback_bufsize[dev] = 128; 1621 playback_bufsize = 128;
1621 if (capture_bufsize[dev] < 4) 1622 if (capture_bufsize < 4)
1622 capture_bufsize[dev] = 4; 1623 capture_bufsize = 4;
1623 if (capture_bufsize[dev] > 128) 1624 if (capture_bufsize > 128)
1624 capture_bufsize[dev] = 128; 1625 capture_bufsize = 128;
1625 if ((err = snd_nm256_create(card, pci, 1626 if ((err = snd_nm256_create(card, pci,
1626 playback_bufsize[dev] * 1024, /* in bytes */ 1627 playback_bufsize * 1024, /* in bytes */
1627 capture_bufsize[dev] * 1024, /* in bytes */ 1628 capture_bufsize * 1024, /* in bytes */
1628 force_ac97[dev], 1629 force_ac97,
1629 xbuffer_top, 1630 xbuffer_top,
1630 use_cache[dev], 1631 use_cache,
1631 &chip)) < 0) { 1632 &chip)) < 0) {
1632 snd_card_free(card); 1633 snd_card_free(card);
1633 return err; 1634 return err;
1634 } 1635 }
1635 1636
1636 if (reset_workaround[dev]) { 1637 if (reset_workaround) {
1637 snd_printdd(KERN_INFO "nm256: reset_workaround activated\n"); 1638 snd_printdd(KERN_INFO "nm256: reset_workaround activated\n");
1638 chip->reset_workaround = 1; 1639 chip->reset_workaround = 1;
1639 } 1640 }
1640 1641
1642 if (reset_workaround_2) {
1643 snd_printdd(KERN_INFO "nm256: reset_workaround_2 activated\n");
1644 chip->reset_workaround_2 = 1;
1645 }
1646
1641 if ((err = snd_nm256_pcm(chip, 0)) < 0 || 1647 if ((err = snd_nm256_pcm(chip, 0)) < 0 ||
1642 (err = snd_nm256_mixer(chip)) < 0) { 1648 (err = snd_nm256_mixer(chip)) < 0) {
1643 snd_card_free(card); 1649 snd_card_free(card);
@@ -1655,7 +1661,6 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1655 } 1661 }
1656 1662
1657 pci_set_drvdata(pci, card); 1663 pci_set_drvdata(pci, card);
1658 dev++;
1659 return 0; 1664 return 0;
1660} 1665}
1661 1666
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index cd313af6ebcf..e6627b0e38e4 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1369,13 +1369,13 @@ static int __devinit snd_rme32_create(rme32_t * rme32)
1369 rme32->port = pci_resource_start(rme32->pci, 0); 1369 rme32->port = pci_resource_start(rme32->pci, 0);
1370 1370
1371 if (request_irq(pci->irq, snd_rme32_interrupt, SA_INTERRUPT | SA_SHIRQ, "RME32", (void *) rme32)) { 1371 if (request_irq(pci->irq, snd_rme32_interrupt, SA_INTERRUPT | SA_SHIRQ, "RME32", (void *) rme32)) {
1372 snd_printk("unable to grab IRQ %d\n", pci->irq); 1372 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1373 return -EBUSY; 1373 return -EBUSY;
1374 } 1374 }
1375 rme32->irq = pci->irq; 1375 rme32->irq = pci->irq;
1376 1376
1377 if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) { 1377 if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) {
1378 snd_printk("unable to remap memory region 0x%lx-0x%lx\n", 1378 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n",
1379 rme32->port, rme32->port + RME32_IO_SIZE - 1); 1379 rme32->port, rme32->port + RME32_IO_SIZE - 1);
1380 return -ENOMEM; 1380 return -ENOMEM;
1381 } 1381 }
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index c495cae78dbf..0eddeb16a10f 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -1570,13 +1570,13 @@ snd_rme96_create(rme96_t *rme96)
1570 rme96->port = pci_resource_start(rme96->pci, 0); 1570 rme96->port = pci_resource_start(rme96->pci, 0);
1571 1571
1572 if (request_irq(pci->irq, snd_rme96_interrupt, SA_INTERRUPT|SA_SHIRQ, "RME96", (void *)rme96)) { 1572 if (request_irq(pci->irq, snd_rme96_interrupt, SA_INTERRUPT|SA_SHIRQ, "RME96", (void *)rme96)) {
1573 snd_printk("unable to grab IRQ %d\n", pci->irq); 1573 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1574 return -EBUSY; 1574 return -EBUSY;
1575 } 1575 }
1576 rme96->irq = pci->irq; 1576 rme96->irq = pci->irq;
1577 1577
1578 if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) { 1578 if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) {
1579 snd_printk("unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); 1579 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1);
1580 return -ENOMEM; 1580 return -ENOMEM;
1581 } 1581 }
1582 1582
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 52525eb198c7..845158b01b02 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -671,11 +671,7 @@ static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
671 } 671 }
672 } 672 }
673 673
674 if ((1000 / HZ) < 3000) { 674 ssleep(3);
675 ssleep(3);
676 } else {
677 mdelay(3000);
678 }
679 675
680 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 676 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
681 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n"); 677 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
@@ -692,7 +688,7 @@ static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
692 688
693 } 689 }
694 if (hdsp->state & HDSP_InitializationComplete) { 690 if (hdsp->state & HDSP_InitializationComplete) {
695 snd_printk("Hammerfall-DSP: firmware loaded from cache, restoring defaults\n"); 691 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
696 spin_lock_irqsave(&hdsp->lock, flags); 692 spin_lock_irqsave(&hdsp->lock, flags);
697 snd_hdsp_set_defaults(hdsp); 693 snd_hdsp_set_defaults(hdsp);
698 spin_unlock_irqrestore(&hdsp->lock, flags); 694 spin_unlock_irqrestore(&hdsp->lock, flags);
@@ -709,9 +705,8 @@ static int hdsp_get_iobox_version (hdsp_t *hdsp)
709 705
710 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM); 706 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
711 hdsp_write (hdsp, HDSP_fifoData, 0); 707 hdsp_write (hdsp, HDSP_fifoData, 0);
712 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) { 708 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
713 return -EIO; 709 return -EIO;
714 }
715 710
716 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 711 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
717 hdsp_write (hdsp, HDSP_fifoData, 0); 712 hdsp_write (hdsp, HDSP_fifoData, 0);
@@ -726,22 +721,30 @@ static int hdsp_get_iobox_version (hdsp_t *hdsp)
726 } 721 }
727 } else { 722 } else {
728 /* firmware was already loaded, get iobox type */ 723 /* firmware was already loaded, get iobox type */
729 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) { 724 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
730 hdsp->io_type = Multiface; 725 hdsp->io_type = Multiface;
731 } else { 726 else
732 hdsp->io_type = Digiface; 727 hdsp->io_type = Digiface;
733 }
734 } 728 }
735 return 0; 729 return 0;
736} 730}
737 731
738 732
739static int hdsp_check_for_firmware (hdsp_t *hdsp) 733static int hdsp_check_for_firmware (hdsp_t *hdsp, int show_err)
740{ 734{
741 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; 735 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
742 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 736 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
743 snd_printk("Hammerfall-DSP: firmware not present.\n"); 737 snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n");
744 hdsp->state &= ~HDSP_FirmwareLoaded; 738 hdsp->state &= ~HDSP_FirmwareLoaded;
739 if (! show_err)
740 return -EIO;
741 /* try to load firmware */
742 if (hdsp->state & HDSP_FirmwareCached) {
743 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0)
744 snd_printk(KERN_ERR "Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
745 } else {
746 snd_printk(KERN_ERR "Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
747 }
745 return -EIO; 748 return -EIO;
746 } 749 }
747 return 0; 750 return 0;
@@ -775,9 +778,9 @@ static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
775 778
776static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr) 779static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
777{ 780{
778 if (addr >= HDSP_MATRIX_MIXER_SIZE) { 781 if (addr >= HDSP_MATRIX_MIXER_SIZE)
779 return 0; 782 return 0;
780 } 783
781 return hdsp->mixer_matrix[addr]; 784 return hdsp->mixer_matrix[addr];
782} 785}
783 786
@@ -802,13 +805,11 @@ static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
802 memory." 805 memory."
803 */ 806 */
804 807
805 if (hdsp->io_type == H9632 && addr >= 512) { 808 if (hdsp->io_type == H9632 && addr >= 512)
806 return 0; 809 return 0;
807 }
808 810
809 if (hdsp->io_type == H9652 && addr >= 1352) { 811 if (hdsp->io_type == H9652 && addr >= 1352)
810 return 0; 812 return 0;
811 }
812 813
813 hdsp->mixer_matrix[addr] = data; 814 hdsp->mixer_matrix[addr] = data;
814 815
@@ -832,9 +833,8 @@ static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
832 833
833 ad = (addr << 16) + data; 834 ad = (addr << 16) + data;
834 835
835 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) { 836 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
836 return -1; 837 return -1;
837 }
838 838
839 hdsp_write (hdsp, HDSP_fifoData, ad); 839 hdsp_write (hdsp, HDSP_fifoData, ad);
840 hdsp->mixer_matrix[addr] = data; 840 hdsp->mixer_matrix[addr] = data;
@@ -851,9 +851,8 @@ static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
851 851
852 spin_lock_irqsave(&hdsp->lock, flags); 852 spin_lock_irqsave(&hdsp->lock, flags);
853 if ((hdsp->playback_pid != hdsp->capture_pid) && 853 if ((hdsp->playback_pid != hdsp->capture_pid) &&
854 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) { 854 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
855 ret = 0; 855 ret = 0;
856 }
857 spin_unlock_irqrestore(&hdsp->lock, flags); 856 spin_unlock_irqrestore(&hdsp->lock, flags);
858 return ret; 857 return ret;
859} 858}
@@ -880,9 +879,8 @@ static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
880 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister); 879 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
881 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask); 880 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
882 881
883 if (status & HDSP_SPDIFErrorFlag) { 882 if (status & HDSP_SPDIFErrorFlag)
884 return 0; 883 return 0;
885 }
886 884
887 switch (rate_bits) { 885 switch (rate_bits) {
888 case HDSP_spdifFrequency32KHz: return 32000; 886 case HDSP_spdifFrequency32KHz: return 32000;
@@ -918,9 +916,8 @@ static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
918 916
919 position = hdsp_read(hdsp, HDSP_statusRegister); 917 position = hdsp_read(hdsp, HDSP_statusRegister);
920 918
921 if (!hdsp->precise_ptr) { 919 if (!hdsp->precise_ptr)
922 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0; 920 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
923 }
924 921
925 position &= HDSP_BufferPositionMask; 922 position &= HDSP_BufferPositionMask;
926 position /= 4; 923 position /= 4;
@@ -989,19 +986,19 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
989 if (!(hdsp->control_register & HDSP_ClockModeMaster)) { 986 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
990 if (called_internally) { 987 if (called_internally) {
991 /* request from ctl or card initialization */ 988 /* request from ctl or card initialization */
992 snd_printk("Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n"); 989 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
993 return -1; 990 return -1;
994 } else { 991 } else {
995 /* hw_param request while in AutoSync mode */ 992 /* hw_param request while in AutoSync mode */
996 int external_freq = hdsp_external_sample_rate(hdsp); 993 int external_freq = hdsp_external_sample_rate(hdsp);
997 int spdif_freq = hdsp_spdif_sample_rate(hdsp); 994 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
998 995
999 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) { 996 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1000 snd_printk("Hammerfall-DSP: Detected ADAT in double speed mode\n"); 997 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
1001 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) { 998 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1002 snd_printk("Hammerfall-DSP: Detected ADAT in quad speed mode\n"); 999 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1003 } else if (rate != external_freq) { 1000 else if (rate != external_freq) {
1004 snd_printk("Hammerfall-DSP: No AutoSync source for requested rate\n"); 1001 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
1005 return -1; 1002 return -1;
1006 } 1003 }
1007 } 1004 }
@@ -1019,63 +1016,53 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1019 exists for externally-driven rate changes. All we can do 1016 exists for externally-driven rate changes. All we can do
1020 is to flag rate changes in the read/write routines. */ 1017 is to flag rate changes in the read/write routines. */
1021 1018
1022 if (rate > 96000 && hdsp->io_type != H9632) { 1019 if (rate > 96000 && hdsp->io_type != H9632)
1023 return -EINVAL; 1020 return -EINVAL;
1024 }
1025 1021
1026 switch (rate) { 1022 switch (rate) {
1027 case 32000: 1023 case 32000:
1028 if (current_rate > 48000) { 1024 if (current_rate > 48000)
1029 reject_if_open = 1; 1025 reject_if_open = 1;
1030 }
1031 rate_bits = HDSP_Frequency32KHz; 1026 rate_bits = HDSP_Frequency32KHz;
1032 break; 1027 break;
1033 case 44100: 1028 case 44100:
1034 if (current_rate > 48000) { 1029 if (current_rate > 48000)
1035 reject_if_open = 1; 1030 reject_if_open = 1;
1036 }
1037 rate_bits = HDSP_Frequency44_1KHz; 1031 rate_bits = HDSP_Frequency44_1KHz;
1038 break; 1032 break;
1039 case 48000: 1033 case 48000:
1040 if (current_rate > 48000) { 1034 if (current_rate > 48000)
1041 reject_if_open = 1; 1035 reject_if_open = 1;
1042 }
1043 rate_bits = HDSP_Frequency48KHz; 1036 rate_bits = HDSP_Frequency48KHz;
1044 break; 1037 break;
1045 case 64000: 1038 case 64000:
1046 if (current_rate <= 48000 || current_rate > 96000) { 1039 if (current_rate <= 48000 || current_rate > 96000)
1047 reject_if_open = 1; 1040 reject_if_open = 1;
1048 }
1049 rate_bits = HDSP_Frequency64KHz; 1041 rate_bits = HDSP_Frequency64KHz;
1050 break; 1042 break;
1051 case 88200: 1043 case 88200:
1052 if (current_rate <= 48000 || current_rate > 96000) { 1044 if (current_rate <= 48000 || current_rate > 96000)
1053 reject_if_open = 1; 1045 reject_if_open = 1;
1054 }
1055 rate_bits = HDSP_Frequency88_2KHz; 1046 rate_bits = HDSP_Frequency88_2KHz;
1056 break; 1047 break;
1057 case 96000: 1048 case 96000:
1058 if (current_rate <= 48000 || current_rate > 96000) { 1049 if (current_rate <= 48000 || current_rate > 96000)
1059 reject_if_open = 1; 1050 reject_if_open = 1;
1060 }
1061 rate_bits = HDSP_Frequency96KHz; 1051 rate_bits = HDSP_Frequency96KHz;
1062 break; 1052 break;
1063 case 128000: 1053 case 128000:
1064 if (current_rate < 128000) { 1054 if (current_rate < 128000)
1065 reject_if_open = 1; 1055 reject_if_open = 1;
1066 }
1067 rate_bits = HDSP_Frequency128KHz; 1056 rate_bits = HDSP_Frequency128KHz;
1068 break; 1057 break;
1069 case 176400: 1058 case 176400:
1070 if (current_rate < 128000) { 1059 if (current_rate < 128000)
1071 reject_if_open = 1; 1060 reject_if_open = 1;
1072 }
1073 rate_bits = HDSP_Frequency176_4KHz; 1061 rate_bits = HDSP_Frequency176_4KHz;
1074 break; 1062 break;
1075 case 192000: 1063 case 192000:
1076 if (current_rate < 128000) { 1064 if (current_rate < 128000)
1077 reject_if_open = 1; 1065 reject_if_open = 1;
1078 }
1079 rate_bits = HDSP_Frequency192KHz; 1066 rate_bits = HDSP_Frequency192KHz;
1080 break; 1067 break;
1081 default: 1068 default:
@@ -1096,11 +1083,10 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1096 if (rate >= 128000) { 1083 if (rate >= 128000) {
1097 hdsp->channel_map = channel_map_H9632_qs; 1084 hdsp->channel_map = channel_map_H9632_qs;
1098 } else if (rate > 48000) { 1085 } else if (rate > 48000) {
1099 if (hdsp->io_type == H9632) { 1086 if (hdsp->io_type == H9632)
1100 hdsp->channel_map = channel_map_H9632_ds; 1087 hdsp->channel_map = channel_map_H9632_ds;
1101 } else { 1088 else
1102 hdsp->channel_map = channel_map_ds; 1089 hdsp->channel_map = channel_map_ds;
1103 }
1104 } else { 1090 } else {
1105 switch (hdsp->io_type) { 1091 switch (hdsp->io_type) {
1106 case Multiface: 1092 case Multiface:
@@ -1131,54 +1117,48 @@ static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
1131static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id) 1117static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1132{ 1118{
1133 /* the hardware already does the relevant bit-mask with 0xff */ 1119 /* the hardware already does the relevant bit-mask with 0xff */
1134 if (id) { 1120 if (id)
1135 return hdsp_read(hdsp, HDSP_midiDataIn1); 1121 return hdsp_read(hdsp, HDSP_midiDataIn1);
1136 } else { 1122 else
1137 return hdsp_read(hdsp, HDSP_midiDataIn0); 1123 return hdsp_read(hdsp, HDSP_midiDataIn0);
1138 }
1139} 1124}
1140 1125
1141static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val) 1126static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1142{ 1127{
1143 /* the hardware already does the relevant bit-mask with 0xff */ 1128 /* the hardware already does the relevant bit-mask with 0xff */
1144 if (id) { 1129 if (id)
1145 hdsp_write(hdsp, HDSP_midiDataOut1, val); 1130 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1146 } else { 1131 else
1147 hdsp_write(hdsp, HDSP_midiDataOut0, val); 1132 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1148 }
1149} 1133}
1150 1134
1151static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id) 1135static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1152{ 1136{
1153 if (id) { 1137 if (id)
1154 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff); 1138 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1155 } else { 1139 else
1156 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff); 1140 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1157 }
1158} 1141}
1159 1142
1160static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id) 1143static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1161{ 1144{
1162 int fifo_bytes_used; 1145 int fifo_bytes_used;
1163 1146
1164 if (id) { 1147 if (id)
1165 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff; 1148 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1166 } else { 1149 else
1167 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff; 1150 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1168 }
1169 1151
1170 if (fifo_bytes_used < 128) { 1152 if (fifo_bytes_used < 128)
1171 return 128 - fifo_bytes_used; 1153 return 128 - fifo_bytes_used;
1172 } else { 1154 else
1173 return 0; 1155 return 0;
1174 }
1175} 1156}
1176 1157
1177static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id) 1158static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1178{ 1159{
1179 while (snd_hdsp_midi_input_available (hdsp, id)) { 1160 while (snd_hdsp_midi_input_available (hdsp, id))
1180 snd_hdsp_midi_read_byte (hdsp, id); 1161 snd_hdsp_midi_read_byte (hdsp, id);
1181 }
1182} 1162}
1183 1163
1184static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi) 1164static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
@@ -1219,28 +1199,23 @@ static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1219 spin_lock_irqsave (&hmidi->lock, flags); 1199 spin_lock_irqsave (&hmidi->lock, flags);
1220 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) { 1200 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1221 if (hmidi->input) { 1201 if (hmidi->input) {
1222 if (n_pending > (int)sizeof (buf)) { 1202 if (n_pending > (int)sizeof (buf))
1223 n_pending = sizeof (buf); 1203 n_pending = sizeof (buf);
1224 } 1204 for (i = 0; i < n_pending; ++i)
1225 for (i = 0; i < n_pending; ++i) {
1226 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); 1205 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1227 } 1206 if (n_pending)
1228 if (n_pending) {
1229 snd_rawmidi_receive (hmidi->input, buf, n_pending); 1207 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1230 }
1231 } else { 1208 } else {
1232 /* flush the MIDI input FIFO */ 1209 /* flush the MIDI input FIFO */
1233 while (--n_pending) { 1210 while (--n_pending)
1234 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id); 1211 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1235 }
1236 } 1212 }
1237 } 1213 }
1238 hmidi->pending = 0; 1214 hmidi->pending = 0;
1239 if (hmidi->id) { 1215 if (hmidi->id)
1240 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable; 1216 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1241 } else { 1217 else
1242 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable; 1218 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1243 }
1244 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register); 1219 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1245 spin_unlock_irqrestore (&hmidi->lock, flags); 1220 spin_unlock_irqrestore (&hmidi->lock, flags);
1246 return snd_hdsp_midi_output_write (hmidi); 1221 return snd_hdsp_midi_output_write (hmidi);
@@ -1310,9 +1285,8 @@ static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, in
1310 hmidi->istimer++; 1285 hmidi->istimer++;
1311 } 1286 }
1312 } else { 1287 } else {
1313 if (hmidi->istimer && --hmidi->istimer <= 0) { 1288 if (hmidi->istimer && --hmidi->istimer <= 0)
1314 del_timer (&hmidi->timer); 1289 del_timer (&hmidi->timer);
1315 }
1316 } 1290 }
1317 spin_unlock_irqrestore (&hmidi->lock, flags); 1291 spin_unlock_irqrestore (&hmidi->lock, flags);
1318 if (up) 1292 if (up)
@@ -1400,9 +1374,8 @@ static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int i
1400 spin_lock_init (&hdsp->midi[id].lock); 1374 spin_lock_init (&hdsp->midi[id].lock);
1401 1375
1402 sprintf (buf, "%s MIDI %d", card->shortname, id+1); 1376 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1403 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) { 1377 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1404 return -1; 1378 return -1;
1405 }
1406 1379
1407 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1); 1380 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1408 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id]; 1381 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
@@ -1588,11 +1561,10 @@ static int hdsp_spdif_out(hdsp_t *hdsp)
1588 1561
1589static int hdsp_set_spdif_output(hdsp_t *hdsp, int out) 1562static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1590{ 1563{
1591 if (out) { 1564 if (out)
1592 hdsp->control_register |= HDSP_SPDIFOpticalOut; 1565 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1593 } else { 1566 else
1594 hdsp->control_register &= ~HDSP_SPDIFOpticalOut; 1567 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1595 }
1596 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1568 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1597 return 0; 1569 return 0;
1598} 1570}
@@ -1642,11 +1614,10 @@ static int hdsp_spdif_professional(hdsp_t *hdsp)
1642 1614
1643static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val) 1615static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1644{ 1616{
1645 if (val) { 1617 if (val)
1646 hdsp->control_register |= HDSP_SPDIFProfessional; 1618 hdsp->control_register |= HDSP_SPDIFProfessional;
1647 } else { 1619 else
1648 hdsp->control_register &= ~HDSP_SPDIFProfessional; 1620 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1649 }
1650 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1621 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1651 return 0; 1622 return 0;
1652} 1623}
@@ -1687,11 +1658,10 @@ static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1687 1658
1688static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val) 1659static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1689{ 1660{
1690 if (val) { 1661 if (val)
1691 hdsp->control_register |= HDSP_SPDIFEmphasis; 1662 hdsp->control_register |= HDSP_SPDIFEmphasis;
1692 } else { 1663 else
1693 hdsp->control_register &= ~HDSP_SPDIFEmphasis; 1664 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1694 }
1695 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1665 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1696 return 0; 1666 return 0;
1697} 1667}
@@ -1732,11 +1702,10 @@ static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1732 1702
1733static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val) 1703static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1734{ 1704{
1735 if (val) { 1705 if (val)
1736 hdsp->control_register |= HDSP_SPDIFNonAudio; 1706 hdsp->control_register |= HDSP_SPDIFNonAudio;
1737 } else { 1707 else
1738 hdsp->control_register &= ~HDSP_SPDIFNonAudio; 1708 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1739 }
1740 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 1709 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1741 return 0; 1710 return 0;
1742} 1711}
@@ -1921,11 +1890,10 @@ static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_
1921 1890
1922static int hdsp_system_clock_mode(hdsp_t *hdsp) 1891static int hdsp_system_clock_mode(hdsp_t *hdsp)
1923{ 1892{
1924 if (hdsp->control_register & HDSP_ClockModeMaster) { 1893 if (hdsp->control_register & HDSP_ClockModeMaster)
1925 return 0; 1894 return 0;
1926 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) { 1895 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1927 return 0; 1896 return 0;
1928 }
1929 return 1; 1897 return 1;
1930} 1898}
1931 1899
@@ -2074,16 +2042,17 @@ static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_val
2074 val = ucontrol->value.enumerated.item[0]; 2042 val = ucontrol->value.enumerated.item[0];
2075 if (val < 0) val = 0; 2043 if (val < 0) val = 0;
2076 if (hdsp->io_type == H9632) { 2044 if (hdsp->io_type == H9632) {
2077 if (val > 9) val = 9; 2045 if (val > 9)
2046 val = 9;
2078 } else { 2047 } else {
2079 if (val > 6) val = 6; 2048 if (val > 6)
2049 val = 6;
2080 } 2050 }
2081 spin_lock_irq(&hdsp->lock); 2051 spin_lock_irq(&hdsp->lock);
2082 if (val != hdsp_clock_source(hdsp)) { 2052 if (val != hdsp_clock_source(hdsp))
2083 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0; 2053 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2084 } else { 2054 else
2085 change = 0; 2055 change = 0;
2086 }
2087 spin_unlock_irq(&hdsp->lock); 2056 spin_unlock_irq(&hdsp->lock);
2088 return change; 2057 return change;
2089} 2058}
@@ -2193,11 +2162,10 @@ static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2193 if (val < 0) val = 0; 2162 if (val < 0) val = 0;
2194 if (val > 2) val = 2; 2163 if (val > 2) val = 2;
2195 spin_lock_irq(&hdsp->lock); 2164 spin_lock_irq(&hdsp->lock);
2196 if (val != hdsp_da_gain(hdsp)) { 2165 if (val != hdsp_da_gain(hdsp))
2197 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0; 2166 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2198 } else { 2167 else
2199 change = 0; 2168 change = 0;
2200 }
2201 spin_unlock_irq(&hdsp->lock); 2169 spin_unlock_irq(&hdsp->lock);
2202 return change; 2170 return change;
2203} 2171}
@@ -2279,11 +2247,10 @@ static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2279 if (val < 0) val = 0; 2247 if (val < 0) val = 0;
2280 if (val > 2) val = 2; 2248 if (val > 2) val = 2;
2281 spin_lock_irq(&hdsp->lock); 2249 spin_lock_irq(&hdsp->lock);
2282 if (val != hdsp_ad_gain(hdsp)) { 2250 if (val != hdsp_ad_gain(hdsp))
2283 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0; 2251 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2284 } else { 2252 else
2285 change = 0; 2253 change = 0;
2286 }
2287 spin_unlock_irq(&hdsp->lock); 2254 spin_unlock_irq(&hdsp->lock);
2288 return change; 2255 return change;
2289} 2256}
@@ -2365,11 +2332,10 @@ static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
2365 if (val < 0) val = 0; 2332 if (val < 0) val = 0;
2366 if (val > 2) val = 2; 2333 if (val > 2) val = 2;
2367 spin_lock_irq(&hdsp->lock); 2334 spin_lock_irq(&hdsp->lock);
2368 if (val != hdsp_phone_gain(hdsp)) { 2335 if (val != hdsp_phone_gain(hdsp))
2369 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0; 2336 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2370 } else { 2337 else
2371 change = 0; 2338 change = 0;
2372 }
2373 spin_unlock_irq(&hdsp->lock); 2339 spin_unlock_irq(&hdsp->lock);
2374 return change; 2340 return change;
2375} 2341}
@@ -2385,19 +2351,17 @@ static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
2385 2351
2386static int hdsp_xlr_breakout_cable(hdsp_t *hdsp) 2352static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2387{ 2353{
2388 if (hdsp->control_register & HDSP_XLRBreakoutCable) { 2354 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2389 return 1; 2355 return 1;
2390 }
2391 return 0; 2356 return 0;
2392} 2357}
2393 2358
2394static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode) 2359static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2395{ 2360{
2396 if (mode) { 2361 if (mode)
2397 hdsp->control_register |= HDSP_XLRBreakoutCable; 2362 hdsp->control_register |= HDSP_XLRBreakoutCable;
2398 } else { 2363 else
2399 hdsp->control_register &= ~HDSP_XLRBreakoutCable; 2364 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2400 }
2401 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2365 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2402 return 0; 2366 return 0;
2403} 2367}
@@ -2450,19 +2414,17 @@ static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_el
2450 2414
2451static int hdsp_aeb(hdsp_t *hdsp) 2415static int hdsp_aeb(hdsp_t *hdsp)
2452{ 2416{
2453 if (hdsp->control_register & HDSP_AnalogExtensionBoard) { 2417 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2454 return 1; 2418 return 1;
2455 }
2456 return 0; 2419 return 0;
2457} 2420}
2458 2421
2459static int hdsp_set_aeb(hdsp_t *hdsp, int mode) 2422static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2460{ 2423{
2461 if (mode) { 2424 if (mode)
2462 hdsp->control_register |= HDSP_AnalogExtensionBoard; 2425 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2463 } else { 2426 else
2464 hdsp->control_register &= ~HDSP_AnalogExtensionBoard; 2427 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2465 }
2466 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2428 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2467 return 0; 2429 return 0;
2468} 2430}
@@ -2705,11 +2667,10 @@ static int hdsp_line_out(hdsp_t *hdsp)
2705 2667
2706static int hdsp_set_line_output(hdsp_t *hdsp, int out) 2668static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2707{ 2669{
2708 if (out) { 2670 if (out)
2709 hdsp->control_register |= HDSP_LineOut; 2671 hdsp->control_register |= HDSP_LineOut;
2710 } else { 2672 else
2711 hdsp->control_register &= ~HDSP_LineOut; 2673 hdsp->control_register &= ~HDSP_LineOut;
2712 }
2713 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2674 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2714 return 0; 2675 return 0;
2715} 2676}
@@ -2760,11 +2721,10 @@ static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
2760 2721
2761static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise) 2722static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise)
2762{ 2723{
2763 if (precise) { 2724 if (precise)
2764 hdsp->precise_ptr = 1; 2725 hdsp->precise_ptr = 1;
2765 } else { 2726 else
2766 hdsp->precise_ptr = 0; 2727 hdsp->precise_ptr = 0;
2767 }
2768 return 0; 2728 return 0;
2769} 2729}
2770 2730
@@ -2814,11 +2774,10 @@ static int snd_hdsp_put_precise_pointer(snd_kcontrol_t * kcontrol, snd_ctl_elem_
2814 2774
2815static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet) 2775static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet)
2816{ 2776{
2817 if (use_tasklet) { 2777 if (use_tasklet)
2818 hdsp->use_midi_tasklet = 1; 2778 hdsp->use_midi_tasklet = 1;
2819 } else { 2779 else
2820 hdsp->use_midi_tasklet = 0; 2780 hdsp->use_midi_tasklet = 0;
2821 }
2822 return 0; 2781 return 0;
2823} 2782}
2824 2783
@@ -2889,11 +2848,10 @@ static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
2889 source = ucontrol->value.integer.value[0]; 2848 source = ucontrol->value.integer.value[0];
2890 destination = ucontrol->value.integer.value[1]; 2849 destination = ucontrol->value.integer.value[1];
2891 2850
2892 if (source >= hdsp->max_channels) { 2851 if (source >= hdsp->max_channels)
2893 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination); 2852 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2894 } else { 2853 else
2895 addr = hdsp_input_to_output_key(hdsp,source, destination); 2854 addr = hdsp_input_to_output_key(hdsp,source, destination);
2896 }
2897 2855
2898 spin_lock_irq(&hdsp->lock); 2856 spin_lock_irq(&hdsp->lock);
2899 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr); 2857 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
@@ -2916,11 +2874,10 @@ static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
2916 source = ucontrol->value.integer.value[0]; 2874 source = ucontrol->value.integer.value[0];
2917 destination = ucontrol->value.integer.value[1]; 2875 destination = ucontrol->value.integer.value[1];
2918 2876
2919 if (source >= hdsp->max_channels) { 2877 if (source >= hdsp->max_channels)
2920 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination); 2878 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2921 } else { 2879 else
2922 addr = hdsp_input_to_output_key(hdsp,source, destination); 2880 addr = hdsp_input_to_output_key(hdsp,source, destination);
2923 }
2924 2881
2925 gain = ucontrol->value.integer.value[2]; 2882 gain = ucontrol->value.integer.value[2];
2926 2883
@@ -2957,14 +2914,12 @@ static int hdsp_wc_sync_check(hdsp_t *hdsp)
2957{ 2914{
2958 int status2 = hdsp_read(hdsp, HDSP_status2Register); 2915 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2959 if (status2 & HDSP_wc_lock) { 2916 if (status2 & HDSP_wc_lock) {
2960 if (status2 & HDSP_wc_sync) { 2917 if (status2 & HDSP_wc_sync)
2961 return 2; 2918 return 2;
2962 } else { 2919 else
2963 return 1; 2920 return 1;
2964 } 2921 } else
2965 } else {
2966 return 0; 2922 return 0;
2967 }
2968 return 0; 2923 return 0;
2969} 2924}
2970 2925
@@ -2988,14 +2943,13 @@ static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_va
2988static int hdsp_spdif_sync_check(hdsp_t *hdsp) 2943static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2989{ 2944{
2990 int status = hdsp_read(hdsp, HDSP_statusRegister); 2945 int status = hdsp_read(hdsp, HDSP_statusRegister);
2991 if (status & HDSP_SPDIFErrorFlag) { 2946 if (status & HDSP_SPDIFErrorFlag)
2992 return 0; 2947 return 0;
2993 } else { 2948 else {
2994 if (status & HDSP_SPDIFSync) { 2949 if (status & HDSP_SPDIFSync)
2995 return 2; 2950 return 2;
2996 } else { 2951 else
2997 return 1; 2952 return 1;
2998 }
2999 } 2953 }
3000 return 0; 2954 return 0;
3001} 2955}
@@ -3021,14 +2975,12 @@ static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3021{ 2975{
3022 int status = hdsp_read(hdsp, HDSP_statusRegister); 2976 int status = hdsp_read(hdsp, HDSP_statusRegister);
3023 if (status & HDSP_TimecodeLock) { 2977 if (status & HDSP_TimecodeLock) {
3024 if (status & HDSP_TimecodeSync) { 2978 if (status & HDSP_TimecodeSync)
3025 return 2; 2979 return 2;
3026 } else { 2980 else
3027 return 1; 2981 return 1;
3028 } 2982 } else
3029 } else {
3030 return 0; 2983 return 0;
3031 }
3032} 2984}
3033 2985
3034static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 2986static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
@@ -3051,14 +3003,12 @@ static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3051 int status = hdsp_read(hdsp, HDSP_statusRegister); 3003 int status = hdsp_read(hdsp, HDSP_statusRegister);
3052 3004
3053 if (status & (HDSP_Lock0>>idx)) { 3005 if (status & (HDSP_Lock0>>idx)) {
3054 if (status & (HDSP_Sync0>>idx)) { 3006 if (status & (HDSP_Sync0>>idx))
3055 return 2; 3007 return 2;
3056 } else { 3008 else
3057 return 1; 3009 return 1;
3058 } 3010 } else
3059 } else {
3060 return 0; 3011 return 0;
3061 }
3062} 3012}
3063 3013
3064static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 3014static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
@@ -3171,9 +3121,8 @@ static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3171 snd_kcontrol_t *kctl; 3121 snd_kcontrol_t *kctl;
3172 3122
3173 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) { 3123 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3174 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) { 3124 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3175 return err; 3125 return err;
3176 }
3177 if (idx == 1) /* IEC958 (S/PDIF) Stream */ 3126 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3178 hdsp->spdif_ctl = kctl; 3127 hdsp->spdif_ctl = kctl;
3179 } 3128 }
@@ -3181,32 +3130,28 @@ static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3181 /* ADAT SyncCheck status */ 3130 /* ADAT SyncCheck status */
3182 snd_hdsp_adat_sync_check.name = "ADAT Lock Status"; 3131 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3183 snd_hdsp_adat_sync_check.index = 1; 3132 snd_hdsp_adat_sync_check.index = 1;
3184 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) { 3133 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3185 return err; 3134 return err;
3186 }
3187 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 3135 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3188 for (idx = 1; idx < 3; ++idx) { 3136 for (idx = 1; idx < 3; ++idx) {
3189 snd_hdsp_adat_sync_check.index = idx+1; 3137 snd_hdsp_adat_sync_check.index = idx+1;
3190 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) { 3138 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3191 return err; 3139 return err;
3192 }
3193 } 3140 }
3194 } 3141 }
3195 3142
3196 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */ 3143 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3197 if (hdsp->io_type == H9632) { 3144 if (hdsp->io_type == H9632) {
3198 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) { 3145 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3199 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) { 3146 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3200 return err; 3147 return err;
3201 }
3202 } 3148 }
3203 } 3149 }
3204 3150
3205 /* AEB control for H96xx card */ 3151 /* AEB control for H96xx card */
3206 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { 3152 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3207 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) { 3153 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3208 return err; 3154 return err;
3209 }
3210 } 3155 }
3211 3156
3212 return 0; 3157 return 0;
@@ -3228,12 +3173,11 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3228 char *clock_source; 3173 char *clock_source;
3229 int x; 3174 int x;
3230 3175
3231 if (hdsp_check_for_iobox (hdsp)) { 3176 if (hdsp_check_for_iobox (hdsp))
3232 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n"); 3177 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3233 return; 3178 return;
3234 }
3235 3179
3236 if (hdsp_check_for_firmware(hdsp)) { 3180 if (hdsp_check_for_firmware(hdsp, 0)) {
3237 if (hdsp->state & HDSP_FirmwareCached) { 3181 if (hdsp->state & HDSP_FirmwareCached) {
3238 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) { 3182 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3239 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n"); 3183 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
@@ -3314,11 +3258,10 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3314 } 3258 }
3315 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source); 3259 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3316 3260
3317 if (hdsp_system_clock_mode(hdsp)) { 3261 if (hdsp_system_clock_mode(hdsp))
3318 system_clock_mode = "Slave"; 3262 system_clock_mode = "Slave";
3319 } else { 3263 else
3320 system_clock_mode = "Master"; 3264 system_clock_mode = "Master";
3321 }
3322 3265
3323 switch (hdsp_pref_sync_ref (hdsp)) { 3266 switch (hdsp_pref_sync_ref (hdsp)) {
3324 case HDSP_SYNC_FROM_WORD: 3267 case HDSP_SYNC_FROM_WORD:
@@ -3400,85 +3343,75 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3400 break; 3343 break;
3401 } 3344 }
3402 3345
3403 if (hdsp->control_register & HDSP_SPDIFOpticalOut) { 3346 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3404 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n"); 3347 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3405 } else { 3348 else
3406 snd_iprintf(buffer, "IEC958 output: Coaxial only\n"); 3349 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3407 }
3408 3350
3409 if (hdsp->control_register & HDSP_SPDIFProfessional) { 3351 if (hdsp->control_register & HDSP_SPDIFProfessional)
3410 snd_iprintf(buffer, "IEC958 quality: Professional\n"); 3352 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3411 } else { 3353 else
3412 snd_iprintf(buffer, "IEC958 quality: Consumer\n"); 3354 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3413 }
3414 3355
3415 if (hdsp->control_register & HDSP_SPDIFEmphasis) { 3356 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3416 snd_iprintf(buffer, "IEC958 emphasis: on\n"); 3357 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3417 } else { 3358 else
3418 snd_iprintf(buffer, "IEC958 emphasis: off\n"); 3359 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3419 }
3420 3360
3421 if (hdsp->control_register & HDSP_SPDIFNonAudio) { 3361 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3422 snd_iprintf(buffer, "IEC958 NonAudio: on\n"); 3362 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3423 } else { 3363 else
3424 snd_iprintf(buffer, "IEC958 NonAudio: off\n"); 3364 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3425 } 3365 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0)
3426 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
3427 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x); 3366 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3428 } else { 3367 else
3429 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n"); 3368 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3430 }
3431 3369
3432 snd_iprintf(buffer, "\n"); 3370 snd_iprintf(buffer, "\n");
3433 3371
3434 /* Sync Check */ 3372 /* Sync Check */
3435 x = status & HDSP_Sync0; 3373 x = status & HDSP_Sync0;
3436 if (status & HDSP_Lock0) { 3374 if (status & HDSP_Lock0)
3437 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock"); 3375 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3438 } else { 3376 else
3439 snd_iprintf(buffer, "ADAT1: No Lock\n"); 3377 snd_iprintf(buffer, "ADAT1: No Lock\n");
3440 }
3441 3378
3442 switch (hdsp->io_type) { 3379 switch (hdsp->io_type) {
3443 case Digiface: 3380 case Digiface:
3444 case H9652: 3381 case H9652:
3445 x = status & HDSP_Sync1; 3382 x = status & HDSP_Sync1;
3446 if (status & HDSP_Lock1) { 3383 if (status & HDSP_Lock1)
3447 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock"); 3384 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3448 } else { 3385 else
3449 snd_iprintf(buffer, "ADAT2: No Lock\n"); 3386 snd_iprintf(buffer, "ADAT2: No Lock\n");
3450 }
3451 x = status & HDSP_Sync2; 3387 x = status & HDSP_Sync2;
3452 if (status & HDSP_Lock2) { 3388 if (status & HDSP_Lock2)
3453 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock"); 3389 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3454 } else { 3390 else
3455 snd_iprintf(buffer, "ADAT3: No Lock\n"); 3391 snd_iprintf(buffer, "ADAT3: No Lock\n");
3456 } 3392 break;
3457 default: 3393 default:
3458 /* relax */ 3394 /* relax */
3459 break; 3395 break;
3460 } 3396 }
3461 3397
3462 x = status & HDSP_SPDIFSync; 3398 x = status & HDSP_SPDIFSync;
3463 if (status & HDSP_SPDIFErrorFlag) { 3399 if (status & HDSP_SPDIFErrorFlag)
3464 snd_iprintf (buffer, "SPDIF: No Lock\n"); 3400 snd_iprintf (buffer, "SPDIF: No Lock\n");
3465 } else { 3401 else
3466 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock"); 3402 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3467 }
3468 3403
3469 x = status2 & HDSP_wc_sync; 3404 x = status2 & HDSP_wc_sync;
3470 if (status2 & HDSP_wc_lock) { 3405 if (status2 & HDSP_wc_lock)
3471 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock"); 3406 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3472 } else { 3407 else
3473 snd_iprintf (buffer, "Word Clock: No Lock\n"); 3408 snd_iprintf (buffer, "Word Clock: No Lock\n");
3474 }
3475 3409
3476 x = status & HDSP_TimecodeSync; 3410 x = status & HDSP_TimecodeSync;
3477 if (status & HDSP_TimecodeLock) { 3411 if (status & HDSP_TimecodeLock)
3478 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock"); 3412 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3479 } else { 3413 else
3480 snd_iprintf(buffer, "ADAT Sync: No Lock\n"); 3414 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3481 }
3482 3415
3483 snd_iprintf(buffer, "\n"); 3416 snd_iprintf(buffer, "\n");
3484 3417
@@ -3527,11 +3460,10 @@ snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3527 3460
3528 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no"); 3461 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3529 3462
3530 if (hdsp->control_register & HDSP_AnalogExtensionBoard) { 3463 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3531 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n"); 3464 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3532 } else { 3465 else
3533 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n"); 3466 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3534 }
3535 snd_iprintf(buffer, "\n"); 3467 snd_iprintf(buffer, "\n");
3536 } 3468 }
3537 3469
@@ -3610,25 +3542,22 @@ static int snd_hdsp_set_defaults(hdsp_t *hdsp)
3610#else 3542#else
3611 hdsp->control2_register = 0; 3543 hdsp->control2_register = 0;
3612#endif 3544#endif
3613 if (hdsp->io_type == H9652) { 3545 if (hdsp->io_type == H9652)
3614 snd_hdsp_9652_enable_mixer (hdsp); 3546 snd_hdsp_9652_enable_mixer (hdsp);
3615 } else { 3547 else
3616 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); 3548 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3617 }
3618 3549
3619 hdsp_reset_hw_pointer(hdsp); 3550 hdsp_reset_hw_pointer(hdsp);
3620 hdsp_compute_period_size(hdsp); 3551 hdsp_compute_period_size(hdsp);
3621 3552
3622 /* silence everything */ 3553 /* silence everything */
3623 3554
3624 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) { 3555 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
3625 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN; 3556 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3626 }
3627 3557
3628 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) { 3558 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3629 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) { 3559 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3630 return -EIO; 3560 return -EIO;
3631 }
3632 } 3561 }
3633 3562
3634 /* H9632 specific defaults */ 3563 /* H9632 specific defaults */
@@ -3649,12 +3578,10 @@ static void hdsp_midi_tasklet(unsigned long arg)
3649{ 3578{
3650 hdsp_t *hdsp = (hdsp_t *)arg; 3579 hdsp_t *hdsp = (hdsp_t *)arg;
3651 3580
3652 if (hdsp->midi[0].pending) { 3581 if (hdsp->midi[0].pending)
3653 snd_hdsp_midi_input_read (&hdsp->midi[0]); 3582 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3654 } 3583 if (hdsp->midi[1].pending)
3655 if (hdsp->midi[1].pending) {
3656 snd_hdsp_midi_input_read (&hdsp->midi[1]); 3584 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3657 }
3658} 3585}
3659 3586
3660static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs) 3587static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
@@ -3674,9 +3601,8 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *reg
3674 midi0 = status & HDSP_midi0IRQPending; 3601 midi0 = status & HDSP_midi0IRQPending;
3675 midi1 = status & HDSP_midi1IRQPending; 3602 midi1 = status & HDSP_midi1IRQPending;
3676 3603
3677 if (!audio && !midi0 && !midi1) { 3604 if (!audio && !midi0 && !midi1)
3678 return IRQ_NONE; 3605 return IRQ_NONE;
3679 }
3680 3606
3681 hdsp_write(hdsp, HDSP_interruptConfirmation, 0); 3607 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3682 3608
@@ -3684,13 +3610,11 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *reg
3684 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff; 3610 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3685 3611
3686 if (audio) { 3612 if (audio) {
3687 if (hdsp->capture_substream) { 3613 if (hdsp->capture_substream)
3688 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 3614 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3689 }
3690 3615
3691 if (hdsp->playback_substream) { 3616 if (hdsp->playback_substream)
3692 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream); 3617 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3693 }
3694 } 3618 }
3695 3619
3696 if (midi0 && midi0status) { 3620 if (midi0 && midi0status) {
@@ -3735,15 +3659,13 @@ static char *hdsp_channel_buffer_location(hdsp_t *hdsp,
3735 3659
3736 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL); 3660 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3737 3661
3738 if ((mapped_channel = hdsp->channel_map[channel]) < 0) { 3662 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3739 return NULL; 3663 return NULL;
3740 }
3741 3664
3742 if (stream == SNDRV_PCM_STREAM_CAPTURE) { 3665 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3743 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); 3666 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3744 } else { 3667 else
3745 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); 3668 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3746 }
3747} 3669}
3748 3670
3749static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel, 3671static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel,
@@ -3824,20 +3746,11 @@ static int snd_hdsp_hw_params(snd_pcm_substream_t *substream,
3824 pid_t this_pid; 3746 pid_t this_pid;
3825 pid_t other_pid; 3747 pid_t other_pid;
3826 3748
3827 if (hdsp_check_for_iobox (hdsp)) { 3749 if (hdsp_check_for_iobox (hdsp))
3828 return -EIO; 3750 return -EIO;
3829 }
3830 3751
3831 if (hdsp_check_for_firmware(hdsp)) { 3752 if (hdsp_check_for_firmware(hdsp, 1))
3832 if (hdsp->state & HDSP_FirmwareCached) {
3833 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3834 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3835 }
3836 } else {
3837 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3838 }
3839 return -EIO; 3753 return -EIO;
3840 }
3841 3754
3842 spin_lock_irq(&hdsp->lock); 3755 spin_lock_irq(&hdsp->lock);
3843 3756
@@ -3908,9 +3821,8 @@ static int snd_hdsp_channel_info(snd_pcm_substream_t *substream,
3908 3821
3909 snd_assert(info->channel < hdsp->max_channels, return -EINVAL); 3822 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3910 3823
3911 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) { 3824 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
3912 return -EINVAL; 3825 return -EINVAL;
3913 }
3914 3826
3915 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES; 3827 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3916 info->first = 0; 3828 info->first = 0;
@@ -3923,14 +3835,9 @@ static int snd_hdsp_ioctl(snd_pcm_substream_t *substream,
3923{ 3835{
3924 switch (cmd) { 3836 switch (cmd) {
3925 case SNDRV_PCM_IOCTL1_RESET: 3837 case SNDRV_PCM_IOCTL1_RESET:
3926 {
3927 return snd_hdsp_reset(substream); 3838 return snd_hdsp_reset(substream);
3928 }
3929 case SNDRV_PCM_IOCTL1_CHANNEL_INFO: 3839 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3930 { 3840 return snd_hdsp_channel_info(substream, arg);
3931 snd_pcm_channel_info_t *info = arg;
3932 return snd_hdsp_channel_info(substream, info);
3933 }
3934 default: 3841 default:
3935 break; 3842 break;
3936 } 3843 }
@@ -3944,20 +3851,11 @@ static int snd_hdsp_trigger(snd_pcm_substream_t *substream, int cmd)
3944 snd_pcm_substream_t *other; 3851 snd_pcm_substream_t *other;
3945 int running; 3852 int running;
3946 3853
3947 if (hdsp_check_for_iobox (hdsp)) { 3854 if (hdsp_check_for_iobox (hdsp))
3948 return -EIO; 3855 return -EIO;
3949 }
3950 3856
3951 if (hdsp_check_for_firmware(hdsp)) { 3857 if (hdsp_check_for_firmware(hdsp, 1))
3952 if (hdsp->state & HDSP_FirmwareCached) {
3953 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3954 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3955 }
3956 } else {
3957 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3958 }
3959 return -EIO; 3858 return -EIO;
3960 }
3961 3859
3962 spin_lock(&hdsp->lock); 3860 spin_lock(&hdsp->lock);
3963 running = hdsp->running; 3861 running = hdsp->running;
@@ -4022,20 +3920,11 @@ static int snd_hdsp_prepare(snd_pcm_substream_t *substream)
4022 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 3920 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4023 int result = 0; 3921 int result = 0;
4024 3922
4025 if (hdsp_check_for_iobox (hdsp)) { 3923 if (hdsp_check_for_iobox (hdsp))
4026 return -EIO; 3924 return -EIO;
4027 }
4028 3925
4029 if (hdsp_check_for_firmware(hdsp)) { 3926 if (hdsp_check_for_firmware(hdsp, 1))
4030 if (hdsp->state & HDSP_FirmwareCached) {
4031 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4032 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4033 }
4034 } else {
4035 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4036 }
4037 return -EIO; 3927 return -EIO;
4038 }
4039 3928
4040 spin_lock_irq(&hdsp->lock); 3929 spin_lock_irq(&hdsp->lock);
4041 if (!hdsp->running) 3930 if (!hdsp->running)
@@ -4285,20 +4174,11 @@ static int snd_hdsp_playback_open(snd_pcm_substream_t *substream)
4285 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 4174 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4286 snd_pcm_runtime_t *runtime = substream->runtime; 4175 snd_pcm_runtime_t *runtime = substream->runtime;
4287 4176
4288 if (hdsp_check_for_iobox (hdsp)) { 4177 if (hdsp_check_for_iobox (hdsp))
4289 return -EIO; 4178 return -EIO;
4290 }
4291 4179
4292 if (hdsp_check_for_firmware(hdsp)) { 4180 if (hdsp_check_for_firmware(hdsp, 1))
4293 if (hdsp->state & HDSP_FirmwareCached) {
4294 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4295 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4296 }
4297 } else {
4298 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4299 }
4300 return -EIO; 4181 return -EIO;
4301 }
4302 4182
4303 spin_lock_irq(&hdsp->lock); 4183 spin_lock_irq(&hdsp->lock);
4304 4184
@@ -4367,20 +4247,11 @@ static int snd_hdsp_capture_open(snd_pcm_substream_t *substream)
4367 hdsp_t *hdsp = snd_pcm_substream_chip(substream); 4247 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4368 snd_pcm_runtime_t *runtime = substream->runtime; 4248 snd_pcm_runtime_t *runtime = substream->runtime;
4369 4249
4370 if (hdsp_check_for_iobox (hdsp)) { 4250 if (hdsp_check_for_iobox (hdsp))
4371 return -EIO; 4251 return -EIO;
4372 }
4373 4252
4374 if (hdsp_check_for_firmware(hdsp)) { 4253 if (hdsp_check_for_firmware(hdsp, 1))
4375 if (hdsp->state & HDSP_FirmwareCached) {
4376 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4377 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4378 }
4379 } else {
4380 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4381 }
4382 return -EIO; 4254 return -EIO;
4383 }
4384 4255
4385 spin_lock_irq(&hdsp->lock); 4256 spin_lock_irq(&hdsp->lock);
4386 4257
@@ -4589,19 +4460,17 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4589 int i; 4460 int i;
4590 4461
4591 if (!(hdsp->state & HDSP_FirmwareLoaded)) { 4462 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4592 snd_printk("Hammerfall-DSP: Firmware needs to be uploaded to the card.\n"); 4463 snd_printk(KERN_ERR "Hammerfall-DSP: Firmware needs to be uploaded to the card.\n");
4593 return -EINVAL; 4464 return -EINVAL;
4594 } 4465 }
4595 spin_lock_irqsave(&hdsp->lock, flags); 4466 spin_lock_irqsave(&hdsp->lock, flags);
4596 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp); 4467 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4597 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp); 4468 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4598 if (hdsp->io_type != H9632) { 4469 if (hdsp->io_type != H9632)
4599 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp); 4470 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4600 }
4601 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp); 4471 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4602 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i) { 4472 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i)
4603 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i); 4473 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4604 }
4605 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp); 4474 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4606 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp); 4475 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4607 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp); 4476 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
@@ -4621,9 +4490,8 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4621 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp); 4490 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4622 4491
4623 } 4492 }
4624 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) { 4493 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4625 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp); 4494 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4626 }
4627 spin_unlock_irqrestore(&hdsp->lock, flags); 4495 spin_unlock_irqrestore(&hdsp->lock, flags);
4628 if (copy_to_user(argp, &info, sizeof(info))) 4496 if (copy_to_user(argp, &info, sizeof(info)))
4629 return -EFAULT; 4497 return -EFAULT;
@@ -4645,15 +4513,13 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4645 4513
4646 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4514 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4647 if (hdsp->io_type == Undefined) { 4515 if (hdsp->io_type == Undefined) {
4648 if ((err = hdsp_get_iobox_version(hdsp)) < 0) { 4516 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4649 return err; 4517 return err;
4650 }
4651 } 4518 }
4652 hdsp_version.io_type = hdsp->io_type; 4519 hdsp_version.io_type = hdsp->io_type;
4653 hdsp_version.firmware_rev = hdsp->firmware_rev; 4520 hdsp_version.firmware_rev = hdsp->firmware_rev;
4654 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) { 4521 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
4655 return -EFAULT; 4522 return -EFAULT;
4656 }
4657 break; 4523 break;
4658 } 4524 }
4659 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: { 4525 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
@@ -4668,38 +4534,33 @@ static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int
4668 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded)) 4534 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4669 return -EBUSY; 4535 return -EBUSY;
4670 4536
4671 snd_printk("Hammerfall-DSP: initializing firmware upload\n"); 4537 snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n");
4672 firmware = (hdsp_firmware_t __user *)argp; 4538 firmware = (hdsp_firmware_t __user *)argp;
4673 4539
4674 if (get_user(firmware_data, &firmware->firmware_data)) { 4540 if (get_user(firmware_data, &firmware->firmware_data))
4675 return -EFAULT; 4541 return -EFAULT;
4676 }
4677 4542
4678 if (hdsp_check_for_iobox (hdsp)) { 4543 if (hdsp_check_for_iobox (hdsp))
4679 return -EIO; 4544 return -EIO;
4680 }
4681 4545
4682 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) { 4546 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
4683 return -EFAULT; 4547 return -EFAULT;
4684 }
4685 4548
4686 hdsp->state |= HDSP_FirmwareCached; 4549 hdsp->state |= HDSP_FirmwareCached;
4687 4550
4688 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) { 4551 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4689 return err; 4552 return err;
4690 }
4691 4553
4692 if (!(hdsp->state & HDSP_InitializationComplete)) { 4554 if (!(hdsp->state & HDSP_InitializationComplete)) {
4693 if ((err = snd_hdsp_enable_io(hdsp)) < 0) { 4555 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4694 return err; 4556 return err;
4695 }
4696 4557
4697 snd_hdsp_initialize_channels(hdsp); 4558 snd_hdsp_initialize_channels(hdsp);
4698 snd_hdsp_initialize_midi_flush(hdsp); 4559 snd_hdsp_initialize_midi_flush(hdsp);
4699 4560
4700 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4561 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4701 snd_printk("Hammerfall-DSP: error creating alsa devices\n"); 4562 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4702 return err; 4563 return err;
4703 } 4564 }
4704 } 4565 }
4705 break; 4566 break;
@@ -4790,7 +4651,7 @@ static int snd_hdsp_enable_io (hdsp_t *hdsp)
4790 int i; 4651 int i;
4791 4652
4792 if (hdsp_fifo_wait (hdsp, 0, 100)) { 4653 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4793 snd_printk("Hammerfall-DSP: enable_io fifo_wait failed\n"); 4654 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n");
4794 return -EIO; 4655 return -EIO;
4795 } 4656 }
4796 4657
@@ -4856,25 +4717,25 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4856 int err; 4717 int err;
4857 4718
4858 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) { 4719 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4859 snd_printk("Hammerfall-DSP: Error creating pcm interface\n"); 4720 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n");
4860 return err; 4721 return err;
4861 } 4722 }
4862 4723
4863 4724
4864 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) { 4725 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4865 snd_printk("Hammerfall-DSP: Error creating first midi interface\n"); 4726 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n");
4866 return err; 4727 return err;
4867 } 4728 }
4868 4729
4869 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) { 4730 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
4870 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) { 4731 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4871 snd_printk("Hammerfall-DSP: Error creating second midi interface\n"); 4732 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n");
4872 return err; 4733 return err;
4873 } 4734 }
4874 } 4735 }
4875 4736
4876 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) { 4737 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4877 snd_printk("Hammerfall-DSP: Error creating ctl interface\n"); 4738 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n");
4878 return err; 4739 return err;
4879 } 4740 }
4880 4741
@@ -4887,7 +4748,7 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4887 hdsp->playback_substream = NULL; 4748 hdsp->playback_substream = NULL;
4888 4749
4889 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) { 4750 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4890 snd_printk("Hammerfall-DSP: Error setting default values\n"); 4751 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n");
4891 return err; 4752 return err;
4892 } 4753 }
4893 4754
@@ -4897,7 +4758,7 @@ static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4897 hdsp->port, hdsp->irq); 4758 hdsp->port, hdsp->irq);
4898 4759
4899 if ((err = snd_card_register(card)) < 0) { 4760 if ((err = snd_card_register(card)) < 0) {
4900 snd_printk("Hammerfall-DSP: error registering card\n"); 4761 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n");
4901 return err; 4762 return err;
4902 } 4763 }
4903 hdsp->state |= HDSP_InitializationComplete; 4764 hdsp->state |= HDSP_InitializationComplete;
@@ -4963,18 +4824,17 @@ static int __devinit hdsp_request_fw_loader(hdsp_t *hdsp)
4963 return err; 4824 return err;
4964 4825
4965 if (!(hdsp->state & HDSP_InitializationComplete)) { 4826 if (!(hdsp->state & HDSP_InitializationComplete)) {
4966 if ((err = snd_hdsp_enable_io(hdsp)) < 0) { 4827 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4967 return err; 4828 return err;
4968 }
4969 4829
4970 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) { 4830 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
4971 snd_printk("Hammerfall-DSP: error creating hwdep device\n"); 4831 snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n");
4972 return err; 4832 return err;
4973 } 4833 }
4974 snd_hdsp_initialize_channels(hdsp); 4834 snd_hdsp_initialize_channels(hdsp);
4975 snd_hdsp_initialize_midi_flush(hdsp); 4835 snd_hdsp_initialize_midi_flush(hdsp);
4976 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4836 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4977 snd_printk("Hammerfall-DSP: error creating alsa devices\n"); 4837 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4978 return err; 4838 return err;
4979 } 4839 }
4980 } 4840 }
@@ -5029,11 +4889,11 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5029 strcpy(card->driver, "H-DSP"); 4889 strcpy(card->driver, "H-DSP");
5030 strcpy(card->mixername, "Xilinx FPGA"); 4890 strcpy(card->mixername, "Xilinx FPGA");
5031 4891
5032 if (hdsp->firmware_rev < 0xa) { 4892 if (hdsp->firmware_rev < 0xa)
5033 return -ENODEV; 4893 return -ENODEV;
5034 } else if (hdsp->firmware_rev < 0x64) { 4894 else if (hdsp->firmware_rev < 0x64)
5035 hdsp->card_name = "RME Hammerfall DSP"; 4895 hdsp->card_name = "RME Hammerfall DSP";
5036 } else if (hdsp->firmware_rev < 0x96) { 4896 else if (hdsp->firmware_rev < 0x96) {
5037 hdsp->card_name = "RME HDSP 9652"; 4897 hdsp->card_name = "RME HDSP 9652";
5038 is_9652 = 1; 4898 is_9652 = 1;
5039 } else { 4899 } else {
@@ -5042,9 +4902,8 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5042 is_9632 = 1; 4902 is_9632 = 1;
5043 } 4903 }
5044 4904
5045 if ((err = pci_enable_device(pci)) < 0) { 4905 if ((err = pci_enable_device(pci)) < 0)
5046 return err; 4906 return err;
5047 }
5048 4907
5049 pci_set_master(hdsp->pci); 4908 pci_set_master(hdsp->pci);
5050 4909
@@ -5052,12 +4911,12 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5052 return err; 4911 return err;
5053 hdsp->port = pci_resource_start(pci, 0); 4912 hdsp->port = pci_resource_start(pci, 0);
5054 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) { 4913 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5055 snd_printk("Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1); 4914 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5056 return -EBUSY; 4915 return -EBUSY;
5057 } 4916 }
5058 4917
5059 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) { 4918 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) {
5060 snd_printk("Hammerfall-DSP: unable to use IRQ %d\n", pci->irq); 4919 snd_printk(KERN_ERR "Hammerfall-DSP: unable to use IRQ %d\n", pci->irq);
5061 return -EBUSY; 4920 return -EBUSY;
5062 } 4921 }
5063 4922
@@ -5065,71 +4924,58 @@ static int __devinit snd_hdsp_create(snd_card_t *card,
5065 hdsp->precise_ptr = 1; 4924 hdsp->precise_ptr = 1;
5066 hdsp->use_midi_tasklet = 1; 4925 hdsp->use_midi_tasklet = 1;
5067 4926
5068 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) { 4927 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5069 return err; 4928 return err;
5070 }
5071 4929
5072 if (!is_9652 && !is_9632) { 4930 if (!is_9652 && !is_9632) {
5073 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */ 4931 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */
5074 if ((1000 / HZ) < 2000) { 4932 ssleep(2);
5075 ssleep(2);
5076 } else {
5077 mdelay(2000);
5078 }
5079 4933
5080 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 4934 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5081#ifdef HDSP_FW_LOADER 4935#ifdef HDSP_FW_LOADER
5082 if ((err = hdsp_request_fw_loader(hdsp)) < 0) { 4936 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5083 /* we don't fail as this can happen 4937 /* we don't fail as this can happen
5084 if userspace is not ready for 4938 if userspace is not ready for
5085 firmware upload 4939 firmware upload
5086 */ 4940 */
5087 snd_printk("Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n"); 4941 snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5088 } else { 4942 else
5089 /* init is complete, we return */ 4943 /* init is complete, we return */
5090 return 0; 4944 return 0;
5091 }
5092#endif 4945#endif
5093 /* no iobox connected, we defer initialization */ 4946 /* no iobox connected, we defer initialization */
5094 snd_printk("Hammerfall-DSP: card initialization pending : waiting for firmware\n"); 4947 snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5095 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) { 4948 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5096 return err; 4949 return err;
5097 }
5098 return 0; 4950 return 0;
5099 } else { 4951 } else {
5100 snd_printk("Hammerfall-DSP: Firmware already present, initializing card.\n"); 4952 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
5101 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) { 4953 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5102 hdsp->io_type = Multiface; 4954 hdsp->io_type = Multiface;
5103 } else { 4955 else
5104 hdsp->io_type = Digiface; 4956 hdsp->io_type = Digiface;
5105 }
5106 } 4957 }
5107 } 4958 }
5108 4959
5109 if ((err = snd_hdsp_enable_io(hdsp)) != 0) { 4960 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5110 return err; 4961 return err;
5111 }
5112 4962
5113 if (is_9652) { 4963 if (is_9652)
5114 hdsp->io_type = H9652; 4964 hdsp->io_type = H9652;
5115 }
5116 4965
5117 if (is_9632) { 4966 if (is_9632)
5118 hdsp->io_type = H9632; 4967 hdsp->io_type = H9632;
5119 }
5120 4968
5121 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) { 4969 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5122 return err; 4970 return err;
5123 }
5124 4971
5125 snd_hdsp_initialize_channels(hdsp); 4972 snd_hdsp_initialize_channels(hdsp);
5126 snd_hdsp_initialize_midi_flush(hdsp); 4973 snd_hdsp_initialize_midi_flush(hdsp);
5127 4974
5128 hdsp->state |= HDSP_FirmwareLoaded; 4975 hdsp->state |= HDSP_FirmwareLoaded;
5129 4976
5130 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) { 4977 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5131 return err; 4978 return err;
5132 }
5133 4979
5134 return 0; 4980 return 0;
5135} 4981}
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index fc3f3283ff37..60a1141f1327 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -3563,8 +3563,7 @@ static int snd_hdspm_free(hdspm_t * hdspm)
3563 free_irq(hdspm->irq, (void *) hdspm); 3563 free_irq(hdspm->irq, (void *) hdspm);
3564 3564
3565 3565
3566 if (hdspm->mixer) 3566 kfree(hdspm->mixer);
3567 kfree(hdspm->mixer);
3568 3567
3569 if (hdspm->iobase) 3568 if (hdspm->iobase)
3570 iounmap(hdspm->iobase); 3569 iounmap(hdspm->iobase);
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index b600f45e1834..59fcef9b6b81 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -779,7 +779,7 @@ static inline int rme9652_spdif_sample_rate(rme9652_t *s)
779 break; 779 break;
780 780
781 default: 781 default:
782 snd_printk("%s: unknown S/PDIF input rate (bits = 0x%x)\n", 782 snd_printk(KERN_ERR "%s: unknown S/PDIF input rate (bits = 0x%x)\n",
783 s->card_name, rate_bits); 783 s->card_name, rate_bits);
784 return 0; 784 return 0;
785 break; 785 break;
@@ -2496,12 +2496,12 @@ static int __devinit snd_rme9652_create(snd_card_t *card,
2496 rme9652->port = pci_resource_start(pci, 0); 2496 rme9652->port = pci_resource_start(pci, 0);
2497 rme9652->iobase = ioremap_nocache(rme9652->port, RME9652_IO_EXTENT); 2497 rme9652->iobase = ioremap_nocache(rme9652->port, RME9652_IO_EXTENT);
2498 if (rme9652->iobase == NULL) { 2498 if (rme9652->iobase == NULL) {
2499 snd_printk("unable to remap region 0x%lx-0x%lx\n", rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1); 2499 snd_printk(KERN_ERR "unable to remap region 0x%lx-0x%lx\n", rme9652->port, rme9652->port + RME9652_IO_EXTENT - 1);
2500 return -EBUSY; 2500 return -EBUSY;
2501 } 2501 }
2502 2502
2503 if (request_irq(pci->irq, snd_rme9652_interrupt, SA_INTERRUPT|SA_SHIRQ, "rme9652", (void *)rme9652)) { 2503 if (request_irq(pci->irq, snd_rme9652_interrupt, SA_INTERRUPT|SA_SHIRQ, "rme9652", (void *)rme9652)) {
2504 snd_printk("unable to request IRQ %d\n", pci->irq); 2504 snd_printk(KERN_ERR "unable to request IRQ %d\n", pci->irq);
2505 return -EBUSY; 2505 return -EBUSY;
2506 } 2506 }
2507 rme9652->irq = pci->irq; 2507 rme9652->irq = pci->irq;
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 1f6c2bfd43fd..9a35474aad05 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -591,7 +591,7 @@ static irqreturn_t snd_sonicvibes_interrupt(int irq, void *dev_id, struct pt_reg
591 return IRQ_NONE; 591 return IRQ_NONE;
592 if (status == 0xff) { /* failure */ 592 if (status == 0xff) { /* failure */
593 outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK)); 593 outb(sonic->irqmask = ~0, SV_REG(sonic, IRQMASK));
594 snd_printk("IRQ failure - interrupts disabled!!\n"); 594 snd_printk(KERN_ERR "IRQ failure - interrupts disabled!!\n");
595 return IRQ_HANDLED; 595 return IRQ_HANDLED;
596 } 596 }
597 if (sonic->pcm) { 597 if (sonic->pcm) {
@@ -1205,14 +1205,8 @@ static int snd_sonicvibes_free(sonicvibes_t *sonic)
1205 pci_write_config_dword(sonic->pci, 0x48, sonic->dmac_port); 1205 pci_write_config_dword(sonic->pci, 0x48, sonic->dmac_port);
1206 if (sonic->irq >= 0) 1206 if (sonic->irq >= 0)
1207 free_irq(sonic->irq, (void *)sonic); 1207 free_irq(sonic->irq, (void *)sonic);
1208 if (sonic->res_dmaa) { 1208 release_and_free_resource(sonic->res_dmaa);
1209 release_resource(sonic->res_dmaa); 1209 release_and_free_resource(sonic->res_dmac);
1210 kfree_nocheck(sonic->res_dmaa);
1211 }
1212 if (sonic->res_dmac) {
1213 release_resource(sonic->res_dmac);
1214 kfree_nocheck(sonic->res_dmac);
1215 }
1216 pci_release_regions(sonic->pci); 1210 pci_release_regions(sonic->pci);
1217 pci_disable_device(sonic->pci); 1211 pci_disable_device(sonic->pci);
1218 kfree(sonic); 1212 kfree(sonic);
@@ -1245,7 +1239,7 @@ static int __devinit snd_sonicvibes_create(snd_card_t * card,
1245 /* check, if we can restrict PCI DMA transfers to 24 bits */ 1239 /* check, if we can restrict PCI DMA transfers to 24 bits */
1246 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || 1240 if (pci_set_dma_mask(pci, 0x00ffffff) < 0 ||
1247 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { 1241 pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) {
1248 snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); 1242 snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n");
1249 pci_disable_device(pci); 1243 pci_disable_device(pci);
1250 return -ENXIO; 1244 return -ENXIO;
1251 } 1245 }
@@ -1273,7 +1267,7 @@ static int __devinit snd_sonicvibes_create(snd_card_t * card,
1273 sonic->game_port = pci_resource_start(pci, 4); 1267 sonic->game_port = pci_resource_start(pci, 4);
1274 1268
1275 if (request_irq(pci->irq, snd_sonicvibes_interrupt, SA_INTERRUPT|SA_SHIRQ, "S3 SonicVibes", (void *)sonic)) { 1269 if (request_irq(pci->irq, snd_sonicvibes_interrupt, SA_INTERRUPT|SA_SHIRQ, "S3 SonicVibes", (void *)sonic)) {
1276 snd_printk("unable to grab IRQ %d\n", pci->irq); 1270 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1277 snd_sonicvibes_free(sonic); 1271 snd_sonicvibes_free(sonic);
1278 return -EBUSY; 1272 return -EBUSY;
1279 } 1273 }
@@ -1287,24 +1281,24 @@ static int __devinit snd_sonicvibes_create(snd_card_t * card,
1287 if (!dmaa) { 1281 if (!dmaa) {
1288 dmaa = dmaio; 1282 dmaa = dmaio;
1289 dmaio += 0x10; 1283 dmaio += 0x10;
1290 snd_printk("BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n", dmaa); 1284 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel A i/o, allocated at 0x%x\n", dmaa);
1291 } 1285 }
1292 if (!dmac) { 1286 if (!dmac) {
1293 dmac = dmaio; 1287 dmac = dmaio;
1294 dmaio += 0x10; 1288 dmaio += 0x10;
1295 snd_printk("BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n", dmac); 1289 snd_printk(KERN_INFO "BIOS did not allocate DDMA channel C i/o, allocated at 0x%x\n", dmac);
1296 } 1290 }
1297 pci_write_config_dword(pci, 0x40, dmaa); 1291 pci_write_config_dword(pci, 0x40, dmaa);
1298 pci_write_config_dword(pci, 0x48, dmac); 1292 pci_write_config_dword(pci, 0x48, dmac);
1299 1293
1300 if ((sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A")) == NULL) { 1294 if ((sonic->res_dmaa = request_region(dmaa, 0x10, "S3 SonicVibes DDMA-A")) == NULL) {
1301 snd_sonicvibes_free(sonic); 1295 snd_sonicvibes_free(sonic);
1302 snd_printk("unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1); 1296 snd_printk(KERN_ERR "unable to grab DDMA-A port at 0x%x-0x%x\n", dmaa, dmaa + 0x10 - 1);
1303 return -EBUSY; 1297 return -EBUSY;
1304 } 1298 }
1305 if ((sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C")) == NULL) { 1299 if ((sonic->res_dmac = request_region(dmac, 0x10, "S3 SonicVibes DDMA-C")) == NULL) {
1306 snd_sonicvibes_free(sonic); 1300 snd_sonicvibes_free(sonic);
1307 snd_printk("unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1); 1301 snd_printk(KERN_ERR "unable to grab DDMA-C port at 0x%x-0x%x\n", dmac, dmac + 0x10 - 1);
1308 return -EBUSY; 1302 return -EBUSY;
1309 } 1303 }
1310 1304
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index 777da9a7298b..b9b93c7faafd 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -153,7 +153,7 @@ static unsigned short snd_trident_codec_read(ac97_t *ac97, unsigned short reg)
153 } 153 }
154 154
155 if (count == 0 && !trident->ac97_detect) { 155 if (count == 0 && !trident->ac97_detect) {
156 snd_printk("ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg, data); 156 snd_printk(KERN_ERR "ac97 codec read TIMEOUT [0x%x/0x%x]!!!\n", reg, data);
157 data = 0; 157 data = 0;
158 } 158 }
159 159
@@ -2893,7 +2893,8 @@ static void snd_trident_notify_pcm_change1(snd_card_t * card, snd_kcontrol_t *kc
2893{ 2893{
2894 snd_ctl_elem_id_t id; 2894 snd_ctl_elem_id_t id;
2895 2895
2896 snd_runtime_check(kctl != NULL, return); 2896 if (! kctl)
2897 return;
2897 if (activate) 2898 if (activate)
2898 kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 2899 kctl->vd[num].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
2899 else 2900 else
@@ -2989,13 +2990,13 @@ static int __devinit snd_trident_mixer(trident_t * trident, int pcm_spdif_device
2989 _ac97.num = 1; 2990 _ac97.num = 1;
2990 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec); 2991 err = snd_ac97_mixer(trident->ac97_bus, &_ac97, &trident->ac97_sec);
2991 if (err < 0) 2992 if (err < 0)
2992 snd_printk("SI7018: the secondary codec - invalid access\n"); 2993 snd_printk(KERN_ERR "SI7018: the secondary codec - invalid access\n");
2993#if 0 // only for my testing purpose --jk 2994#if 0 // only for my testing purpose --jk
2994 { 2995 {
2995 ac97_t *mc97; 2996 ac97_t *mc97;
2996 err = snd_ac97_modem(trident->card, &_ac97, &mc97); 2997 err = snd_ac97_modem(trident->card, &_ac97, &mc97);
2997 if (err < 0) 2998 if (err < 0)
2998 snd_printk("snd_ac97_modem returned error %i\n", err); 2999 snd_printk(KERN_ERR "snd_ac97_modem returned error %i\n", err);
2999 } 3000 }
3000#endif 3001#endif
3001 } 3002 }
@@ -3206,8 +3207,7 @@ static inline void snd_trident_free_gameport(trident_t *chip) { }
3206 */ 3207 */
3207static inline void do_delay(trident_t *chip) 3208static inline void do_delay(trident_t *chip)
3208{ 3209{
3209 set_current_state(TASK_UNINTERRUPTIBLE); 3210 schedule_timeout_uninterruptible(1);
3210 schedule_timeout(1);
3211} 3211}
3212 3212
3213/* 3213/*
@@ -3243,7 +3243,7 @@ static int snd_trident_sis_reset(trident_t *trident)
3243 goto __si7018_ok; 3243 goto __si7018_ok;
3244 do_delay(trident); 3244 do_delay(trident);
3245 } while (time_after_eq(end_time, jiffies)); 3245 } while (time_after_eq(end_time, jiffies));
3246 snd_printk("AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL))); 3246 snd_printk(KERN_ERR "AC'97 codec ready error [0x%x]\n", inl(TRID_REG(trident, SI_SERIAL_INTF_CTRL)));
3247 if (r-- > 0) { 3247 if (r-- > 0) {
3248 end_time = jiffies + HZ; 3248 end_time = jiffies + HZ;
3249 do { 3249 do {
@@ -3541,7 +3541,7 @@ int __devinit snd_trident_create(snd_card_t * card,
3541 /* check, if we can restrict PCI DMA transfers to 30 bits */ 3541 /* check, if we can restrict PCI DMA transfers to 30 bits */
3542 if (pci_set_dma_mask(pci, 0x3fffffff) < 0 || 3542 if (pci_set_dma_mask(pci, 0x3fffffff) < 0 ||
3543 pci_set_consistent_dma_mask(pci, 0x3fffffff) < 0) { 3543 pci_set_consistent_dma_mask(pci, 0x3fffffff) < 0) {
3544 snd_printk("architecture does not support 30bit PCI busmaster DMA\n"); 3544 snd_printk(KERN_ERR "architecture does not support 30bit PCI busmaster DMA\n");
3545 pci_disable_device(pci); 3545 pci_disable_device(pci);
3546 return -ENXIO; 3546 return -ENXIO;
3547 } 3547 }
@@ -3578,7 +3578,7 @@ int __devinit snd_trident_create(snd_card_t * card,
3578 trident->port = pci_resource_start(pci, 0); 3578 trident->port = pci_resource_start(pci, 0);
3579 3579
3580 if (request_irq(pci->irq, snd_trident_interrupt, SA_INTERRUPT|SA_SHIRQ, "Trident Audio", (void *) trident)) { 3580 if (request_irq(pci->irq, snd_trident_interrupt, SA_INTERRUPT|SA_SHIRQ, "Trident Audio", (void *) trident)) {
3581 snd_printk("unable to grab IRQ %d\n", pci->irq); 3581 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
3582 snd_trident_free(trident); 3582 snd_trident_free(trident);
3583 return -EBUSY; 3583 return -EBUSY;
3584 } 3584 }
diff --git a/sound/pci/trident/trident_memory.c b/sound/pci/trident/trident_memory.c
index 333d3790692a..f3e6c546af74 100644
--- a/sound/pci/trident/trident_memory.c
+++ b/sound/pci/trident/trident_memory.c
@@ -170,11 +170,11 @@ __found_pages:
170static int is_valid_page(unsigned long ptr) 170static int is_valid_page(unsigned long ptr)
171{ 171{
172 if (ptr & ~0x3fffffffUL) { 172 if (ptr & ~0x3fffffffUL) {
173 snd_printk("max memory size is 1GB!!\n"); 173 snd_printk(KERN_ERR "max memory size is 1GB!!\n");
174 return 0; 174 return 0;
175 } 175 }
176 if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) { 176 if (ptr & (SNDRV_TRIDENT_PAGE_SIZE-1)) {
177 snd_printk("page is not aligned\n"); 177 snd_printk(KERN_ERR "page is not aligned\n");
178 return 0; 178 return 0;
179 } 179 }
180 return 1; 180 return 1;
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 3c0205b91e10..523eace250f7 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -41,6 +41,9 @@
41 * device for applications. 41 * device for applications.
42 * - clean up the code, separate low-level initialization 42 * - clean up the code, separate low-level initialization
43 * routines for each chipset. 43 * routines for each chipset.
44 *
45 * Sep. 26, 2005 Karsten Wiese <annabellesgarden@yahoo.de>
46 * - Optimize position calculation for the 823x chips.
44 */ 47 */
45 48
46#include <sound/driver.h> 49#include <sound/driver.h>
@@ -73,36 +76,37 @@ MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}");
73#define SUPPORT_JOYSTICK 1 76#define SUPPORT_JOYSTICK 1
74#endif 77#endif
75 78
76static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 79static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
77static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 80static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
78static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 81static long mpu_port;
79static long mpu_port[SNDRV_CARDS];
80#ifdef SUPPORT_JOYSTICK 82#ifdef SUPPORT_JOYSTICK
81static int joystick[SNDRV_CARDS]; 83static int joystick;
82#endif 84#endif
83static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000}; 85static int ac97_clock = 48000;
84static char *ac97_quirk[SNDRV_CARDS]; 86static char *ac97_quirk;
85static int dxs_support[SNDRV_CARDS]; 87static int dxs_support;
86 88
87module_param_array(index, int, NULL, 0444); 89module_param(index, int, 0444);
88MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge."); 90MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
89module_param_array(id, charp, NULL, 0444); 91module_param(id, charp, 0444);
90MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge."); 92MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
91module_param_array(enable, bool, NULL, 0444); 93module_param(mpu_port, long, 0444);
92MODULE_PARM_DESC(enable, "Enable audio part of VIA 82xx bridge.");
93module_param_array(mpu_port, long, NULL, 0444);
94MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)"); 94MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)");
95#ifdef SUPPORT_JOYSTICK 95#ifdef SUPPORT_JOYSTICK
96module_param_array(joystick, bool, NULL, 0444); 96module_param(joystick, bool, 0444);
97MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)"); 97MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)");
98#endif 98#endif
99module_param_array(ac97_clock, int, NULL, 0444); 99module_param(ac97_clock, int, 0444);
100MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 100MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
101module_param_array(ac97_quirk, charp, NULL, 0444); 101module_param(ac97_quirk, charp, 0444);
102MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware."); 102MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
103module_param_array(dxs_support, int, NULL, 0444); 103module_param(dxs_support, int, 0444);
104MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)"); 104MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)");
105 105
106/* just for backward compatibility */
107static int enable;
108module_param(enable, bool, 0444);
109
106 110
107/* revision numbers for via686 */ 111/* revision numbers for via686 */
108#define VIA_REV_686_A 0x10 112#define VIA_REV_686_A 0x10
@@ -130,6 +134,7 @@ MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2
130/* common offsets */ 134/* common offsets */
131#define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */ 135#define VIA_REG_OFFSET_STATUS 0x00 /* byte - channel status */
132#define VIA_REG_STAT_ACTIVE 0x80 /* RO */ 136#define VIA_REG_STAT_ACTIVE 0x80 /* RO */
137#define VIA8233_SHADOW_STAT_ACTIVE 0x08 /* RO */
133#define VIA_REG_STAT_PAUSED 0x40 /* RO */ 138#define VIA_REG_STAT_PAUSED 0x40 /* RO */
134#define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */ 139#define VIA_REG_STAT_TRIGGER_QUEUED 0x08 /* RO */
135#define VIA_REG_STAT_STOPPED 0x04 /* RWC */ 140#define VIA_REG_STAT_STOPPED 0x04 /* RWC */
@@ -328,6 +333,9 @@ struct via_dev {
328 unsigned int fragsize; 333 unsigned int fragsize;
329 unsigned int bufsize; 334 unsigned int bufsize;
330 unsigned int bufsize2; 335 unsigned int bufsize2;
336 int hwptr_done; /* processed frame position in the buffer */
337 int in_interrupt;
338 int shadow_shift;
331}; 339};
332 340
333 341
@@ -360,7 +368,8 @@ struct _snd_via82xx {
360 unsigned int mpu_port_saved; 368 unsigned int mpu_port_saved;
361#endif 369#endif
362 370
363 unsigned char playback_volume[2]; /* for VIA8233/C/8235; default = 0 */ 371 unsigned char playback_volume[4][2]; /* for VIA8233/C/8235; default = 0 */
372 unsigned char playback_volume_c[2]; /* for VIA8233/C/8235; default = 0 */
364 373
365 unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */ 374 unsigned int intr_mask; /* SGD_SHADOW mask to check interrupts */
366 375
@@ -393,8 +402,10 @@ struct _snd_via82xx {
393}; 402};
394 403
395static struct pci_device_id snd_via82xx_ids[] = { 404static struct pci_device_id snd_via82xx_ids[] = {
396 { 0x1106, 0x3058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */ 405 /* 0x1106, 0x3058 */
397 { 0x1106, 0x3059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */ 406 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA686, }, /* 686A */
407 /* 0x1106, 0x3059 */
408 { PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, TYPE_CARD_VIA8233, }, /* VT8233 */
398 { 0, } 409 { 0, }
399}; 410};
400 411
@@ -548,7 +559,7 @@ static void snd_via82xx_codec_write(ac97_t *ac97,
548{ 559{
549 via82xx_t *chip = ac97->private_data; 560 via82xx_t *chip = ac97->private_data;
550 unsigned int xval; 561 unsigned int xval;
551 562
552 xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY; 563 xval = !ac97->num ? VIA_REG_AC97_CODEC_ID_PRIMARY : VIA_REG_AC97_CODEC_ID_SECONDARY;
553 xval <<= VIA_REG_AC97_CODEC_ID_SHIFT; 564 xval <<= VIA_REG_AC97_CODEC_ID_SHIFT;
554 xval |= reg << VIA_REG_AC97_CMD_SHIFT; 565 xval |= reg << VIA_REG_AC97_CMD_SHIFT;
@@ -596,14 +607,15 @@ static void snd_via82xx_channel_reset(via82xx_t *chip, viadev_t *viadev)
596 outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */ 607 outb(0x00, VIADEV_REG(viadev, OFFSET_TYPE)); /* for via686 */
597 // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR)); 608 // outl(0, VIADEV_REG(viadev, OFFSET_CURR_PTR));
598 viadev->lastpos = 0; 609 viadev->lastpos = 0;
610 viadev->hwptr_done = 0;
599} 611}
600 612
601 613
602/* 614/*
603 * Interrupt handler 615 * Interrupt handler
616 * Used for 686 and 8233A
604 */ 617 */
605 618static irqreturn_t snd_via686_interrupt(int irq, void *dev_id, struct pt_regs *regs)
606static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
607{ 619{
608 via82xx_t *chip = dev_id; 620 via82xx_t *chip = dev_id;
609 unsigned int status; 621 unsigned int status;
@@ -622,13 +634,23 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs *
622 for (i = 0; i < chip->num_devs; i++) { 634 for (i = 0; i < chip->num_devs; i++) {
623 viadev_t *viadev = &chip->devs[i]; 635 viadev_t *viadev = &chip->devs[i];
624 unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS)); 636 unsigned char c_status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
625 c_status &= (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED); 637 if (! (c_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG|VIA_REG_STAT_STOPPED)))
626 if (! c_status)
627 continue; 638 continue;
628 if (viadev->substream && viadev->running) { 639 if (viadev->substream && viadev->running) {
640 /*
641 * Update hwptr_done based on 'period elapsed'
642 * interrupts. We'll use it, when the chip returns 0
643 * for OFFSET_CURR_COUNT.
644 */
645 if (c_status & VIA_REG_STAT_EOL)
646 viadev->hwptr_done = 0;
647 else
648 viadev->hwptr_done += viadev->fragsize;
649 viadev->in_interrupt = c_status;
629 spin_unlock(&chip->reg_lock); 650 spin_unlock(&chip->reg_lock);
630 snd_pcm_period_elapsed(viadev->substream); 651 snd_pcm_period_elapsed(viadev->substream);
631 spin_lock(&chip->reg_lock); 652 spin_lock(&chip->reg_lock);
653 viadev->in_interrupt = 0;
632 } 654 }
633 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */ 655 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
634 } 656 }
@@ -637,6 +659,60 @@ static irqreturn_t snd_via82xx_interrupt(int irq, void *dev_id, struct pt_regs *
637} 659}
638 660
639/* 661/*
662 * Interrupt handler
663 */
664static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id, struct pt_regs *regs)
665{
666 via82xx_t *chip = dev_id;
667 unsigned int status;
668 unsigned int i;
669 int irqreturn = 0;
670
671 /* check status for each stream */
672 spin_lock(&chip->reg_lock);
673 status = inl(VIAREG(chip, SGD_SHADOW));
674
675 for (i = 0; i < chip->num_devs; i++) {
676 viadev_t *viadev = &chip->devs[i];
677 snd_pcm_substream_t *substream;
678 unsigned char c_status, shadow_status;
679
680 shadow_status = (status >> viadev->shadow_shift) &
681 (VIA8233_SHADOW_STAT_ACTIVE|VIA_REG_STAT_EOL|
682 VIA_REG_STAT_FLAG);
683 c_status = shadow_status & (VIA_REG_STAT_EOL|VIA_REG_STAT_FLAG);
684 if (!c_status)
685 continue;
686
687 substream = viadev->substream;
688 if (substream && viadev->running) {
689 /*
690 * Update hwptr_done based on 'period elapsed'
691 * interrupts. We'll use it, when the chip returns 0
692 * for OFFSET_CURR_COUNT.
693 */
694 if (c_status & VIA_REG_STAT_EOL)
695 viadev->hwptr_done = 0;
696 else
697 viadev->hwptr_done += viadev->fragsize;
698 viadev->in_interrupt = c_status;
699 if (shadow_status & VIA8233_SHADOW_STAT_ACTIVE)
700 viadev->in_interrupt |= VIA_REG_STAT_ACTIVE;
701 spin_unlock(&chip->reg_lock);
702
703 snd_pcm_period_elapsed(substream);
704
705 spin_lock(&chip->reg_lock);
706 viadev->in_interrupt = 0;
707 }
708 outb(c_status, VIADEV_REG(viadev, OFFSET_STATUS)); /* ack */
709 irqreturn = 1;
710 }
711 spin_unlock(&chip->reg_lock);
712 return IRQ_RETVAL(irqreturn);
713}
714
715/*
640 * PCM callbacks 716 * PCM callbacks
641 */ 717 */
642 718
@@ -699,6 +775,8 @@ static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, u
699 size = viadev->idx_table[idx].size; 775 size = viadev->idx_table[idx].size;
700 base = viadev->idx_table[idx].offset; 776 base = viadev->idx_table[idx].offset;
701 res = base + size - count; 777 res = base + size - count;
778 if (res >= viadev->bufsize)
779 res -= viadev->bufsize;
702 780
703 /* check the validity of the calculated position */ 781 /* check the validity of the calculated position */
704 if (size < count) { 782 if (size < count) {
@@ -728,9 +806,6 @@ static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, u
728 } 806 }
729 } 807 }
730 } 808 }
731 viadev->lastpos = res; /* remember the last position */
732 if (res >= viadev->bufsize)
733 res -= viadev->bufsize;
734 return res; 809 return res;
735} 810}
736 811
@@ -758,6 +833,7 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(snd_pcm_substream_t *substream)
758 else /* CURR_PTR holds the address + 8 */ 833 else /* CURR_PTR holds the address + 8 */
759 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries; 834 idx = ((ptr - (unsigned int)viadev->table.addr) / 8 - 1) % viadev->tbl_entries;
760 res = calc_linear_pos(viadev, idx, count); 835 res = calc_linear_pos(viadev, idx, count);
836 viadev->lastpos = res; /* remember the last position */
761 spin_unlock(&chip->reg_lock); 837 spin_unlock(&chip->reg_lock);
762 838
763 return bytes_to_frames(substream->runtime, res); 839 return bytes_to_frames(substream->runtime, res);
@@ -771,30 +847,44 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(snd_pcm_substream_t *substream)
771 via82xx_t *chip = snd_pcm_substream_chip(substream); 847 via82xx_t *chip = snd_pcm_substream_chip(substream);
772 viadev_t *viadev = (viadev_t *)substream->runtime->private_data; 848 viadev_t *viadev = (viadev_t *)substream->runtime->private_data;
773 unsigned int idx, count, res; 849 unsigned int idx, count, res;
774 int timeout = 5000; 850 int status;
775 851
776 snd_assert(viadev->tbl_entries, return 0); 852 snd_assert(viadev->tbl_entries, return 0);
777 if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE)) 853
778 return 0;
779 spin_lock(&chip->reg_lock); 854 spin_lock(&chip->reg_lock);
780 do { 855 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
781 count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT)); 856 status = viadev->in_interrupt;
782 /* some mobos read 0 count */ 857 if (!status)
783 if ((count & 0xffffff) || ! viadev->running) 858 status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
784 break; 859
785 } while (--timeout); 860 if (!(status & VIA_REG_STAT_ACTIVE)) {
786 if (! timeout) 861 res = 0;
787 snd_printd(KERN_ERR "zero position is read\n"); 862 goto unlock;
788 idx = count >> 24; 863 }
789 if (idx >= viadev->tbl_entries) { 864 if (count & 0xffffff) {
865 idx = count >> 24;
866 if (idx >= viadev->tbl_entries) {
790#ifdef POINTER_DEBUG 867#ifdef POINTER_DEBUG
791 printk("fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries); 868 printk(KERN_DEBUG "fail: invalid idx = %i/%i\n", idx, viadev->tbl_entries);
792#endif 869#endif
793 res = viadev->lastpos; 870 res = viadev->lastpos;
871 } else {
872 count &= 0xffffff;
873 res = calc_linear_pos(viadev, idx, count);
874 }
794 } else { 875 } else {
795 count &= 0xffffff; 876 res = viadev->hwptr_done;
796 res = calc_linear_pos(viadev, idx, count); 877 if (!viadev->in_interrupt) {
797 } 878 if (status & VIA_REG_STAT_EOL) {
879 res = 0;
880 } else
881 if (status & VIA_REG_STAT_FLAG) {
882 res += viadev->fragsize;
883 }
884 }
885 }
886unlock:
887 viadev->lastpos = res;
798 spin_unlock(&chip->reg_lock); 888 spin_unlock(&chip->reg_lock);
799 889
800 return bytes_to_frames(substream->runtime, res); 890 return bytes_to_frames(substream->runtime, res);
@@ -936,8 +1026,8 @@ static int snd_via8233_playback_prepare(snd_pcm_substream_t *substream)
936 snd_assert((rbits & ~0xfffff) == 0, return -EINVAL); 1026 snd_assert((rbits & ~0xfffff) == 0, return -EINVAL);
937 snd_via82xx_channel_reset(chip, viadev); 1027 snd_via82xx_channel_reset(chip, viadev);
938 snd_via82xx_set_table_ptr(chip, viadev); 1028 snd_via82xx_set_table_ptr(chip, viadev);
939 outb(chip->playback_volume[0], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L)); 1029 outb(chip->playback_volume[viadev->reg_offset / 0x10][0], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_L));
940 outb(chip->playback_volume[1], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R)); 1030 outb(chip->playback_volume[viadev->reg_offset / 0x10][1], VIADEV_REG(viadev, OFS_PLAYBACK_VOLUME_R));
941 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */ 1031 outl((runtime->format == SNDRV_PCM_FORMAT_S16_LE ? VIA8233_REG_TYPE_16BIT : 0) | /* format */
942 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */ 1032 (runtime->channels > 1 ? VIA8233_REG_TYPE_STEREO : 0) | /* stereo */
943 rbits | /* rate */ 1033 rbits | /* rate */
@@ -1239,9 +1329,10 @@ static snd_pcm_ops_t snd_via8233_capture_ops = {
1239}; 1329};
1240 1330
1241 1331
1242static void init_viadev(via82xx_t *chip, int idx, unsigned int reg_offset, int direction) 1332static void init_viadev(via82xx_t *chip, int idx, unsigned int reg_offset, int shadow_pos, int direction)
1243{ 1333{
1244 chip->devs[idx].reg_offset = reg_offset; 1334 chip->devs[idx].reg_offset = reg_offset;
1335 chip->devs[idx].shadow_shift = shadow_pos * 4;
1245 chip->devs[idx].direction = direction; 1336 chip->devs[idx].direction = direction;
1246 chip->devs[idx].port = chip->port + reg_offset; 1337 chip->devs[idx].port = chip->port + reg_offset;
1247} 1338}
@@ -1271,9 +1362,9 @@ static int __devinit snd_via8233_pcm_new(via82xx_t *chip)
1271 chip->pcms[0] = pcm; 1362 chip->pcms[0] = pcm;
1272 /* set up playbacks */ 1363 /* set up playbacks */
1273 for (i = 0; i < 4; i++) 1364 for (i = 0; i < 4; i++)
1274 init_viadev(chip, i, 0x10 * i, 0); 1365 init_viadev(chip, i, 0x10 * i, i, 0);
1275 /* capture */ 1366 /* capture */
1276 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 1); 1367 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1277 1368
1278 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1369 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1279 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1370 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1289,9 +1380,9 @@ static int __devinit snd_via8233_pcm_new(via82xx_t *chip)
1289 strcpy(pcm->name, chip->card->shortname); 1380 strcpy(pcm->name, chip->card->shortname);
1290 chip->pcms[1] = pcm; 1381 chip->pcms[1] = pcm;
1291 /* set up playback */ 1382 /* set up playback */
1292 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 0); 1383 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1293 /* set up capture */ 1384 /* set up capture */
1294 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 1); 1385 init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
1295 1386
1296 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1387 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1297 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1388 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1324,9 +1415,9 @@ static int __devinit snd_via8233a_pcm_new(via82xx_t *chip)
1324 strcpy(pcm->name, chip->card->shortname); 1415 strcpy(pcm->name, chip->card->shortname);
1325 chip->pcms[0] = pcm; 1416 chip->pcms[0] = pcm;
1326 /* set up playback */ 1417 /* set up playback */
1327 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 0); 1418 init_viadev(chip, chip->multi_devno, VIA_REG_MULTPLAY_STATUS, 4, 0);
1328 /* capture */ 1419 /* capture */
1329 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 1); 1420 init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
1330 1421
1331 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1422 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1332 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1423 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1345,7 +1436,7 @@ static int __devinit snd_via8233a_pcm_new(via82xx_t *chip)
1345 strcpy(pcm->name, chip->card->shortname); 1436 strcpy(pcm->name, chip->card->shortname);
1346 chip->pcms[1] = pcm; 1437 chip->pcms[1] = pcm;
1347 /* set up playback */ 1438 /* set up playback */
1348 init_viadev(chip, chip->playback_devno, 0x30, 0); 1439 init_viadev(chip, chip->playback_devno, 0x30, 3, 0);
1349 1440
1350 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1441 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1351 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1442 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1375,8 +1466,8 @@ static int __devinit snd_via686_pcm_new(via82xx_t *chip)
1375 pcm->private_data = chip; 1466 pcm->private_data = chip;
1376 strcpy(pcm->name, chip->card->shortname); 1467 strcpy(pcm->name, chip->card->shortname);
1377 chip->pcms[0] = pcm; 1468 chip->pcms[0] = pcm;
1378 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0); 1469 init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
1379 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 1); 1470 init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
1380 1471
1381 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, 1472 if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1382 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0) 1473 snd_dma_pci_data(chip->pci), 64*1024, 128*1024)) < 0)
@@ -1497,14 +1588,46 @@ static int snd_via8233_dxs_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_in
1497static int snd_via8233_dxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1588static int snd_via8233_dxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1498{ 1589{
1499 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1590 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1500 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[0]; 1591 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id);
1501 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[1]; 1592
1593 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][0];
1594 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume[idx][1];
1595 return 0;
1596}
1597
1598static int snd_via8233_pcmdxs_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1599{
1600 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1601 ucontrol->value.integer.value[0] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[0];
1602 ucontrol->value.integer.value[1] = VIA_DXS_MAX_VOLUME - chip->playback_volume_c[1];
1502 return 0; 1603 return 0;
1503} 1604}
1504 1605
1505static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol) 1606static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1506{ 1607{
1507 via82xx_t *chip = snd_kcontrol_chip(kcontrol); 1608 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1609 unsigned int idx = snd_ctl_get_ioff(kcontrol, &ucontrol->id);
1610 unsigned long port = chip->port + 0x10 * idx;
1611 unsigned char val;
1612 int i, change = 0;
1613
1614 for (i = 0; i < 2; i++) {
1615 val = ucontrol->value.integer.value[i];
1616 if (val > VIA_DXS_MAX_VOLUME)
1617 val = VIA_DXS_MAX_VOLUME;
1618 val = VIA_DXS_MAX_VOLUME - val;
1619 change |= val != chip->playback_volume[idx][i];
1620 if (change) {
1621 chip->playback_volume[idx][i] = val;
1622 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
1623 }
1624 }
1625 return change;
1626}
1627
1628static int snd_via8233_pcmdxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
1629{
1630 via82xx_t *chip = snd_kcontrol_chip(kcontrol);
1508 unsigned int idx; 1631 unsigned int idx;
1509 unsigned char val; 1632 unsigned char val;
1510 int i, change = 0; 1633 int i, change = 0;
@@ -1514,11 +1637,12 @@ static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_val
1514 if (val > VIA_DXS_MAX_VOLUME) 1637 if (val > VIA_DXS_MAX_VOLUME)
1515 val = VIA_DXS_MAX_VOLUME; 1638 val = VIA_DXS_MAX_VOLUME;
1516 val = VIA_DXS_MAX_VOLUME - val; 1639 val = VIA_DXS_MAX_VOLUME - val;
1517 if (val != chip->playback_volume[i]) { 1640 if (val != chip->playback_volume_c[i]) {
1518 change = 1; 1641 change = 1;
1519 chip->playback_volume[i] = val; 1642 chip->playback_volume_c[i] = val;
1520 for (idx = 0; idx < 4; idx++) { 1643 for (idx = 0; idx < 4; idx++) {
1521 unsigned long port = chip->port + 0x10 * idx; 1644 unsigned long port = chip->port + 0x10 * idx;
1645 chip->playback_volume[idx][i] = val;
1522 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 1646 outb(val, port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
1523 } 1647 }
1524 } 1648 }
@@ -1526,10 +1650,19 @@ static int snd_via8233_dxs_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_val
1526 return change; 1650 return change;
1527} 1651}
1528 1652
1529static snd_kcontrol_new_t snd_via8233_dxs_volume_control __devinitdata = { 1653static snd_kcontrol_new_t snd_via8233_pcmdxs_volume_control __devinitdata = {
1530 .name = "PCM Playback Volume", 1654 .name = "PCM Playback Volume",
1531 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1655 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1532 .info = snd_via8233_dxs_volume_info, 1656 .info = snd_via8233_dxs_volume_info,
1657 .get = snd_via8233_pcmdxs_volume_get,
1658 .put = snd_via8233_pcmdxs_volume_put,
1659};
1660
1661static snd_kcontrol_new_t snd_via8233_dxs_volume_control __devinitdata = {
1662 .name = "VIA DXS Playback Volume",
1663 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1664 .count = 4,
1665 .info = snd_via8233_dxs_volume_info,
1533 .get = snd_via8233_dxs_volume_get, 1666 .get = snd_via8233_dxs_volume_get,
1534 .put = snd_via8233_dxs_volume_put, 1667 .put = snd_via8233_dxs_volume_put,
1535}; 1668};
@@ -1616,12 +1749,12 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, const char *quirk_ov
1616 return err; 1749 return err;
1617 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 1750 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
1618 chip->ac97_bus->clock = chip->ac97_clock; 1751 chip->ac97_bus->clock = chip->ac97_clock;
1619 chip->ac97_bus->shared_type = AC97_SHARED_TYPE_VIA;
1620 1752
1621 memset(&ac97, 0, sizeof(ac97)); 1753 memset(&ac97, 0, sizeof(ac97));
1622 ac97.private_data = chip; 1754 ac97.private_data = chip;
1623 ac97.private_free = snd_via82xx_mixer_free_ac97; 1755 ac97.private_free = snd_via82xx_mixer_free_ac97;
1624 ac97.pci = chip->pci; 1756 ac97.pci = chip->pci;
1757 ac97.scaps = AC97_SCAP_SKIP_MODEM;
1625 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) 1758 if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
1626 return err; 1759 return err;
1627 1760
@@ -1637,12 +1770,12 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, const char *quirk_ov
1637 1770
1638#ifdef SUPPORT_JOYSTICK 1771#ifdef SUPPORT_JOYSTICK
1639#define JOYSTICK_ADDR 0x200 1772#define JOYSTICK_ADDR 0x200
1640static int __devinit snd_via686_create_gameport(via82xx_t *chip, int dev, unsigned char *legacy) 1773static int __devinit snd_via686_create_gameport(via82xx_t *chip, unsigned char *legacy)
1641{ 1774{
1642 struct gameport *gp; 1775 struct gameport *gp;
1643 struct resource *r; 1776 struct resource *r;
1644 1777
1645 if (!joystick[dev]) 1778 if (!joystick)
1646 return -ENODEV; 1779 return -ENODEV;
1647 1780
1648 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport"); 1781 r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport");
@@ -1654,8 +1787,7 @@ static int __devinit snd_via686_create_gameport(via82xx_t *chip, int dev, unsign
1654 chip->gameport = gp = gameport_allocate_port(); 1787 chip->gameport = gp = gameport_allocate_port();
1655 if (!gp) { 1788 if (!gp) {
1656 printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n"); 1789 printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n");
1657 release_resource(r); 1790 release_and_free_resource(r);
1658 kfree_nocheck(r);
1659 return -ENOMEM; 1791 return -ENOMEM;
1660 } 1792 }
1661 1793
@@ -1681,12 +1813,11 @@ static void snd_via686_free_gameport(via82xx_t *chip)
1681 1813
1682 gameport_unregister_port(chip->gameport); 1814 gameport_unregister_port(chip->gameport);
1683 chip->gameport = NULL; 1815 chip->gameport = NULL;
1684 release_resource(r); 1816 release_and_free_resource(r);
1685 kfree_nocheck(r);
1686 } 1817 }
1687} 1818}
1688#else 1819#else
1689static inline int snd_via686_create_gameport(via82xx_t *chip, int dev, unsigned char *legacy) 1820static inline int snd_via686_create_gameport(via82xx_t *chip, unsigned char *legacy)
1690{ 1821{
1691 return -ENOSYS; 1822 return -ENOSYS;
1692} 1823}
@@ -1698,7 +1829,7 @@ static inline void snd_via686_free_gameport(via82xx_t *chip) { }
1698 * 1829 *
1699 */ 1830 */
1700 1831
1701static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev) 1832static int __devinit snd_via8233_init_misc(via82xx_t *chip)
1702{ 1833{
1703 int i, err, caps; 1834 int i, err, caps;
1704 unsigned char val; 1835 unsigned char val;
@@ -1724,12 +1855,19 @@ static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev)
1724 strcpy(sid.name, "PCM Playback Volume"); 1855 strcpy(sid.name, "PCM Playback Volume");
1725 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1856 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1726 if (! snd_ctl_find_id(chip->card, &sid)) { 1857 if (! snd_ctl_find_id(chip->card, &sid)) {
1858 snd_printd(KERN_INFO "Using DXS as PCM Playback\n");
1859 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_pcmdxs_volume_control, chip));
1860 if (err < 0)
1861 return err;
1862 }
1863 else /* Using DXS when PCM emulation is enabled is really weird */
1864 {
1865 /* Standalone DXS controls */
1727 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip)); 1866 err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_via8233_dxs_volume_control, chip));
1728 if (err < 0) 1867 if (err < 0)
1729 return err; 1868 return err;
1730 } 1869 }
1731 } 1870 }
1732
1733 /* select spdif data slot 10/11 */ 1871 /* select spdif data slot 10/11 */
1734 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val); 1872 pci_read_config_byte(chip->pci, VIA8233_SPDIF_CTRL, &val);
1735 val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011; 1873 val = (val & ~VIA8233_SPDIF_SLOT_MASK) | VIA8233_SPDIF_SLOT_1011;
@@ -1739,7 +1877,7 @@ static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev)
1739 return 0; 1877 return 0;
1740} 1878}
1741 1879
1742static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev) 1880static int __devinit snd_via686_init_misc(via82xx_t *chip)
1743{ 1881{
1744 unsigned char legacy, legacy_cfg; 1882 unsigned char legacy, legacy_cfg;
1745 int rev_h = 0; 1883 int rev_h = 0;
@@ -1750,32 +1888,33 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
1750 legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */ 1888 legacy &= ~VIA_FUNC_ENABLE_GAME; /* disable joystick */
1751 if (chip->revision >= VIA_REV_686_H) { 1889 if (chip->revision >= VIA_REV_686_H) {
1752 rev_h = 1; 1890 rev_h = 1;
1753 if (mpu_port[dev] >= 0x200) { /* force MIDI */ 1891 if (mpu_port >= 0x200) { /* force MIDI */
1754 mpu_port[dev] &= 0xfffc; 1892 mpu_port &= 0xfffc;
1755 pci_write_config_dword(chip->pci, 0x18, mpu_port[dev] | 0x01); 1893 pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01);
1756#ifdef CONFIG_PM 1894#ifdef CONFIG_PM
1757 chip->mpu_port_saved = mpu_port[dev]; 1895 chip->mpu_port_saved = mpu_port;
1758#endif 1896#endif
1759 } else { 1897 } else {
1760 mpu_port[dev] = pci_resource_start(chip->pci, 2); 1898 mpu_port = pci_resource_start(chip->pci, 2);
1761 } 1899 }
1762 } else { 1900 } else {
1763 switch (mpu_port[dev]) { /* force MIDI */ 1901 switch (mpu_port) { /* force MIDI */
1764 case 0x300: 1902 case 0x300:
1765 case 0x310: 1903 case 0x310:
1766 case 0x320: 1904 case 0x320:
1767 case 0x330: 1905 case 0x330:
1768 legacy_cfg &= ~(3 << 2); 1906 legacy_cfg &= ~(3 << 2);
1769 legacy_cfg |= (mpu_port[dev] & 0x0030) >> 2; 1907 legacy_cfg |= (mpu_port & 0x0030) >> 2;
1770 break; 1908 break;
1771 default: /* no, use BIOS settings */ 1909 default: /* no, use BIOS settings */
1772 if (legacy & VIA_FUNC_ENABLE_MIDI) 1910 if (legacy & VIA_FUNC_ENABLE_MIDI)
1773 mpu_port[dev] = 0x300 + ((legacy_cfg & 0x000c) << 2); 1911 mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2);
1774 break; 1912 break;
1775 } 1913 }
1776 } 1914 }
1777 if (mpu_port[dev] >= 0x200 && 1915 if (mpu_port >= 0x200 &&
1778 (chip->mpu_res = request_region(mpu_port[dev], 2, "VIA82xx MPU401")) != NULL) { 1916 (chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401"))
1917 != NULL) {
1779 if (rev_h) 1918 if (rev_h)
1780 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */ 1919 legacy |= VIA_FUNC_MIDI_PNP; /* enable PCI I/O 2 */
1781 legacy |= VIA_FUNC_ENABLE_MIDI; 1920 legacy |= VIA_FUNC_ENABLE_MIDI;
@@ -1783,16 +1922,17 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
1783 if (rev_h) 1922 if (rev_h)
1784 legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */ 1923 legacy &= ~VIA_FUNC_MIDI_PNP; /* disable PCI I/O 2 */
1785 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1924 legacy &= ~VIA_FUNC_ENABLE_MIDI;
1786 mpu_port[dev] = 0; 1925 mpu_port = 0;
1787 } 1926 }
1788 1927
1789 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1928 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
1790 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); 1929 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
1791 if (chip->mpu_res) { 1930 if (chip->mpu_res) {
1792 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, 1931 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
1793 mpu_port[dev], 1, 1932 mpu_port, 1,
1794 chip->irq, 0, &chip->rmidi) < 0) { 1933 chip->irq, 0, &chip->rmidi) < 0) {
1795 printk(KERN_WARNING "unable to initialize MPU-401 at 0x%lx, skipping\n", mpu_port[dev]); 1934 printk(KERN_WARNING "unable to initialize MPU-401"
1935 " at 0x%lx, skipping\n", mpu_port);
1796 legacy &= ~VIA_FUNC_ENABLE_MIDI; 1936 legacy &= ~VIA_FUNC_ENABLE_MIDI;
1797 } else { 1937 } else {
1798 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */ 1938 legacy &= ~VIA_FUNC_MIDI_IRQMASK; /* enable MIDI interrupt */
@@ -1800,7 +1940,7 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
1800 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy); 1940 pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
1801 } 1941 }
1802 1942
1803 snd_via686_create_gameport(chip, dev, &legacy); 1943 snd_via686_create_gameport(chip, &legacy);
1804 1944
1805#ifdef CONFIG_PM 1945#ifdef CONFIG_PM
1806 chip->legacy_saved = legacy; 1946 chip->legacy_saved = legacy;
@@ -1887,12 +2027,11 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
1887 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 2027 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
1888 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 2028 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */
1889 break; 2029 break;
1890 set_current_state(TASK_UNINTERRUPTIBLE); 2030 schedule_timeout_uninterruptible(1);
1891 schedule_timeout(1);
1892 } while (time_before(jiffies, end_time)); 2031 } while (time_before(jiffies, end_time));
1893 2032
1894 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 2033 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
1895 snd_printk("AC'97 codec is not ready [0x%x]\n", val); 2034 snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val);
1896 2035
1897#if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */ 2036#if 0 /* FIXME: we don't support the second codec yet so skip the detection now.. */
1898 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 2037 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
@@ -1907,8 +2046,7 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
1907 chip->ac97_secondary = 1; 2046 chip->ac97_secondary = 1;
1908 goto __ac97_ok2; 2047 goto __ac97_ok2;
1909 } 2048 }
1910 set_current_state(TASK_INTERRUPTIBLE); 2049 schedule_timeout_interruptible(1);
1911 schedule_timeout(1);
1912 } while (time_before(jiffies, end_time)); 2050 } while (time_before(jiffies, end_time));
1913 /* This is ok, the most of motherboards have only one codec */ 2051 /* This is ok, the most of motherboards have only one codec */
1914 2052
@@ -1940,8 +2078,10 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
1940 int i, idx; 2078 int i, idx;
1941 for (idx = 0; idx < 4; idx++) { 2079 for (idx = 0; idx < 4; idx++) {
1942 unsigned long port = chip->port + 0x10 * idx; 2080 unsigned long port = chip->port + 0x10 * idx;
1943 for (i = 0; i < 2; i++) 2081 for (i = 0; i < 2; i++) {
1944 outb(chip->playback_volume[i], port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i); 2082 chip->playback_volume[idx][i]=chip->playback_volume_c[i];
2083 outb(chip->playback_volume_c[i], port + VIA_REG_OFS_PLAYBACK_VOLUME_L + i);
2084 }
1945 } 2085 }
1946 } 2086 }
1947 2087
@@ -2020,10 +2160,7 @@ static int snd_via82xx_free(via82xx_t *chip)
2020 __end_hw: 2160 __end_hw:
2021 if (chip->irq >= 0) 2161 if (chip->irq >= 0)
2022 free_irq(chip->irq, (void *)chip); 2162 free_irq(chip->irq, (void *)chip);
2023 if (chip->mpu_res) { 2163 release_and_free_resource(chip->mpu_res);
2024 release_resource(chip->mpu_res);
2025 kfree_nocheck(chip->mpu_res);
2026 }
2027 pci_release_regions(chip->pci); 2164 pci_release_regions(chip->pci);
2028 2165
2029 if (chip->chip_type == TYPE_VIA686) { 2166 if (chip->chip_type == TYPE_VIA686) {
@@ -2084,9 +2221,12 @@ static int __devinit snd_via82xx_create(snd_card_t * card,
2084 return err; 2221 return err;
2085 } 2222 }
2086 chip->port = pci_resource_start(pci, 0); 2223 chip->port = pci_resource_start(pci, 0);
2087 if (request_irq(pci->irq, snd_via82xx_interrupt, SA_INTERRUPT|SA_SHIRQ, 2224 if (request_irq(pci->irq,
2225 chip_type == TYPE_VIA8233 ?
2226 snd_via8233_interrupt : snd_via686_interrupt,
2227 SA_INTERRUPT|SA_SHIRQ,
2088 card->driver, (void *)chip)) { 2228 card->driver, (void *)chip)) {
2089 snd_printk("unable to grab IRQ %d\n", pci->irq); 2229 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2090 snd_via82xx_free(chip); 2230 snd_via82xx_free(chip);
2091 return -EBUSY; 2231 return -EBUSY;
2092 } 2232 }
@@ -2178,6 +2318,7 @@ static int __devinit check_dxs_list(struct pci_dev *pci)
2178 { .subvendor = 0x147b, .subdevice = 0x1415, .action = VIA_DXS_NO_VRA }, /* Abit AV8 */ 2318 { .subvendor = 0x147b, .subdevice = 0x1415, .action = VIA_DXS_NO_VRA }, /* Abit AV8 */
2179 { .subvendor = 0x14ff, .subdevice = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */ 2319 { .subvendor = 0x14ff, .subdevice = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */
2180 { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */ 2320 { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */
2321 { .subvendor = 0x1558, .subdevice = 0x4701, .action = VIA_DXS_SRC }, /* Clevo D470 */
2181 { .subvendor = 0x1584, .subdevice = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */ 2322 { .subvendor = 0x1584, .subdevice = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */
2182 { .subvendor = 0x1584, .subdevice = 0x8123, .action = VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */ 2323 { .subvendor = 0x1584, .subdevice = 0x8123, .action = VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */
2183 { .subvendor = 0x161f, .subdevice = 0x202b, .action = VIA_DXS_NO_VRA }, /* Amira Note book */ 2324 { .subvendor = 0x161f, .subdevice = 0x202b, .action = VIA_DXS_NO_VRA }, /* Amira Note book */
@@ -2221,7 +2362,6 @@ static int __devinit check_dxs_list(struct pci_dev *pci)
2221static int __devinit snd_via82xx_probe(struct pci_dev *pci, 2362static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2222 const struct pci_device_id *pci_id) 2363 const struct pci_device_id *pci_id)
2223{ 2364{
2224 static int dev;
2225 snd_card_t *card; 2365 snd_card_t *card;
2226 via82xx_t *chip; 2366 via82xx_t *chip;
2227 unsigned char revision; 2367 unsigned char revision;
@@ -2229,14 +2369,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2229 unsigned int i; 2369 unsigned int i;
2230 int err; 2370 int err;
2231 2371
2232 if (dev >= SNDRV_CARDS) 2372 card = snd_card_new(index, id, THIS_MODULE, 0);
2233 return -ENODEV;
2234 if (!enable[dev]) {
2235 dev++;
2236 return -ENOENT;
2237 }
2238
2239 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
2240 if (card == NULL) 2373 if (card == NULL)
2241 return -ENOMEM; 2374 return -ENOMEM;
2242 2375
@@ -2259,12 +2392,12 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2259 } 2392 }
2260 } 2393 }
2261 if (chip_type != TYPE_VIA8233A) { 2394 if (chip_type != TYPE_VIA8233A) {
2262 if (dxs_support[dev] == VIA_DXS_AUTO) 2395 if (dxs_support == VIA_DXS_AUTO)
2263 dxs_support[dev] = check_dxs_list(pci); 2396 dxs_support = check_dxs_list(pci);
2264 /* force to use VIA8233 or 8233A model according to 2397 /* force to use VIA8233 or 8233A model according to
2265 * dxs_support module option 2398 * dxs_support module option
2266 */ 2399 */
2267 if (dxs_support[dev] == VIA_DXS_DISABLE) 2400 if (dxs_support == VIA_DXS_DISABLE)
2268 chip_type = TYPE_VIA8233A; 2401 chip_type = TYPE_VIA8233A;
2269 else 2402 else
2270 chip_type = TYPE_VIA8233; 2403 chip_type = TYPE_VIA8233;
@@ -2282,14 +2415,15 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2282 goto __error; 2415 goto __error;
2283 } 2416 }
2284 2417
2285 if ((err = snd_via82xx_create(card, pci, chip_type, revision, ac97_clock[dev], &chip)) < 0) 2418 if ((err = snd_via82xx_create(card, pci, chip_type, revision,
2419 ac97_clock, &chip)) < 0)
2286 goto __error; 2420 goto __error;
2287 if ((err = snd_via82xx_mixer_new(chip, ac97_quirk[dev])) < 0) 2421 if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0)
2288 goto __error; 2422 goto __error;
2289 2423
2290 if (chip_type == TYPE_VIA686) { 2424 if (chip_type == TYPE_VIA686) {
2291 if ((err = snd_via686_pcm_new(chip)) < 0 || 2425 if ((err = snd_via686_pcm_new(chip)) < 0 ||
2292 (err = snd_via686_init_misc(chip, dev)) < 0) 2426 (err = snd_via686_init_misc(chip)) < 0)
2293 goto __error; 2427 goto __error;
2294 } else { 2428 } else {
2295 if (chip_type == TYPE_VIA8233A) { 2429 if (chip_type == TYPE_VIA8233A) {
@@ -2299,16 +2433,16 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2299 } else { 2433 } else {
2300 if ((err = snd_via8233_pcm_new(chip)) < 0) 2434 if ((err = snd_via8233_pcm_new(chip)) < 0)
2301 goto __error; 2435 goto __error;
2302 if (dxs_support[dev] == VIA_DXS_48K) 2436 if (dxs_support == VIA_DXS_48K)
2303 chip->dxs_fixed = 1; 2437 chip->dxs_fixed = 1;
2304 else if (dxs_support[dev] == VIA_DXS_NO_VRA) 2438 else if (dxs_support == VIA_DXS_NO_VRA)
2305 chip->no_vra = 1; 2439 chip->no_vra = 1;
2306 else if (dxs_support[dev] == VIA_DXS_SRC) { 2440 else if (dxs_support == VIA_DXS_SRC) {
2307 chip->no_vra = 1; 2441 chip->no_vra = 1;
2308 chip->dxs_src = 1; 2442 chip->dxs_src = 1;
2309 } 2443 }
2310 } 2444 }
2311 if ((err = snd_via8233_init_misc(chip, dev)) < 0) 2445 if ((err = snd_via8233_init_misc(chip)) < 0)
2312 goto __error; 2446 goto __error;
2313 } 2447 }
2314 2448
@@ -2329,7 +2463,6 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2329 return err; 2463 return err;
2330 } 2464 }
2331 pci_set_drvdata(pci, card); 2465 pci_set_drvdata(pci, card);
2332 dev++;
2333 return 0; 2466 return 0;
2334 2467
2335 __error: 2468 __error:
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 7eac6f6ac737..011f0fb63bf9 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -26,7 +26,7 @@
26/* 26/*
27 * Changes: 27 * Changes:
28 * 28 *
29 * Sep. 2, 2004 Sasha Khapyorsky <sashak@smlink.com> 29 * Sep. 2, 2004 Sasha Khapyorsky <sashak@alsa-project.org>
30 * Modified from original audio driver 'via82xx.c' to support AC97 30 * Modified from original audio driver 'via82xx.c' to support AC97
31 * modems. 31 * modems.
32 */ 32 */
@@ -55,20 +55,21 @@ MODULE_DESCRIPTION("VIA VT82xx modem");
55MODULE_LICENSE("GPL"); 55MODULE_LICENSE("GPL");
56MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C modem,pci}}"); 56MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C modem,pci}}");
57 57
58static int index[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -2}; /* Exclude the first card */ 58static int index = -2; /* Exclude the first card */
59static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 59static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
60static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 60static int ac97_clock = 48000;
61static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000};
62 61
63module_param_array(index, int, NULL, 0444); 62module_param(index, int, 0444);
64MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge."); 63MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
65module_param_array(id, charp, NULL, 0444); 64module_param(id, charp, 0444);
66MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge."); 65MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
67module_param_array(enable, bool, NULL, 0444); 66module_param(ac97_clock, int, 0444);
68MODULE_PARM_DESC(enable, "Enable modem part of VIA 82xx bridge.");
69module_param_array(ac97_clock, int, NULL, 0444);
70MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz)."); 67MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
71 68
69/* just for backward compatibility */
70static int enable;
71module_param(enable, bool, 0444);
72
72 73
73/* 74/*
74 * Direct registers 75 * Direct registers
@@ -569,7 +570,7 @@ static inline unsigned int calc_linear_pos(viadev_t *viadev, unsigned int idx, u
569 res = viadev->lastpos; 570 res = viadev->lastpos;
570 } else if (check_invalid_pos(viadev, res)) { 571 } else if (check_invalid_pos(viadev, res)) {
571#ifdef POINTER_DEBUG 572#ifdef POINTER_DEBUG
572 printk("fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count); 573 printk(KERN_DEBUG "fail: idx = %i/%i, lastpos = 0x%x, bufsize2 = 0x%x, offsize = 0x%x, size = 0x%x, count = 0x%x\n", idx, viadev->tbl_entries, viadev->lastpos, viadev->bufsize2, viadev->idx_table[idx].offset, viadev->idx_table[idx].size, count);
573#endif 574#endif
574 if (count && size < count) { 575 if (count && size < count) {
575 snd_printd(KERN_ERR "invalid via82xx_cur_ptr, using last valid pointer\n"); 576 snd_printd(KERN_ERR "invalid via82xx_cur_ptr, using last valid pointer\n");
@@ -832,6 +833,7 @@ static int __devinit snd_via686_pcm_new(via82xx_t *chip)
832 return err; 833 return err;
833 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops); 834 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_via686_playback_ops);
834 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops); 835 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_via686_capture_ops);
836 pcm->dev_class = SNDRV_PCM_CLASS_MODEM;
835 pcm->private_data = chip; 837 pcm->private_data = chip;
836 strcpy(pcm->name, chip->card->shortname); 838 strcpy(pcm->name, chip->card->shortname);
837 chip->pcms[0] = pcm; 839 chip->pcms[0] = pcm;
@@ -878,7 +880,6 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip)
878 return err; 880 return err;
879 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus; 881 chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
880 chip->ac97_bus->clock = chip->ac97_clock; 882 chip->ac97_bus->clock = chip->ac97_clock;
881 chip->ac97_bus->shared_type = AC97_SHARED_TYPE_VIA;
882 883
883 memset(&ac97, 0, sizeof(ac97)); 884 memset(&ac97, 0, sizeof(ac97));
884 ac97.private_data = chip; 885 ac97.private_data = chip;
@@ -967,12 +968,11 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
967 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval); 968 pci_read_config_byte(chip->pci, VIA_ACLINK_STAT, &pval);
968 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */ 969 if (pval & VIA_ACLINK_C00_READY) /* primary codec ready */
969 break; 970 break;
970 set_current_state(TASK_UNINTERRUPTIBLE); 971 schedule_timeout_uninterruptible(1);
971 schedule_timeout(1);
972 } while (time_before(jiffies, end_time)); 972 } while (time_before(jiffies, end_time));
973 973
974 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY) 974 if ((val = snd_via82xx_codec_xread(chip)) & VIA_REG_AC97_BUSY)
975 snd_printk("AC'97 codec is not ready [0x%x]\n", val); 975 snd_printk(KERN_ERR "AC'97 codec is not ready [0x%x]\n", val);
976 976
977 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ | 977 snd_via82xx_codec_xwrite(chip, VIA_REG_AC97_READ |
978 VIA_REG_AC97_SECONDARY_VALID | 978 VIA_REG_AC97_SECONDARY_VALID |
@@ -986,8 +986,7 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
986 chip->ac97_secondary = 1; 986 chip->ac97_secondary = 1;
987 goto __ac97_ok2; 987 goto __ac97_ok2;
988 } 988 }
989 set_current_state(TASK_INTERRUPTIBLE); 989 schedule_timeout_interruptible(1);
990 schedule_timeout(1);
991 } while (time_before(jiffies, end_time)); 990 } while (time_before(jiffies, end_time));
992 /* This is ok, the most of motherboards have only one codec */ 991 /* This is ok, the most of motherboards have only one codec */
993 992
@@ -1101,7 +1100,7 @@ static int __devinit snd_via82xx_create(snd_card_t * card,
1101 chip->port = pci_resource_start(pci, 0); 1100 chip->port = pci_resource_start(pci, 0);
1102 if (request_irq(pci->irq, snd_via82xx_interrupt, SA_INTERRUPT|SA_SHIRQ, 1101 if (request_irq(pci->irq, snd_via82xx_interrupt, SA_INTERRUPT|SA_SHIRQ,
1103 card->driver, (void *)chip)) { 1102 card->driver, (void *)chip)) {
1104 snd_printk("unable to grab IRQ %d\n", pci->irq); 1103 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
1105 snd_via82xx_free(chip); 1104 snd_via82xx_free(chip);
1106 return -EBUSY; 1105 return -EBUSY;
1107 } 1106 }
@@ -1135,7 +1134,6 @@ static int __devinit snd_via82xx_create(snd_card_t * card,
1135static int __devinit snd_via82xx_probe(struct pci_dev *pci, 1134static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1136 const struct pci_device_id *pci_id) 1135 const struct pci_device_id *pci_id)
1137{ 1136{
1138 static int dev;
1139 snd_card_t *card; 1137 snd_card_t *card;
1140 via82xx_t *chip; 1138 via82xx_t *chip;
1141 unsigned char revision; 1139 unsigned char revision;
@@ -1143,14 +1141,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1143 unsigned int i; 1141 unsigned int i;
1144 int err; 1142 int err;
1145 1143
1146 if (dev >= SNDRV_CARDS) 1144 card = snd_card_new(index, id, THIS_MODULE, 0);
1147 return -ENODEV;
1148 if (!enable[dev]) {
1149 dev++;
1150 return -ENOENT;
1151 }
1152
1153 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
1154 if (card == NULL) 1145 if (card == NULL)
1155 return -ENOMEM; 1146 return -ENOMEM;
1156 1147
@@ -1167,7 +1158,8 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1167 goto __error; 1158 goto __error;
1168 } 1159 }
1169 1160
1170 if ((err = snd_via82xx_create(card, pci, chip_type, revision, ac97_clock[dev], &chip)) < 0) 1161 if ((err = snd_via82xx_create(card, pci, chip_type, revision,
1162 ac97_clock, &chip)) < 0)
1171 goto __error; 1163 goto __error;
1172 if ((err = snd_via82xx_mixer_new(chip)) < 0) 1164 if ((err = snd_via82xx_mixer_new(chip)) < 0)
1173 goto __error; 1165 goto __error;
@@ -1191,7 +1183,6 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1191 return err; 1183 return err;
1192 } 1184 }
1193 pci_set_drvdata(pci, card); 1185 pci_set_drvdata(pci, card);
1194 dev++;
1195 return 0; 1186 return 0;
1196 1187
1197 __error: 1188 __error:
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index 2e69abe51aa9..1bbba32517ff 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -130,8 +130,7 @@ static int __devinit snd_ymfpci_create_gameport(ymfpci_t *chip, int dev,
130 chip->gameport = gp = gameport_allocate_port(); 130 chip->gameport = gp = gameport_allocate_port();
131 if (!gp) { 131 if (!gp) {
132 printk(KERN_ERR "ymfpci: cannot allocate memory for gameport\n"); 132 printk(KERN_ERR "ymfpci: cannot allocate memory for gameport\n");
133 release_resource(r); 133 release_and_free_resource(r);
134 kfree_nocheck(r);
135 return -ENOMEM; 134 return -ENOMEM;
136 } 135 }
137 136
@@ -161,8 +160,7 @@ void snd_ymfpci_free_gameport(ymfpci_t *chip)
161 gameport_unregister_port(chip->gameport); 160 gameport_unregister_port(chip->gameport);
162 chip->gameport = NULL; 161 chip->gameport = NULL;
163 162
164 release_resource(r); 163 release_and_free_resource(r);
165 kfree_nocheck(r);
166 } 164 }
167} 165}
168#else 166#else
@@ -267,14 +265,8 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
267 old_legacy_ctrl, 265 old_legacy_ctrl,
268 &chip)) < 0) { 266 &chip)) < 0) {
269 snd_card_free(card); 267 snd_card_free(card);
270 if (mpu_res) { 268 release_and_free_resource(mpu_res);
271 release_resource(mpu_res); 269 release_and_free_resource(fm_res);
272 kfree_nocheck(mpu_res);
273 }
274 if (fm_res) {
275 release_resource(fm_res);
276 kfree_nocheck(fm_res);
277 }
278 return err; 270 return err;
279 } 271 }
280 chip->fm_res = fm_res; 272 chip->fm_res = fm_res;
@@ -328,7 +320,7 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
328 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); 320 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
329 } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { 321 } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
330 snd_card_free(card); 322 snd_card_free(card);
331 snd_printk("cannot create opl3 hwdep\n"); 323 snd_printk(KERN_ERR "cannot create opl3 hwdep\n");
332 return err; 324 return err;
333 } 325 }
334 } 326 }
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 27fa523639ae..88a43e091d77 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -92,9 +92,9 @@ static int snd_ymfpci_codec_ready(ymfpci_t *chip, int secondary)
92 if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0) 92 if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0)
93 return 0; 93 return 0;
94 set_current_state(TASK_UNINTERRUPTIBLE); 94 set_current_state(TASK_UNINTERRUPTIBLE);
95 schedule_timeout(1); 95 schedule_timeout_uninterruptible(1);
96 } while (time_before(jiffies, end_time)); 96 } while (time_before(jiffies, end_time));
97 snd_printk("codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); 97 snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg));
98 return -EBUSY; 98 return -EBUSY;
99} 99}
100 100
@@ -728,8 +728,7 @@ static void snd_ymfpci_irq_wait(ymfpci_t *chip)
728 init_waitqueue_entry(&wait, current); 728 init_waitqueue_entry(&wait, current);
729 add_wait_queue(&chip->interrupt_sleep, &wait); 729 add_wait_queue(&chip->interrupt_sleep, &wait);
730 atomic_inc(&chip->interrupt_sleep_count); 730 atomic_inc(&chip->interrupt_sleep_count);
731 set_current_state(TASK_UNINTERRUPTIBLE); 731 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
732 schedule_timeout(HZ/20);
733 remove_wait_queue(&chip->interrupt_sleep, &wait); 732 remove_wait_queue(&chip->interrupt_sleep, &wait);
734 } 733 }
735} 734}
@@ -1421,15 +1420,18 @@ static snd_kcontrol_new_t snd_ymfpci_drec_source __devinitdata = {
1421 * Mixer controls 1420 * Mixer controls
1422 */ 1421 */
1423 1422
1424#define YMFPCI_SINGLE(xname, xindex, reg) \ 1423#define YMFPCI_SINGLE(xname, xindex, reg, shift) \
1425{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 1424{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1426 .info = snd_ymfpci_info_single, \ 1425 .info = snd_ymfpci_info_single, \
1427 .get = snd_ymfpci_get_single, .put = snd_ymfpci_put_single, \ 1426 .get = snd_ymfpci_get_single, .put = snd_ymfpci_put_single, \
1428 .private_value = reg } 1427 .private_value = ((reg) | ((shift) << 16)) }
1429 1428
1430static int snd_ymfpci_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) 1429static int snd_ymfpci_info_single(snd_kcontrol_t *kcontrol,
1430 snd_ctl_elem_info_t *uinfo)
1431{ 1431{
1432 switch (kcontrol->private_value) { 1432 int reg = kcontrol->private_value & 0xffff;
1433
1434 switch (reg) {
1433 case YDSXGR_SPDIFOUTCTRL: break; 1435 case YDSXGR_SPDIFOUTCTRL: break;
1434 case YDSXGR_SPDIFINCTRL: break; 1436 case YDSXGR_SPDIFINCTRL: break;
1435 default: return -EINVAL; 1437 default: return -EINVAL;
@@ -1441,30 +1443,35 @@ static int snd_ymfpci_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
1441 return 0; 1443 return 0;
1442} 1444}
1443 1445
1444static int snd_ymfpci_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1446static int snd_ymfpci_get_single(snd_kcontrol_t *kcontrol,
1447 snd_ctl_elem_value_t *ucontrol)
1445{ 1448{
1446 ymfpci_t *chip = snd_kcontrol_chip(kcontrol); 1449 ymfpci_t *chip = snd_kcontrol_chip(kcontrol);
1447 int reg = kcontrol->private_value; 1450 int reg = kcontrol->private_value & 0xffff;
1448 unsigned int shift = 0, mask = 1; 1451 unsigned int shift = (kcontrol->private_value >> 16) & 0xff;
1452 unsigned int mask = 1;
1449 1453
1450 switch (kcontrol->private_value) { 1454 switch (reg) {
1451 case YDSXGR_SPDIFOUTCTRL: break; 1455 case YDSXGR_SPDIFOUTCTRL: break;
1452 case YDSXGR_SPDIFINCTRL: break; 1456 case YDSXGR_SPDIFINCTRL: break;
1453 default: return -EINVAL; 1457 default: return -EINVAL;
1454 } 1458 }
1455 ucontrol->value.integer.value[0] = (snd_ymfpci_readl(chip, reg) >> shift) & mask; 1459 ucontrol->value.integer.value[0] =
1460 (snd_ymfpci_readl(chip, reg) >> shift) & mask;
1456 return 0; 1461 return 0;
1457} 1462}
1458 1463
1459static int snd_ymfpci_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) 1464static int snd_ymfpci_put_single(snd_kcontrol_t *kcontrol,
1465 snd_ctl_elem_value_t *ucontrol)
1460{ 1466{
1461 ymfpci_t *chip = snd_kcontrol_chip(kcontrol); 1467 ymfpci_t *chip = snd_kcontrol_chip(kcontrol);
1462 int reg = kcontrol->private_value; 1468 int reg = kcontrol->private_value & 0xffff;
1463 unsigned int shift = 0, mask = 1; 1469 unsigned int shift = (kcontrol->private_value >> 16) & 0xff;
1470 unsigned int mask = 1;
1464 int change; 1471 int change;
1465 unsigned int val, oval; 1472 unsigned int val, oval;
1466 1473
1467 switch (kcontrol->private_value) { 1474 switch (reg) {
1468 case YDSXGR_SPDIFOUTCTRL: break; 1475 case YDSXGR_SPDIFOUTCTRL: break;
1469 case YDSXGR_SPDIFINCTRL: break; 1476 case YDSXGR_SPDIFINCTRL: break;
1470 default: return -EINVAL; 1477 default: return -EINVAL;
@@ -1583,8 +1590,9 @@ YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVO
1583YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL), 1590YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL),
1584YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL), 1591YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL),
1585YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,VOLUME), 1, YDSXGR_SPDIFLOOPVOL), 1592YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,VOLUME), 1, YDSXGR_SPDIFLOOPVOL),
1586YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, YDSXGR_SPDIFOUTCTRL), 1593YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, YDSXGR_SPDIFOUTCTRL, 0),
1587YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL), 1594YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL, 0),
1595YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("Loop",NONE,NONE), 0, YDSXGR_SPDIFINCTRL, 4),
1588{ 1596{
1589 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1597 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1590 .name = "4ch Duplication", 1598 .name = "4ch Duplication",
@@ -1842,9 +1850,7 @@ static int snd_ymfpci_timer_start(snd_timer_t *timer)
1842 unsigned int count; 1850 unsigned int count;
1843 1851
1844 chip = snd_timer_chip(timer); 1852 chip = snd_timer_chip(timer);
1845 count = timer->sticks - 1; 1853 count = (timer->sticks << 1) - 1;
1846 if (count == 0) /* minimum time is 20.8 us */
1847 count = 1;
1848 spin_lock_irqsave(&chip->reg_lock, flags); 1854 spin_lock_irqsave(&chip->reg_lock, flags);
1849 snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count); 1855 snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count);
1850 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03); 1856 snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03);
@@ -1868,14 +1874,14 @@ static int snd_ymfpci_timer_precise_resolution(snd_timer_t *timer,
1868 unsigned long *num, unsigned long *den) 1874 unsigned long *num, unsigned long *den)
1869{ 1875{
1870 *num = 1; 1876 *num = 1;
1871 *den = 96000; 1877 *den = 48000;
1872 return 0; 1878 return 0;
1873} 1879}
1874 1880
1875static struct _snd_timer_hardware snd_ymfpci_timer_hw = { 1881static struct _snd_timer_hardware snd_ymfpci_timer_hw = {
1876 .flags = SNDRV_TIMER_HW_AUTO, 1882 .flags = SNDRV_TIMER_HW_AUTO,
1877 .resolution = 10417, /* 1/2fs = 10.41666...us */ 1883 .resolution = 20833, /* 1/fs = 20.8333...us */
1878 .ticks = 65536, 1884 .ticks = 0x8000,
1879 .start = snd_ymfpci_timer_start, 1885 .start = snd_ymfpci_timer_start,
1880 .stop = snd_ymfpci_timer_stop, 1886 .stop = snd_ymfpci_timer_stop,
1881 .precise_resolution = snd_ymfpci_timer_precise_resolution, 1887 .precise_resolution = snd_ymfpci_timer_precise_resolution,
@@ -2142,14 +2148,8 @@ static int snd_ymfpci_free(ymfpci_t *chip)
2142#ifdef CONFIG_PM 2148#ifdef CONFIG_PM
2143 vfree(chip->saved_regs); 2149 vfree(chip->saved_regs);
2144#endif 2150#endif
2145 if (chip->mpu_res) { 2151 release_and_free_resource(chip->mpu_res);
2146 release_resource(chip->mpu_res); 2152 release_and_free_resource(chip->fm_res);
2147 kfree_nocheck(chip->mpu_res);
2148 }
2149 if (chip->fm_res) {
2150 release_resource(chip->fm_res);
2151 kfree_nocheck(chip->fm_res);
2152 }
2153 snd_ymfpci_free_gameport(chip); 2153 snd_ymfpci_free_gameport(chip);
2154 if (chip->reg_area_virt) 2154 if (chip->reg_area_virt)
2155 iounmap(chip->reg_area_virt); 2155 iounmap(chip->reg_area_virt);
@@ -2158,10 +2158,7 @@ static int snd_ymfpci_free(ymfpci_t *chip)
2158 2158
2159 if (chip->irq >= 0) 2159 if (chip->irq >= 0)
2160 free_irq(chip->irq, (void *)chip); 2160 free_irq(chip->irq, (void *)chip);
2161 if (chip->res_reg_area) { 2161 release_and_free_resource(chip->res_reg_area);
2162 release_resource(chip->res_reg_area);
2163 kfree_nocheck(chip->res_reg_area);
2164 }
2165 2162
2166 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl); 2163 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl);
2167 2164
@@ -2290,12 +2287,12 @@ int __devinit snd_ymfpci_create(snd_card_t * card,
2290 pci_set_master(pci); 2287 pci_set_master(pci);
2291 2288
2292 if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) { 2289 if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) {
2293 snd_printk("unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1); 2290 snd_printk(KERN_ERR "unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1);
2294 snd_ymfpci_free(chip); 2291 snd_ymfpci_free(chip);
2295 return -EBUSY; 2292 return -EBUSY;
2296 } 2293 }
2297 if (request_irq(pci->irq, snd_ymfpci_interrupt, SA_INTERRUPT|SA_SHIRQ, "YMFPCI", (void *) chip)) { 2294 if (request_irq(pci->irq, snd_ymfpci_interrupt, SA_INTERRUPT|SA_SHIRQ, "YMFPCI", (void *) chip)) {
2298 snd_printk("unable to grab IRQ %d\n", pci->irq); 2295 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
2299 snd_ymfpci_free(chip); 2296 snd_ymfpci_free(chip);
2300 return -EBUSY; 2297 return -EBUSY;
2301 } 2298 }