aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt7
-rw-r--r--include/sound/version.h2
-rw-r--r--sound/isa/Kconfig21
-rw-r--r--sound/isa/Makefile2
-rw-r--r--sound/isa/als100.c121
-rw-r--r--sound/isa/dt019x.c321
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c93
-rw-r--r--sound/isa/sb/sb_mixer.c330
-rw-r--r--sound/isa/wss/wss_lib.c80
-rw-r--r--sound/usb/Kconfig12
-rw-r--r--sound/usb/Makefile2
-rw-r--r--sound/usb/ua101.c1457
-rw-r--r--sound/usb/usbaudio.c54
-rw-r--r--sound/usb/usbaudio.h1
-rw-r--r--sound/usb/usbquirks.h31
15 files changed, 1792 insertions, 742 deletions
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index 8923597bd2bd..7a0a4a9dc18d 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -1791,6 +1791,13 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1791 1791
1792 The power-management is supported. 1792 The power-management is supported.
1793 1793
1794 Module snd-ua101
1795 ----------------
1796
1797 Module for the Edirol UA-101 audio/MIDI interface.
1798
1799 This module supports multiple devices, autoprobe and hotplugging.
1800
1794 Module snd-usb-audio 1801 Module snd-usb-audio
1795 -------------------- 1802 --------------------
1796 1803
diff --git a/include/sound/version.h b/include/sound/version.h
index 22939142dd23..1f5d4872d623 100644
--- a/include/sound/version.h
+++ b/include/sound/version.h
@@ -1,3 +1,3 @@
1/* include/version.h */ 1/* include/version.h */
2#define CONFIG_SND_VERSION "1.0.21" 2#define CONFIG_SND_VERSION "1.0.22"
3#define CONFIG_SND_DATE "" 3#define CONFIG_SND_DATE ""
diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig
index 02fe81ca88fd..194af3b01e13 100644
--- a/sound/isa/Kconfig
+++ b/sound/isa/Kconfig
@@ -63,15 +63,16 @@ config SND_AD1848
63 will be called snd-ad1848. 63 will be called snd-ad1848.
64 64
65config SND_ALS100 65config SND_ALS100
66 tristate "Avance Logic ALS100/ALS120" 66 tristate "Diamond Tech. DT-019x and Avance Logic ALSxxx"
67 depends on PNP 67 depends on PNP
68 select ISAPNP 68 select ISAPNP
69 select SND_OPL3_LIB 69 select SND_OPL3_LIB
70 select SND_MPU401_UART 70 select SND_MPU401_UART
71 select SND_SB16_DSP 71 select SND_SB16_DSP
72 help 72 help
73 Say Y here to include support for soundcards based on Avance 73 Say Y here to include support for soundcards based on the
74 Logic ALS100, ALS110, ALS120 and ALS200 chips. 74 Diamond Technologies DT-019X or Avance Logic chips: ALS007,
75 ALS100, ALS110, ALS120 and ALS200 chips.
75 76
76 To compile this driver as a module, choose M here: the module 77 To compile this driver as a module, choose M here: the module
77 will be called snd-als100. 78 will be called snd-als100.
@@ -127,20 +128,6 @@ config SND_CS4236
127 To compile this driver as a module, choose M here: the module 128 To compile this driver as a module, choose M here: the module
128 will be called snd-cs4236. 129 will be called snd-cs4236.
129 130
130config SND_DT019X
131 tristate "Diamond Technologies DT-019X, Avance Logic ALS-007"
132 depends on PNP
133 select ISAPNP
134 select SND_OPL3_LIB
135 select SND_MPU401_UART
136 select SND_SB16_DSP
137 help
138 Say Y here to include support for soundcards based on the
139 Diamond Technologies DT-019X or Avance Logic ALS-007 chips.
140
141 To compile this driver as a module, choose M here: the module
142 will be called snd-dt019x.
143
144config SND_ES968 131config SND_ES968
145 tristate "Generic ESS ES968 driver" 132 tristate "Generic ESS ES968 driver"
146 depends on PNP 133 depends on PNP
diff --git a/sound/isa/Makefile b/sound/isa/Makefile
index b906b9a1a81e..c73d30c4f462 100644
--- a/sound/isa/Makefile
+++ b/sound/isa/Makefile
@@ -7,7 +7,6 @@ snd-adlib-objs := adlib.o
7snd-als100-objs := als100.o 7snd-als100-objs := als100.o
8snd-azt2320-objs := azt2320.o 8snd-azt2320-objs := azt2320.o
9snd-cmi8330-objs := cmi8330.o 9snd-cmi8330-objs := cmi8330.o
10snd-dt019x-objs := dt019x.o
11snd-es18xx-objs := es18xx.o 10snd-es18xx-objs := es18xx.o
12snd-opl3sa2-objs := opl3sa2.o 11snd-opl3sa2-objs := opl3sa2.o
13snd-sc6000-objs := sc6000.o 12snd-sc6000-objs := sc6000.o
@@ -19,7 +18,6 @@ obj-$(CONFIG_SND_ADLIB) += snd-adlib.o
19obj-$(CONFIG_SND_ALS100) += snd-als100.o 18obj-$(CONFIG_SND_ALS100) += snd-als100.o
20obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o 19obj-$(CONFIG_SND_AZT2320) += snd-azt2320.o
21obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o 20obj-$(CONFIG_SND_CMI8330) += snd-cmi8330.o
22obj-$(CONFIG_SND_DT019X) += snd-dt019x.o
23obj-$(CONFIG_SND_ES18XX) += snd-es18xx.o 21obj-$(CONFIG_SND_ES18XX) += snd-es18xx.o
24obj-$(CONFIG_SND_OPL3SA2) += snd-opl3sa2.o 22obj-$(CONFIG_SND_OPL3SA2) += snd-opl3sa2.o
25obj-$(CONFIG_SND_SC6000) += snd-sc6000.o 23obj-$(CONFIG_SND_SC6000) += snd-sc6000.o
diff --git a/sound/isa/als100.c b/sound/isa/als100.c
index 5fd52e4d7079..20becc89f6f6 100644
--- a/sound/isa/als100.c
+++ b/sound/isa/als100.c
@@ -2,9 +2,13 @@
2/* 2/*
3 card-als100.c - driver for Avance Logic ALS100 based soundcards. 3 card-als100.c - driver for Avance Logic ALS100 based soundcards.
4 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it> 4 Copyright (C) 1999-2000 by Massimo Piccioni <dafastidio@libero.it>
5 Copyright (C) 1999-2002 by Massimo Piccioni <dafastidio@libero.it>
5 6
6 Thanks to Pierfrancesco 'qM2' Passerini. 7 Thanks to Pierfrancesco 'qM2' Passerini.
7 8
9 Generalised for soundcards based on DT-0196 and ALS-007 chips
10 by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
11
8 This program is free software; you can redistribute it and/or modify 12 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 13 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or 14 the Free Software Foundation; either version 2 of the License, or
@@ -33,10 +37,10 @@
33 37
34#define PFX "als100: " 38#define PFX "als100: "
35 39
36MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>"); 40MODULE_DESCRIPTION("Avance Logic ALS007/ALS1X0");
37MODULE_DESCRIPTION("Avance Logic ALS1X0"); 41MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
38MODULE_LICENSE("GPL"); 42 "{Avance Logic ALS-007}}"
39MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP}," 43 "{{Avance Logic,ALS100 - PRO16PNP},"
40 "{Avance Logic,ALS110}," 44 "{Avance Logic,ALS110},"
41 "{Avance Logic,ALS120}," 45 "{Avance Logic,ALS120},"
42 "{Avance Logic,ALS200}," 46 "{Avance Logic,ALS200},"
@@ -45,9 +49,12 @@ MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS100 - PRO16PNP},"
45 "{Avance Logic,ALS120}," 49 "{Avance Logic,ALS120},"
46 "{RTL,RTL3000}}"); 50 "{RTL,RTL3000}}");
47 51
52MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
53MODULE_LICENSE("GPL");
54
48static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 55static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
49static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 56static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
50static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ 57static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
51static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 58static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
52static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 59static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
53static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */ 60static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
@@ -57,14 +64,15 @@ static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
57static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */ 64static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
58 65
59module_param_array(index, int, NULL, 0444); 66module_param_array(index, int, NULL, 0444);
60MODULE_PARM_DESC(index, "Index value for als100 based soundcard."); 67MODULE_PARM_DESC(index, "Index value for Avance Logic based soundcard.");
61module_param_array(id, charp, NULL, 0444); 68module_param_array(id, charp, NULL, 0444);
62MODULE_PARM_DESC(id, "ID string for als100 based soundcard."); 69MODULE_PARM_DESC(id, "ID string for Avance Logic based soundcard.");
63module_param_array(enable, bool, NULL, 0444); 70module_param_array(enable, bool, NULL, 0444);
64MODULE_PARM_DESC(enable, "Enable als100 based soundcard."); 71MODULE_PARM_DESC(enable, "Enable Avance Logic based soundcard.");
72
73MODULE_ALIAS("snd-dt019x");
65 74
66struct snd_card_als100 { 75struct snd_card_als100 {
67 int dev_no;
68 struct pnp_dev *dev; 76 struct pnp_dev *dev;
69 struct pnp_dev *devmpu; 77 struct pnp_dev *devmpu;
70 struct pnp_dev *devopl; 78 struct pnp_dev *devopl;
@@ -72,25 +80,43 @@ struct snd_card_als100 {
72}; 80};
73 81
74static struct pnp_card_device_id snd_als100_pnpids[] = { 82static struct pnp_card_device_id snd_als100_pnpids[] = {
83 /* DT197A30 */
84 { .id = "RWB1688",
85 .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
86 .driver_data = SB_HW_DT019X },
87 /* DT0196 / ALS-007 */
88 { .id = "ALS0007",
89 .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
90 .driver_data = SB_HW_DT019X },
75 /* ALS100 - PRO16PNP */ 91 /* ALS100 - PRO16PNP */
76 { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } }, 92 { .id = "ALS0001",
93 .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } },
94 .driver_data = SB_HW_ALS100 },
77 /* ALS110 - MF1000 - Digimate 3D Sound */ 95 /* ALS110 - MF1000 - Digimate 3D Sound */
78 { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } } }, 96 { .id = "ALS0110",
97 .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" } },
98 .driver_data = SB_HW_ALS100 },
79 /* ALS120 */ 99 /* ALS120 */
80 { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } }, 100 { .id = "ALS0120",
101 .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
102 .driver_data = SB_HW_ALS100 },
81 /* ALS200 */ 103 /* ALS200 */
82 { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } } }, 104 { .id = "ALS0200",
105 .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" } },
106 .driver_data = SB_HW_ALS100 },
83 /* ALS200 OEM */ 107 /* ALS200 OEM */
84 { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } } }, 108 { .id = "ALS0200",
109 .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0020" } },
110 .driver_data = SB_HW_ALS100 },
85 /* RTL3000 */ 111 /* RTL3000 */
86 { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } } }, 112 { .id = "RTL3000",
87 { .id = "", } /* end */ 113 .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" } },
114 .driver_data = SB_HW_ALS100 },
115 { .id = "" } /* end */
88}; 116};
89 117
90MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids); 118MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
91 119
92#define DRIVER_NAME "snd-card-als100"
93
94static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard, 120static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
95 struct pnp_card_link *card, 121 struct pnp_card_link *card,
96 const struct pnp_card_device_id *id) 122 const struct pnp_card_device_id *id)
@@ -113,8 +139,12 @@ static int __devinit snd_card_als100_pnp(int dev, struct snd_card_als100 *acard,
113 return err; 139 return err;
114 } 140 }
115 port[dev] = pnp_port_start(pdev, 0); 141 port[dev] = pnp_port_start(pdev, 0);
116 dma8[dev] = pnp_dma(pdev, 1); 142 if (id->driver_data == SB_HW_DT019X)
117 dma16[dev] = pnp_dma(pdev, 0); 143 dma8[dev] = pnp_dma(pdev, 0);
144 else {
145 dma8[dev] = pnp_dma(pdev, 1);
146 dma16[dev] = pnp_dma(pdev, 0);
147 }
118 irq[dev] = pnp_irq(pdev, 0); 148 irq[dev] = pnp_irq(pdev, 0);
119 149
120 pdev = acard->devmpu; 150 pdev = acard->devmpu;
@@ -175,22 +205,33 @@ static int __devinit snd_card_als100_probe(int dev,
175 } 205 }
176 snd_card_set_dev(card, &pcard->card->dev); 206 snd_card_set_dev(card, &pcard->card->dev);
177 207
178 if ((error = snd_sbdsp_create(card, port[dev], 208 if (pid->driver_data == SB_HW_DT019X)
179 irq[dev], 209 dma16[dev] = -1;
180 snd_sb16dsp_interrupt, 210
181 dma8[dev], 211 error = snd_sbdsp_create(card, port[dev], irq[dev],
182 dma16[dev], 212 snd_sb16dsp_interrupt,
183 SB_HW_ALS100, &chip)) < 0) { 213 dma8[dev], dma16[dev],
214 pid->driver_data,
215 &chip);
216 if (error < 0) {
184 snd_card_free(card); 217 snd_card_free(card);
185 return error; 218 return error;
186 } 219 }
187 acard->chip = chip; 220 acard->chip = chip;
188 221
189 strcpy(card->driver, "ALS100"); 222 if (pid->driver_data == SB_HW_DT019X) {
190 strcpy(card->shortname, "Avance Logic ALS100"); 223 strcpy(card->driver, "DT-019X");
191 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d", 224 strcpy(card->shortname, "Diamond Tech. DT-019X");
192 card->shortname, chip->name, chip->port, 225 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
193 irq[dev], dma8[dev], dma16[dev]); 226 card->shortname, chip->name, chip->port,
227 irq[dev], dma8[dev]);
228 } else {
229 strcpy(card->driver, "ALS100");
230 strcpy(card->shortname, "Avance Logic ALS100");
231 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
232 card->shortname, chip->name, chip->port,
233 irq[dev], dma8[dev], dma16[dev]);
234 }
194 235
195 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) { 236 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
196 snd_card_free(card); 237 snd_card_free(card);
@@ -203,9 +244,19 @@ static int __devinit snd_card_als100_probe(int dev,
203 } 244 }
204 245
205 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { 246 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
206 if (snd_mpu401_uart_new(card, 0, MPU401_HW_ALS100, 247 int mpu_type = MPU401_HW_ALS100;
248
249 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
250 mpu_irq[dev] = -1;
251
252 if (pid->driver_data == SB_HW_DT019X)
253 mpu_type = MPU401_HW_MPU401;
254
255 if (snd_mpu401_uart_new(card, 0,
256 mpu_type,
207 mpu_port[dev], 0, 257 mpu_port[dev], 0,
208 mpu_irq[dev], IRQF_DISABLED, 258 mpu_irq[dev],
259 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
209 NULL) < 0) 260 NULL) < 0)
210 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]); 261 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
211 } 262 }
@@ -291,7 +342,7 @@ static int snd_als100_pnp_resume(struct pnp_card_link *pcard)
291 342
292static struct pnp_card_driver als100_pnpc_driver = { 343static struct pnp_card_driver als100_pnpc_driver = {
293 .flags = PNP_DRIVER_RES_DISABLE, 344 .flags = PNP_DRIVER_RES_DISABLE,
294 .name = "als100", 345 .name = "als100",
295 .id_table = snd_als100_pnpids, 346 .id_table = snd_als100_pnpids,
296 .probe = snd_als100_pnp_detect, 347 .probe = snd_als100_pnp_detect,
297 .remove = __devexit_p(snd_als100_pnp_remove), 348 .remove = __devexit_p(snd_als100_pnp_remove),
@@ -312,7 +363,7 @@ static int __init alsa_card_als100_init(void)
312 if (!als100_devices) { 363 if (!als100_devices) {
313 pnp_unregister_card_driver(&als100_pnpc_driver); 364 pnp_unregister_card_driver(&als100_pnpc_driver);
314#ifdef MODULE 365#ifdef MODULE
315 snd_printk(KERN_ERR "no ALS100 based soundcards found\n"); 366 snd_printk(KERN_ERR "no Avance Logic based soundcards found\n");
316#endif 367#endif
317 return -ENODEV; 368 return -ENODEV;
318 } 369 }
diff --git a/sound/isa/dt019x.c b/sound/isa/dt019x.c
deleted file mode 100644
index 80f5b1af9be8..000000000000
--- a/sound/isa/dt019x.c
+++ /dev/null
@@ -1,321 +0,0 @@
1
2/*
3 dt019x.c - driver for Diamond Technologies DT-0197H based soundcards.
4 Copyright (C) 1999, 2002 by Massimo Piccioni <dafastidio@libero.it>
5
6 Generalised for soundcards based on DT-0196 and ALS-007 chips
7 by Jonathan Woithe <jwoithe@physics.adelaide.edu.au>: June 2002.
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#include <linux/init.h>
25#include <linux/wait.h>
26#include <linux/pnp.h>
27#include <linux/moduleparam.h>
28#include <sound/core.h>
29#include <sound/initval.h>
30#include <sound/mpu401.h>
31#include <sound/opl3.h>
32#include <sound/sb.h>
33
34#define PFX "dt019x: "
35
36MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
37MODULE_DESCRIPTION("Diamond Technologies DT-019X / Avance Logic ALS-007");
38MODULE_LICENSE("GPL");
39MODULE_SUPPORTED_DEVICE("{{Diamond Technologies DT-019X},"
40 "{Avance Logic ALS-007}}");
41
42static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
43static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
44static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
45static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
46static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
47static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
48static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
49static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* PnP setup */
50static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* PnP setup */
51
52module_param_array(index, int, NULL, 0444);
53MODULE_PARM_DESC(index, "Index value for DT-019X based soundcard.");
54module_param_array(id, charp, NULL, 0444);
55MODULE_PARM_DESC(id, "ID string for DT-019X based soundcard.");
56module_param_array(enable, bool, NULL, 0444);
57MODULE_PARM_DESC(enable, "Enable DT-019X based soundcard.");
58
59struct snd_card_dt019x {
60 struct pnp_dev *dev;
61 struct pnp_dev *devmpu;
62 struct pnp_dev *devopl;
63 struct snd_sb *chip;
64};
65
66static struct pnp_card_device_id snd_dt019x_pnpids[] = {
67 /* DT197A30 */
68 { .id = "RWB1688", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
69 /* DT0196 / ALS-007 */
70 { .id = "ALS0007", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
71 { .id = "", }
72};
73
74MODULE_DEVICE_TABLE(pnp_card, snd_dt019x_pnpids);
75
76
77#define DRIVER_NAME "snd-card-dt019x"
78
79
80static int __devinit snd_card_dt019x_pnp(int dev, struct snd_card_dt019x *acard,
81 struct pnp_card_link *card,
82 const struct pnp_card_device_id *pid)
83{
84 struct pnp_dev *pdev;
85 int err;
86
87 acard->dev = pnp_request_card_device(card, pid->devs[0].id, NULL);
88 if (acard->dev == NULL)
89 return -ENODEV;
90
91 acard->devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
92 acard->devopl = pnp_request_card_device(card, pid->devs[2].id, NULL);
93
94 pdev = acard->dev;
95
96 err = pnp_activate_dev(pdev);
97 if (err < 0) {
98 snd_printk(KERN_ERR PFX "DT-019X AUDIO pnp configure failure\n");
99 return err;
100 }
101
102 port[dev] = pnp_port_start(pdev, 0);
103 dma8[dev] = pnp_dma(pdev, 0);
104 irq[dev] = pnp_irq(pdev, 0);
105 snd_printdd("dt019x: found audio interface: port=0x%lx, irq=0x%x, dma=0x%x\n",
106 port[dev],irq[dev],dma8[dev]);
107
108 pdev = acard->devmpu;
109 if (pdev != NULL) {
110 err = pnp_activate_dev(pdev);
111 if (err < 0) {
112 pnp_release_card_device(pdev);
113 snd_printk(KERN_ERR PFX "DT-019X MPU401 pnp configure failure, skipping\n");
114 goto __mpu_error;
115 }
116 mpu_port[dev] = pnp_port_start(pdev, 0);
117 mpu_irq[dev] = pnp_irq(pdev, 0);
118 snd_printdd("dt019x: found MPU-401: port=0x%lx, irq=0x%x\n",
119 mpu_port[dev],mpu_irq[dev]);
120 } else {
121 __mpu_error:
122 acard->devmpu = NULL;
123 mpu_port[dev] = -1;
124 }
125
126 pdev = acard->devopl;
127 if (pdev != NULL) {
128 err = pnp_activate_dev(pdev);
129 if (err < 0) {
130 pnp_release_card_device(pdev);
131 snd_printk(KERN_ERR PFX "DT-019X OPL3 pnp configure failure, skipping\n");
132 goto __fm_error;
133 }
134 fm_port[dev] = pnp_port_start(pdev, 0);
135 snd_printdd("dt019x: found OPL3 synth: port=0x%lx\n",fm_port[dev]);
136 } else {
137 __fm_error:
138 acard->devopl = NULL;
139 fm_port[dev] = -1;
140 }
141
142 return 0;
143}
144
145static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard, const struct pnp_card_device_id *pid)
146{
147 int error;
148 struct snd_sb *chip;
149 struct snd_card *card;
150 struct snd_card_dt019x *acard;
151 struct snd_opl3 *opl3;
152
153 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
154 sizeof(struct snd_card_dt019x), &card);
155 if (error < 0)
156 return error;
157 acard = card->private_data;
158
159 snd_card_set_dev(card, &pcard->card->dev);
160 if ((error = snd_card_dt019x_pnp(dev, acard, pcard, pid))) {
161 snd_card_free(card);
162 return error;
163 }
164
165 if ((error = snd_sbdsp_create(card, port[dev],
166 irq[dev],
167 snd_sb16dsp_interrupt,
168 dma8[dev],
169 -1,
170 SB_HW_DT019X,
171 &chip)) < 0) {
172 snd_card_free(card);
173 return error;
174 }
175 acard->chip = chip;
176
177 strcpy(card->driver, "DT-019X");
178 strcpy(card->shortname, "Diamond Tech. DT-019X");
179 sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
180 card->shortname, chip->name, chip->port,
181 irq[dev], dma8[dev]);
182
183 if ((error = snd_sb16dsp_pcm(chip, 0, NULL)) < 0) {
184 snd_card_free(card);
185 return error;
186 }
187 if ((error = snd_sbmixer_new(chip)) < 0) {
188 snd_card_free(card);
189 return error;
190 }
191
192 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
193 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
194 mpu_irq[dev] = -1;
195 if (snd_mpu401_uart_new(card, 0,
196/* MPU401_HW_SB,*/
197 MPU401_HW_MPU401,
198 mpu_port[dev], 0,
199 mpu_irq[dev],
200 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
201 NULL) < 0)
202 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx ?\n", mpu_port[dev]);
203 }
204
205 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
206 if (snd_opl3_create(card,
207 fm_port[dev],
208 fm_port[dev] + 2,
209 OPL3_HW_AUTO, 0, &opl3) < 0) {
210 snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx ?\n",
211 fm_port[dev], fm_port[dev] + 2);
212 } else {
213 if ((error = snd_opl3_timer_new(opl3, 0, 1)) < 0) {
214 snd_card_free(card);
215 return error;
216 }
217 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
218 snd_card_free(card);
219 return error;
220 }
221 }
222 }
223
224 if ((error = snd_card_register(card)) < 0) {
225 snd_card_free(card);
226 return error;
227 }
228 pnp_set_card_drvdata(pcard, card);
229 return 0;
230}
231
232static unsigned int __devinitdata dt019x_devices;
233
234static int __devinit snd_dt019x_pnp_probe(struct pnp_card_link *card,
235 const struct pnp_card_device_id *pid)
236{
237 static int dev;
238 int res;
239
240 for ( ; dev < SNDRV_CARDS; dev++) {
241 if (!enable[dev])
242 continue;
243 res = snd_card_dt019x_probe(dev, card, pid);
244 if (res < 0)
245 return res;
246 dev++;
247 dt019x_devices++;
248 return 0;
249 }
250 return -ENODEV;
251}
252
253static void __devexit snd_dt019x_pnp_remove(struct pnp_card_link * pcard)
254{
255 snd_card_free(pnp_get_card_drvdata(pcard));
256 pnp_set_card_drvdata(pcard, NULL);
257}
258
259#ifdef CONFIG_PM
260static int snd_dt019x_pnp_suspend(struct pnp_card_link *pcard, pm_message_t state)
261{
262 struct snd_card *card = pnp_get_card_drvdata(pcard);
263 struct snd_card_dt019x *acard = card->private_data;
264 struct snd_sb *chip = acard->chip;
265
266 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
267 snd_pcm_suspend_all(chip->pcm);
268 snd_sbmixer_suspend(chip);
269 return 0;
270}
271
272static int snd_dt019x_pnp_resume(struct pnp_card_link *pcard)
273{
274 struct snd_card *card = pnp_get_card_drvdata(pcard);
275 struct snd_card_dt019x *acard = card->private_data;
276 struct snd_sb *chip = acard->chip;
277
278 snd_sbdsp_reset(chip);
279 snd_sbmixer_resume(chip);
280 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
281 return 0;
282}
283#endif
284
285static struct pnp_card_driver dt019x_pnpc_driver = {
286 .flags = PNP_DRIVER_RES_DISABLE,
287 .name = "dt019x",
288 .id_table = snd_dt019x_pnpids,
289 .probe = snd_dt019x_pnp_probe,
290 .remove = __devexit_p(snd_dt019x_pnp_remove),
291#ifdef CONFIG_PM
292 .suspend = snd_dt019x_pnp_suspend,
293 .resume = snd_dt019x_pnp_resume,
294#endif
295};
296
297static int __init alsa_card_dt019x_init(void)
298{
299 int err;
300
301 err = pnp_register_card_driver(&dt019x_pnpc_driver);
302 if (err)
303 return err;
304
305 if (!dt019x_devices) {
306 pnp_unregister_card_driver(&dt019x_pnpc_driver);
307#ifdef MODULE
308 snd_printk(KERN_ERR "no DT-019X / ALS-007 based soundcards found\n");
309#endif
310 return -ENODEV;
311 }
312 return 0;
313}
314
315static void __exit alsa_card_dt019x_exit(void)
316{
317 pnp_unregister_card_driver(&dt019x_pnpc_driver);
318}
319
320module_init(alsa_card_dt019x_init)
321module_exit(alsa_card_dt019x_exit)
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index c8a8da0d4036..a4af53b5c1cf 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -33,6 +33,7 @@
33#include <asm/io.h> 33#include <asm/io.h>
34#include <asm/dma.h> 34#include <asm/dma.h>
35#include <sound/core.h> 35#include <sound/core.h>
36#include <sound/tlv.h>
36#include <sound/wss.h> 37#include <sound/wss.h>
37#include <sound/mpu401.h> 38#include <sound/mpu401.h>
38#include <sound/opl3.h> 39#include <sound/opl3.h>
@@ -546,6 +547,93 @@ __skip_mpu:
546 547
547#ifdef OPTi93X 548#ifdef OPTi93X
548 549
550static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
551static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
552static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
553
554static struct snd_kcontrol_new snd_opti93x_controls[] = {
555WSS_DOUBLE("Master Playback Switch", 0,
556 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
557WSS_DOUBLE_TLV("Master Playback Volume", 0,
558 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
559 db_scale_5bit_3db_step),
560WSS_DOUBLE_TLV("PCM Playback Volume", 0,
561 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
562 db_scale_5bit),
563WSS_DOUBLE_TLV("FM Playback Volume", 0,
564 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
565 db_scale_4bit_12db_max),
566WSS_DOUBLE("Line Playback Switch", 0,
567 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
568WSS_DOUBLE_TLV("Line Playback Volume", 0,
569 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
570 db_scale_4bit_12db_max),
571WSS_DOUBLE("Mic Playback Switch", 0,
572 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
573WSS_DOUBLE_TLV("Mic Playback Volume", 0,
574 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
575 db_scale_4bit_12db_max),
576WSS_DOUBLE_TLV("CD Playback Volume", 0,
577 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
578 db_scale_4bit_12db_max),
579WSS_DOUBLE("Aux Playback Switch", 0,
580 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
581WSS_DOUBLE_TLV("Aux Playback Volume", 0,
582 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
583 db_scale_4bit_12db_max),
584};
585
586static int __devinit snd_opti93x_mixer(struct snd_wss *chip)
587{
588 struct snd_card *card;
589 unsigned int idx;
590 struct snd_ctl_elem_id id1, id2;
591 int err;
592
593 if (snd_BUG_ON(!chip || !chip->pcm))
594 return -EINVAL;
595
596 card = chip->card;
597
598 strcpy(card->mixername, chip->pcm->name);
599
600 memset(&id1, 0, sizeof(id1));
601 memset(&id2, 0, sizeof(id2));
602 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
603 /* reassign AUX0 switch to CD */
604 strcpy(id1.name, "Aux Playback Switch");
605 strcpy(id2.name, "CD Playback Switch");
606 err = snd_ctl_rename_id(card, &id1, &id2);
607 if (err < 0) {
608 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
609 return err;
610 }
611 /* reassign AUX1 switch to FM */
612 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
613 strcpy(id2.name, "FM Playback Switch");
614 err = snd_ctl_rename_id(card, &id1, &id2);
615 if (err < 0) {
616 snd_printk(KERN_ERR "Cannot rename opti93x control\n");
617 return err;
618 }
619 /* remove AUX1 volume */
620 strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
621 snd_ctl_remove_id(card, &id1);
622
623 /* Replace WSS volume controls with OPTi93x volume controls */
624 id1.index = 0;
625 for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
626 strcpy(id1.name, snd_opti93x_controls[idx].name);
627 snd_ctl_remove_id(card, &id1);
628
629 err = snd_ctl_add(card,
630 snd_ctl_new1(&snd_opti93x_controls[idx], chip));
631 if (err < 0)
632 return err;
633 }
634 return 0;
635}
636
549static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id) 637static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
550{ 638{
551 struct snd_opti9xx *chip = dev_id; 639 struct snd_opti9xx *chip = dev_id;
@@ -754,6 +842,11 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
754 error = snd_wss_mixer(codec); 842 error = snd_wss_mixer(codec);
755 if (error < 0) 843 if (error < 0)
756 return error; 844 return error;
845#ifdef OPTi93X
846 error = snd_opti93x_mixer(codec);
847 if (error < 0)
848 return error;
849#endif
757#ifdef CS4231 850#ifdef CS4231
758 error = snd_wss_timer(codec, 0, &timer); 851 error = snd_wss_timer(codec, 0, &timer);
759 if (error < 0) 852 if (error < 0)
diff --git a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c
index 318ff0c823e7..8cfc41fbe368 100644
--- a/sound/isa/sb/sb_mixer.c
+++ b/sound/isa/sb/sb_mixer.c
@@ -528,20 +528,11 @@ int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int ty
528 * SB 2.0 specific mixer elements 528 * SB 2.0 specific mixer elements
529 */ 529 */
530 530
531static struct sbmix_elem snd_sb20_ctl_master_play_vol = 531static struct sbmix_elem snd_sb20_controls[] = {
532 SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7); 532 SB_SINGLE("Master Playback Volume", SB_DSP20_MASTER_DEV, 1, 7),
533static struct sbmix_elem snd_sb20_ctl_pcm_play_vol = 533 SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3),
534 SB_SINGLE("PCM Playback Volume", SB_DSP20_PCM_DEV, 1, 3); 534 SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7),
535static struct sbmix_elem snd_sb20_ctl_synth_play_vol = 535 SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7)
536 SB_SINGLE("Synth Playback Volume", SB_DSP20_FM_DEV, 1, 7);
537static struct sbmix_elem snd_sb20_ctl_cd_play_vol =
538 SB_SINGLE("CD Playback Volume", SB_DSP20_CD_DEV, 1, 7);
539
540static struct sbmix_elem *snd_sb20_controls[] = {
541 &snd_sb20_ctl_master_play_vol,
542 &snd_sb20_ctl_pcm_play_vol,
543 &snd_sb20_ctl_synth_play_vol,
544 &snd_sb20_ctl_cd_play_vol
545}; 536};
546 537
547static unsigned char snd_sb20_init_values[][2] = { 538static unsigned char snd_sb20_init_values[][2] = {
@@ -552,41 +543,24 @@ static unsigned char snd_sb20_init_values[][2] = {
552/* 543/*
553 * SB Pro specific mixer elements 544 * SB Pro specific mixer elements
554 */ 545 */
555static struct sbmix_elem snd_sbpro_ctl_master_play_vol = 546static struct sbmix_elem snd_sbpro_controls[] = {
556 SB_DOUBLE("Master Playback Volume", SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7); 547 SB_DOUBLE("Master Playback Volume",
557static struct sbmix_elem snd_sbpro_ctl_pcm_play_vol = 548 SB_DSP_MASTER_DEV, SB_DSP_MASTER_DEV, 5, 1, 7),
558 SB_DOUBLE("PCM Playback Volume", SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7); 549 SB_DOUBLE("PCM Playback Volume",
559static struct sbmix_elem snd_sbpro_ctl_pcm_play_filter = 550 SB_DSP_PCM_DEV, SB_DSP_PCM_DEV, 5, 1, 7),
560 SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1); 551 SB_SINGLE("PCM Playback Filter", SB_DSP_PLAYBACK_FILT, 5, 1),
561static struct sbmix_elem snd_sbpro_ctl_synth_play_vol = 552 SB_DOUBLE("Synth Playback Volume",
562 SB_DOUBLE("Synth Playback Volume", SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7); 553 SB_DSP_FM_DEV, SB_DSP_FM_DEV, 5, 1, 7),
563static struct sbmix_elem snd_sbpro_ctl_cd_play_vol = 554 SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7),
564 SB_DOUBLE("CD Playback Volume", SB_DSP_CD_DEV, SB_DSP_CD_DEV, 5, 1, 7); 555 SB_DOUBLE("Line Playback Volume",
565static struct sbmix_elem snd_sbpro_ctl_line_play_vol = 556 SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7),
566 SB_DOUBLE("Line Playback Volume", SB_DSP_LINE_DEV, SB_DSP_LINE_DEV, 5, 1, 7); 557 SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3),
567static struct sbmix_elem snd_sbpro_ctl_mic_play_vol =
568 SB_SINGLE("Mic Playback Volume", SB_DSP_MIC_DEV, 1, 3);
569static struct sbmix_elem snd_sbpro_ctl_capture_source =
570 { 558 {
571 .name = "Capture Source", 559 .name = "Capture Source",
572 .type = SB_MIX_CAPTURE_PRO 560 .type = SB_MIX_CAPTURE_PRO
573 }; 561 },
574static struct sbmix_elem snd_sbpro_ctl_capture_filter = 562 SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1),
575 SB_SINGLE("Capture Filter", SB_DSP_CAPTURE_FILT, 5, 1); 563 SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1)
576static struct sbmix_elem snd_sbpro_ctl_capture_low_filter =
577 SB_SINGLE("Capture Low-Pass Filter", SB_DSP_CAPTURE_FILT, 3, 1);
578
579static struct sbmix_elem *snd_sbpro_controls[] = {
580 &snd_sbpro_ctl_master_play_vol,
581 &snd_sbpro_ctl_pcm_play_vol,
582 &snd_sbpro_ctl_pcm_play_filter,
583 &snd_sbpro_ctl_synth_play_vol,
584 &snd_sbpro_ctl_cd_play_vol,
585 &snd_sbpro_ctl_line_play_vol,
586 &snd_sbpro_ctl_mic_play_vol,
587 &snd_sbpro_ctl_capture_source,
588 &snd_sbpro_ctl_capture_filter,
589 &snd_sbpro_ctl_capture_low_filter
590}; 564};
591 565
592static unsigned char snd_sbpro_init_values[][2] = { 566static unsigned char snd_sbpro_init_values[][2] = {
@@ -598,68 +572,42 @@ static unsigned char snd_sbpro_init_values[][2] = {
598/* 572/*
599 * SB16 specific mixer elements 573 * SB16 specific mixer elements
600 */ 574 */
601static struct sbmix_elem snd_sb16_ctl_master_play_vol = 575static struct sbmix_elem snd_sb16_controls[] = {
602 SB_DOUBLE("Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31); 576 SB_DOUBLE("Master Playback Volume",
603static struct sbmix_elem snd_sb16_ctl_3d_enhance_switch = 577 SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31),
604 SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1); 578 SB_DOUBLE("PCM Playback Volume",
605static struct sbmix_elem snd_sb16_ctl_tone_bass = 579 SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31),
606 SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15); 580 SB16_INPUT_SW("Synth Capture Route",
607static struct sbmix_elem snd_sb16_ctl_tone_treble = 581 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5),
608 SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15); 582 SB_DOUBLE("Synth Playback Volume",
609static struct sbmix_elem snd_sb16_ctl_pcm_play_vol = 583 SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31),
610 SB_DOUBLE("PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31); 584 SB16_INPUT_SW("CD Capture Route",
611static struct sbmix_elem snd_sb16_ctl_synth_capture_route = 585 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1),
612 SB16_INPUT_SW("Synth Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 6, 5); 586 SB_DOUBLE("CD Playback Switch",
613static struct sbmix_elem snd_sb16_ctl_synth_play_vol = 587 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
614 SB_DOUBLE("Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31); 588 SB_DOUBLE("CD Playback Volume",
615static struct sbmix_elem snd_sb16_ctl_cd_capture_route = 589 SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31),
616 SB16_INPUT_SW("CD Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 2, 1); 590 SB16_INPUT_SW("Mic Capture Route",
617static struct sbmix_elem snd_sb16_ctl_cd_play_switch = 591 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0),
618 SB_DOUBLE("CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1); 592 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
619static struct sbmix_elem snd_sb16_ctl_cd_play_vol = 593 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
620 SB_DOUBLE("CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31); 594 SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
621static struct sbmix_elem snd_sb16_ctl_line_capture_route = 595 SB_DOUBLE("Capture Volume",
622 SB16_INPUT_SW("Line Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3); 596 SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
623static struct sbmix_elem snd_sb16_ctl_line_play_switch = 597 SB_DOUBLE("Playback Volume",
624 SB_DOUBLE("Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1); 598 SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
625static struct sbmix_elem snd_sb16_ctl_line_play_vol = 599 SB16_INPUT_SW("Line Capture Route",
626 SB_DOUBLE("Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31); 600 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 4, 3),
627static struct sbmix_elem snd_sb16_ctl_mic_capture_route = 601 SB_DOUBLE("Line Playback Switch",
628 SB16_INPUT_SW("Mic Capture Route", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0); 602 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
629static struct sbmix_elem snd_sb16_ctl_mic_play_switch = 603 SB_DOUBLE("Line Playback Volume",
630 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1); 604 SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
631static struct sbmix_elem snd_sb16_ctl_mic_play_vol = 605 SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
632 SB_SINGLE("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31); 606 SB_SINGLE("3D Enhancement Switch", SB_DSP4_3DSE, 0, 1),
633static struct sbmix_elem snd_sb16_ctl_pc_speaker_vol = 607 SB_DOUBLE("Tone Control - Bass",
634 SB_SINGLE("Beep Volume", SB_DSP4_SPEAKER_DEV, 6, 3); 608 SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15),
635static struct sbmix_elem snd_sb16_ctl_capture_vol = 609 SB_DOUBLE("Tone Control - Treble",
636 SB_DOUBLE("Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3); 610 SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15)
637static struct sbmix_elem snd_sb16_ctl_play_vol =
638 SB_DOUBLE("Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3);
639static struct sbmix_elem snd_sb16_ctl_auto_mic_gain =
640 SB_SINGLE("Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1);
641
642static struct sbmix_elem *snd_sb16_controls[] = {
643 &snd_sb16_ctl_master_play_vol,
644 &snd_sb16_ctl_3d_enhance_switch,
645 &snd_sb16_ctl_tone_bass,
646 &snd_sb16_ctl_tone_treble,
647 &snd_sb16_ctl_pcm_play_vol,
648 &snd_sb16_ctl_synth_capture_route,
649 &snd_sb16_ctl_synth_play_vol,
650 &snd_sb16_ctl_cd_capture_route,
651 &snd_sb16_ctl_cd_play_switch,
652 &snd_sb16_ctl_cd_play_vol,
653 &snd_sb16_ctl_line_capture_route,
654 &snd_sb16_ctl_line_play_switch,
655 &snd_sb16_ctl_line_play_vol,
656 &snd_sb16_ctl_mic_capture_route,
657 &snd_sb16_ctl_mic_play_switch,
658 &snd_sb16_ctl_mic_play_vol,
659 &snd_sb16_ctl_pc_speaker_vol,
660 &snd_sb16_ctl_capture_vol,
661 &snd_sb16_ctl_play_vol,
662 &snd_sb16_ctl_auto_mic_gain
663}; 611};
664 612
665static unsigned char snd_sb16_init_values[][2] = { 613static unsigned char snd_sb16_init_values[][2] = {
@@ -678,46 +626,34 @@ static unsigned char snd_sb16_init_values[][2] = {
678/* 626/*
679 * DT019x specific mixer elements 627 * DT019x specific mixer elements
680 */ 628 */
681static struct sbmix_elem snd_dt019x_ctl_master_play_vol = 629static struct sbmix_elem snd_dt019x_controls[] = {
682 SB_DOUBLE("Master Playback Volume", SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4,0, 15); 630 /* ALS4000 below has some parts which we might be lacking,
683static struct sbmix_elem snd_dt019x_ctl_pcm_play_vol = 631 * e.g. snd_als4000_ctl_mono_playback_switch - check it! */
684 SB_DOUBLE("PCM Playback Volume", SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4,0, 15); 632 SB_DOUBLE("Master Playback Volume",
685static struct sbmix_elem snd_dt019x_ctl_synth_play_vol = 633 SB_DT019X_MASTER_DEV, SB_DT019X_MASTER_DEV, 4, 0, 15),
686 SB_DOUBLE("Synth Playback Volume", SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4,0, 15); 634 SB_DOUBLE("PCM Playback Switch",
687static struct sbmix_elem snd_dt019x_ctl_cd_play_vol = 635 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2, 1, 1),
688 SB_DOUBLE("CD Playback Volume", SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4,0, 15); 636 SB_DOUBLE("PCM Playback Volume",
689static struct sbmix_elem snd_dt019x_ctl_mic_play_vol = 637 SB_DT019X_PCM_DEV, SB_DT019X_PCM_DEV, 4, 0, 15),
690 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7); 638 SB_DOUBLE("Synth Playback Switch",
691static struct sbmix_elem snd_dt019x_ctl_pc_speaker_vol = 639 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4, 3, 1),
692 SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV, 0, 7); 640 SB_DOUBLE("Synth Playback Volume",
693static struct sbmix_elem snd_dt019x_ctl_line_play_vol = 641 SB_DT019X_SYNTH_DEV, SB_DT019X_SYNTH_DEV, 4, 0, 15),
694 SB_DOUBLE("Line Playback Volume", SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4,0, 15); 642 SB_DOUBLE("CD Playback Switch",
695static struct sbmix_elem snd_dt019x_ctl_pcm_play_switch = 643 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
696 SB_DOUBLE("PCM Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2,1, 1); 644 SB_DOUBLE("CD Playback Volume",
697static struct sbmix_elem snd_dt019x_ctl_synth_play_switch = 645 SB_DT019X_CD_DEV, SB_DT019X_CD_DEV, 4, 0, 15),
698 SB_DOUBLE("Synth Playback Switch", SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4,3, 1); 646 SB_SINGLE("Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
699static struct sbmix_elem snd_dt019x_ctl_capture_source = 647 SB_SINGLE("Mic Playback Volume", SB_DT019X_MIC_DEV, 4, 7),
648 SB_SINGLE("Beep Volume", SB_DT019X_SPKR_DEV, 0, 7),
649 SB_DOUBLE("Line Playback Switch",
650 SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
651 SB_DOUBLE("Line Playback Volume",
652 SB_DT019X_LINE_DEV, SB_DT019X_LINE_DEV, 4, 0, 15),
700 { 653 {
701 .name = "Capture Source", 654 .name = "Capture Source",
702 .type = SB_MIX_CAPTURE_DT019X 655 .type = SB_MIX_CAPTURE_DT019X
703 }; 656 }
704
705static struct sbmix_elem *snd_dt019x_controls[] = {
706 /* ALS4000 below has some parts which we might be lacking,
707 * e.g. snd_als4000_ctl_mono_playback_switch - check it! */
708 &snd_dt019x_ctl_master_play_vol,
709 &snd_dt019x_ctl_pcm_play_vol,
710 &snd_dt019x_ctl_synth_play_vol,
711 &snd_dt019x_ctl_cd_play_vol,
712 &snd_dt019x_ctl_mic_play_vol,
713 &snd_dt019x_ctl_pc_speaker_vol,
714 &snd_dt019x_ctl_line_play_vol,
715 &snd_sb16_ctl_mic_play_switch,
716 &snd_sb16_ctl_cd_play_switch,
717 &snd_sb16_ctl_line_play_switch,
718 &snd_dt019x_ctl_pcm_play_switch,
719 &snd_dt019x_ctl_synth_play_switch,
720 &snd_dt019x_ctl_capture_source
721}; 657};
722 658
723static unsigned char snd_dt019x_init_values[][2] = { 659static unsigned char snd_dt019x_init_values[][2] = {
@@ -735,82 +671,37 @@ static unsigned char snd_dt019x_init_values[][2] = {
735/* 671/*
736 * ALS4000 specific mixer elements 672 * ALS4000 specific mixer elements
737 */ 673 */
738static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch = 674static struct sbmix_elem snd_als4000_controls[] = {
739 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1); 675 SB_DOUBLE("PCM Playback Switch",
740static struct sbmix_elem snd_als4k_ctl_master_mono_capture_route = { 676 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 2, 1, 1),
677 SB_DOUBLE("Synth Playback Switch",
678 SB_DT019X_OUTPUT_SW2, SB_DT019X_OUTPUT_SW2, 4, 3, 1),
679 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03),
680 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1),
681 {
741 .name = "Master Mono Capture Route", 682 .name = "Master Mono Capture Route",
742 .type = SB_MIX_MONO_CAPTURE_ALS4K 683 .type = SB_MIX_MONO_CAPTURE_ALS4K
743 }; 684 },
744static struct sbmix_elem snd_als4000_ctl_mono_playback_switch = 685 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1),
745 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1); 686 SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN, 7, 0x01),
746static struct sbmix_elem snd_als4000_ctl_mic_20db_boost = 687 SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01),
747 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03);
748static struct sbmix_elem snd_als4000_ctl_mixer_analog_loopback =
749 SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN, 7, 0x01);
750static struct sbmix_elem snd_als4000_ctl_mixer_digital_loopback =
751 SB_SINGLE("Digital Loopback Switch", 688 SB_SINGLE("Digital Loopback Switch",
752 SB_ALS4000_CR3_CONFIGURATION, 7, 0x01); 689 SB_ALS4000_CR3_CONFIGURATION, 7, 0x01),
753/* FIXME: functionality of 3D controls might be swapped, I didn't find 690 /* FIXME: functionality of 3D controls might be swapped, I didn't find
754 * a description of how to identify what is supposed to be what */ 691 * a description of how to identify what is supposed to be what */
755static struct sbmix_elem snd_als4000_3d_control_switch = 692 SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07),
756 SB_SINGLE("3D Control - Switch", SB_ALS4000_3D_SND_FX, 6, 0x01);
757static struct sbmix_elem snd_als4000_3d_control_ratio =
758 SB_SINGLE("3D Control - Level", SB_ALS4000_3D_SND_FX, 0, 0x07);
759static struct sbmix_elem snd_als4000_3d_control_freq =
760 /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */ 693 /* FIXME: maybe there's actually some standard 3D ctrl name for it?? */
761 SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03); 694 SB_SINGLE("3D Control - Freq", SB_ALS4000_3D_SND_FX, 4, 0x03),
762static struct sbmix_elem snd_als4000_3d_control_delay =
763 /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay, 695 /* FIXME: ALS4000a.pdf mentions BBD (Bucket Brigade Device) time delay,
764 * but what ALSA 3D attribute is that actually? "Center", "Depth", 696 * but what ALSA 3D attribute is that actually? "Center", "Depth",
765 * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */ 697 * "Wide" or "Space" or even "Level"? Assuming "Wide" for now... */
766 SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f); 698 SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f),
767static struct sbmix_elem snd_als4000_3d_control_poweroff_switch = 699 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01),
768 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01);
769static struct sbmix_elem snd_als4000_ctl_3db_freq_control_switch =
770 SB_SINGLE("Master Playback 8kHz / 20kHz LPF Switch", 700 SB_SINGLE("Master Playback 8kHz / 20kHz LPF Switch",
771 SB_ALS4000_FMDAC, 5, 0x01); 701 SB_ALS4000_FMDAC, 5, 0x01),
772#ifdef NOT_AVAILABLE 702#ifdef NOT_AVAILABLE
773static struct sbmix_elem snd_als4000_ctl_fmdac = 703 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01),
774 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01); 704 SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f),
775static struct sbmix_elem snd_als4000_ctl_qsound =
776 SB_SINGLE("QSound Mode", SB_ALS4000_QSOUND, 1, 0x1f);
777#endif
778
779static struct sbmix_elem *snd_als4000_controls[] = {
780 /* ALS4000a.PDF regs page */
781 &snd_sb16_ctl_master_play_vol, /* MX30/31 12 */
782 &snd_dt019x_ctl_pcm_play_switch, /* MX4C 16 */
783 &snd_sb16_ctl_pcm_play_vol, /* MX32/33 12 */
784 &snd_sb16_ctl_synth_capture_route, /* MX3D/3E 14 */
785 &snd_dt019x_ctl_synth_play_switch, /* MX4C 16 */
786 &snd_sb16_ctl_synth_play_vol, /* MX34/35 12/13 */
787 &snd_sb16_ctl_cd_capture_route, /* MX3D/3E 14 */
788 &snd_sb16_ctl_cd_play_switch, /* MX3C 14 */
789 &snd_sb16_ctl_cd_play_vol, /* MX36/37 13 */
790 &snd_sb16_ctl_line_capture_route, /* MX3D/3E 14 */
791 &snd_sb16_ctl_line_play_switch, /* MX3C 14 */
792 &snd_sb16_ctl_line_play_vol, /* MX38/39 13 */
793 &snd_sb16_ctl_mic_capture_route, /* MX3D/3E 14 */
794 &snd_als4000_ctl_mic_20db_boost, /* MX4D 16 */
795 &snd_sb16_ctl_mic_play_switch, /* MX3C 14 */
796 &snd_sb16_ctl_mic_play_vol, /* MX3A 13 */
797 &snd_sb16_ctl_pc_speaker_vol, /* MX3B 14 */
798 &snd_sb16_ctl_capture_vol, /* MX3F/40 15 */
799 &snd_sb16_ctl_play_vol, /* MX41/42 15 */
800 &snd_als4000_ctl_master_mono_playback_switch, /* MX4C 16 */
801 &snd_als4k_ctl_master_mono_capture_route, /* MX4B 16 */
802 &snd_als4000_ctl_mono_playback_switch, /* MX4C 16 */
803 &snd_als4000_ctl_mixer_analog_loopback, /* MX4D 16 */
804 &snd_als4000_ctl_mixer_digital_loopback, /* CR3 21 */
805 &snd_als4000_3d_control_switch, /* MX50 17 */
806 &snd_als4000_3d_control_ratio, /* MX50 17 */
807 &snd_als4000_3d_control_freq, /* MX50 17 */
808 &snd_als4000_3d_control_delay, /* MX51 18 */
809 &snd_als4000_3d_control_poweroff_switch, /* MX51 18 */
810 &snd_als4000_ctl_3db_freq_control_switch, /* MX4F 17 */
811#ifdef NOT_AVAILABLE
812 &snd_als4000_ctl_fmdac,
813 &snd_als4000_ctl_qsound,
814#endif 705#endif
815}; 706};
816 707
@@ -829,11 +720,10 @@ static unsigned char snd_als4000_init_values[][2] = {
829 { SB_ALS4000_MIC_IN_GAIN, 0 }, 720 { SB_ALS4000_MIC_IN_GAIN, 0 },
830}; 721};
831 722
832
833/* 723/*
834 */ 724 */
835static int snd_sbmixer_init(struct snd_sb *chip, 725static int snd_sbmixer_init(struct snd_sb *chip,
836 struct sbmix_elem **controls, 726 struct sbmix_elem *controls,
837 int controls_count, 727 int controls_count,
838 unsigned char map[][2], 728 unsigned char map[][2],
839 int map_count, 729 int map_count,
@@ -856,7 +746,8 @@ static int snd_sbmixer_init(struct snd_sb *chip,
856 } 746 }
857 747
858 for (idx = 0; idx < controls_count; idx++) { 748 for (idx = 0; idx < controls_count; idx++) {
859 if ((err = snd_sbmixer_add_ctl_elem(chip, controls[idx])) < 0) 749 err = snd_sbmixer_add_ctl_elem(chip, &controls[idx]);
750 if (err < 0)
860 return err; 751 return err;
861 } 752 }
862 snd_component_add(card, name); 753 snd_component_add(card, name);
@@ -908,6 +799,15 @@ int snd_sbmixer_new(struct snd_sb *chip)
908 return err; 799 return err;
909 break; 800 break;
910 case SB_HW_ALS4000: 801 case SB_HW_ALS4000:
802 /* use only the first 16 controls from SB16 */
803 err = snd_sbmixer_init(chip,
804 snd_sb16_controls,
805 16,
806 snd_sb16_init_values,
807 ARRAY_SIZE(snd_sb16_init_values),
808 "ALS4000");
809 if (err < 0)
810 return err;
911 if ((err = snd_sbmixer_init(chip, 811 if ((err = snd_sbmixer_init(chip,
912 snd_als4000_controls, 812 snd_als4000_controls,
913 ARRAY_SIZE(snd_als4000_controls), 813 ARRAY_SIZE(snd_als4000_controls),
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 5b9d6c18bc45..9191b32d9130 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -2014,6 +2014,7 @@ static int snd_wss_info_mux(struct snd_kcontrol *kcontrol,
2014 case WSS_HW_INTERWAVE: 2014 case WSS_HW_INTERWAVE:
2015 ptexts = gusmax_texts; 2015 ptexts = gusmax_texts;
2016 break; 2016 break;
2017 case WSS_HW_OPTI93X:
2017 case WSS_HW_OPL3SA2: 2018 case WSS_HW_OPL3SA2:
2018 ptexts = opl3sa_texts; 2019 ptexts = opl3sa_texts;
2019 break; 2020 break;
@@ -2246,54 +2247,12 @@ WSS_SINGLE("Beep Bypass Playback Switch", 0,
2246 CS4231_MONO_CTRL, 5, 1, 0), 2247 CS4231_MONO_CTRL, 5, 1, 0),
2247}; 2248};
2248 2249
2249static struct snd_kcontrol_new snd_opti93x_controls[] = {
2250WSS_DOUBLE("Master Playback Switch", 0,
2251 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
2252WSS_DOUBLE_TLV("Master Playback Volume", 0,
2253 OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
2254 db_scale_6bit),
2255WSS_DOUBLE("PCM Playback Switch", 0,
2256 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
2257WSS_DOUBLE("PCM Playback Volume", 0,
2258 CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1),
2259WSS_DOUBLE("FM Playback Switch", 0,
2260 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
2261WSS_DOUBLE("FM Playback Volume", 0,
2262 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1),
2263WSS_DOUBLE("Line Playback Switch", 0,
2264 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
2265WSS_DOUBLE("Line Playback Volume", 0,
2266 CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1),
2267WSS_DOUBLE("Mic Playback Switch", 0,
2268 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
2269WSS_DOUBLE("Mic Playback Volume", 0,
2270 OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
2271WSS_DOUBLE("Mic Boost", 0,
2272 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
2273WSS_DOUBLE("CD Playback Switch", 0,
2274 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
2275WSS_DOUBLE("CD Playback Volume", 0,
2276 CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1),
2277WSS_DOUBLE("Aux Playback Switch", 0,
2278 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
2279WSS_DOUBLE("Aux Playback Volume", 0,
2280 OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
2281WSS_DOUBLE("Capture Volume", 0,
2282 CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
2283{
2284 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2285 .name = "Capture Source",
2286 .info = snd_wss_info_mux,
2287 .get = snd_wss_get_mux,
2288 .put = snd_wss_put_mux,
2289}
2290};
2291
2292int snd_wss_mixer(struct snd_wss *chip) 2250int snd_wss_mixer(struct snd_wss *chip)
2293{ 2251{
2294 struct snd_card *card; 2252 struct snd_card *card;
2295 unsigned int idx; 2253 unsigned int idx;
2296 int err; 2254 int err;
2255 int count = ARRAY_SIZE(snd_wss_controls);
2297 2256
2298 if (snd_BUG_ON(!chip || !chip->pcm)) 2257 if (snd_BUG_ON(!chip || !chip->pcm))
2299 return -EINVAL; 2258 return -EINVAL;
@@ -2302,28 +2261,19 @@ int snd_wss_mixer(struct snd_wss *chip)
2302 2261
2303 strcpy(card->mixername, chip->pcm->name); 2262 strcpy(card->mixername, chip->pcm->name);
2304 2263
2305 if (chip->hardware == WSS_HW_OPTI93X) 2264 /* Use only the first 11 entries on AD1848 */
2306 for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) { 2265 if (chip->hardware & WSS_HW_AD1848_MASK)
2307 err = snd_ctl_add(card, 2266 count = 11;
2308 snd_ctl_new1(&snd_opti93x_controls[idx], 2267 /* There is no loopback on OPTI93X */
2309 chip)); 2268 else if (chip->hardware == WSS_HW_OPTI93X)
2310 if (err < 0) 2269 count = 9;
2311 return err; 2270
2312 } 2271 for (idx = 0; idx < count; idx++) {
2313 else { 2272 err = snd_ctl_add(card,
2314 int count = ARRAY_SIZE(snd_wss_controls); 2273 snd_ctl_new1(&snd_wss_controls[idx],
2315 2274 chip));
2316 /* Use only the first 11 entries on AD1848 */ 2275 if (err < 0)
2317 if (chip->hardware & WSS_HW_AD1848_MASK) 2276 return err;
2318 count = 11;
2319
2320 for (idx = 0; idx < count; idx++) {
2321 err = snd_ctl_add(card,
2322 snd_ctl_new1(&snd_wss_controls[idx],
2323 chip));
2324 if (err < 0)
2325 return err;
2326 }
2327 } 2277 }
2328 return 0; 2278 return 0;
2329} 2279}
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index 73525c048e7f..8c2925814ce4 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -21,6 +21,18 @@ config SND_USB_AUDIO
21 To compile this driver as a module, choose M here: the module 21 To compile this driver as a module, choose M here: the module
22 will be called snd-usb-audio. 22 will be called snd-usb-audio.
23 23
24config SND_USB_UA101
25 tristate "Edirol UA-101 driver (EXPERIMENTAL)"
26 depends on EXPERIMENTAL
27 select SND_PCM
28 select SND_RAWMIDI
29 help
30 Say Y here to include support for the Edirol UA-101 audio/MIDI
31 interface.
32
33 To compile this driver as a module, choose M here: the module
34 will be called snd-ua101.
35
24config SND_USB_USX2Y 36config SND_USB_USX2Y
25 tristate "Tascam US-122, US-224 and US-428 USB driver" 37 tristate "Tascam US-122, US-224 and US-428 USB driver"
26 depends on X86 || PPC || ALPHA 38 depends on X86 || PPC || ALPHA
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index abb288bfe35d..5bf64aef9558 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -4,9 +4,11 @@
4 4
5snd-usb-audio-objs := usbaudio.o usbmixer.o 5snd-usb-audio-objs := usbaudio.o usbmixer.o
6snd-usb-lib-objs := usbmidi.o 6snd-usb-lib-objs := usbmidi.o
7snd-ua101-objs := ua101.o
7 8
8# Toplevel Module Dependency 9# Toplevel Module Dependency
9obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o 10obj-$(CONFIG_SND_USB_AUDIO) += snd-usb-audio.o snd-usb-lib.o
11obj-$(CONFIG_SND_USB_UA101) += snd-ua101.o snd-usb-lib.o
10obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o 12obj-$(CONFIG_SND_USB_USX2Y) += snd-usb-lib.o
11obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o 13obj-$(CONFIG_SND_USB_US122L) += snd-usb-lib.o
12 14
diff --git a/sound/usb/ua101.c b/sound/usb/ua101.c
new file mode 100644
index 000000000000..ab9f8a2e1938
--- /dev/null
+++ b/sound/usb/ua101.c
@@ -0,0 +1,1457 @@
1/*
2 * Edirol UA-101 driver
3 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
4 *
5 * This driver is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License, version 2.
7 *
8 * This driver is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this driver. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/usb.h>
21#include <linux/usb/audio.h>
22#include <linux/vmalloc.h>
23#include <sound/core.h>
24#include <sound/initval.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include "usbaudio.h"
28
29MODULE_DESCRIPTION("Edirol UA-101 driver");
30MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
31MODULE_LICENSE("GPL v2");
32MODULE_SUPPORTED_DEVICE("{{Edirol,UA-101}}");
33
34/* I use my UA-1A for testing because I don't have a UA-101 ... */
35#define UA1A_HACK
36
37/*
38 * Should not be lower than the minimum scheduling delay of the host
39 * controller. Some Intel controllers need more than one frame; as long as
40 * that driver doesn't tell us about this, use 1.5 frames just to be sure.
41 */
42#define MIN_QUEUE_LENGTH 12
43/* Somewhat random. */
44#define MAX_QUEUE_LENGTH 30
45/*
46 * This magic value optimizes memory usage efficiency for the UA-101's packet
47 * sizes at all sample rates, taking into account the stupid cache pool sizes
48 * that usb_buffer_alloc() uses.
49 */
50#define DEFAULT_QUEUE_LENGTH 21
51
52#define MAX_PACKET_SIZE 672 /* hardware specific */
53#define MAX_MEMORY_BUFFERS DIV_ROUND_UP(MAX_QUEUE_LENGTH, \
54 PAGE_SIZE / MAX_PACKET_SIZE)
55
56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
57static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
58static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
59static unsigned int queue_length = 21;
60
61module_param_array(index, int, NULL, 0444);
62MODULE_PARM_DESC(index, "card index");
63module_param_array(id, charp, NULL, 0444);
64MODULE_PARM_DESC(id, "ID string");
65module_param_array(enable, bool, NULL, 0444);
66MODULE_PARM_DESC(enable, "enable card");
67module_param(queue_length, uint, 0644);
68MODULE_PARM_DESC(queue_length, "USB queue length in microframes, "
69 __stringify(MIN_QUEUE_LENGTH)"-"__stringify(MAX_QUEUE_LENGTH));
70
71enum {
72 INTF_PLAYBACK,
73 INTF_CAPTURE,
74 INTF_MIDI,
75
76 INTF_COUNT
77};
78
79/* bits in struct ua101::states */
80enum {
81 USB_CAPTURE_RUNNING,
82 USB_PLAYBACK_RUNNING,
83 ALSA_CAPTURE_OPEN,
84 ALSA_PLAYBACK_OPEN,
85 ALSA_CAPTURE_RUNNING,
86 ALSA_PLAYBACK_RUNNING,
87 CAPTURE_URB_COMPLETED,
88 PLAYBACK_URB_COMPLETED,
89 DISCONNECTED,
90};
91
92struct ua101 {
93 struct usb_device *dev;
94 struct snd_card *card;
95 struct usb_interface *intf[INTF_COUNT];
96 int card_index;
97 struct snd_pcm *pcm;
98 struct list_head midi_list;
99 u64 format_bit;
100 unsigned int rate;
101 unsigned int packets_per_second;
102 spinlock_t lock;
103 struct mutex mutex;
104 unsigned long states;
105
106 /* FIFO to synchronize playback rate to capture rate */
107 unsigned int rate_feedback_start;
108 unsigned int rate_feedback_count;
109 u8 rate_feedback[MAX_QUEUE_LENGTH];
110
111 struct list_head ready_playback_urbs;
112 struct tasklet_struct playback_tasklet;
113 wait_queue_head_t alsa_capture_wait;
114 wait_queue_head_t rate_feedback_wait;
115 wait_queue_head_t alsa_playback_wait;
116 struct ua101_stream {
117 struct snd_pcm_substream *substream;
118 unsigned int usb_pipe;
119 unsigned int channels;
120 unsigned int frame_bytes;
121 unsigned int max_packet_bytes;
122 unsigned int period_pos;
123 unsigned int buffer_pos;
124 unsigned int queue_length;
125 struct ua101_urb {
126 struct urb urb;
127 struct usb_iso_packet_descriptor iso_frame_desc[1];
128 struct list_head ready_list;
129 } *urbs[MAX_QUEUE_LENGTH];
130 struct {
131 unsigned int size;
132 void *addr;
133 dma_addr_t dma;
134 } buffers[MAX_MEMORY_BUFFERS];
135 } capture, playback;
136
137 unsigned int fps[10];
138 unsigned int frame_counter;
139};
140
141static DEFINE_MUTEX(devices_mutex);
142static unsigned int devices_used;
143static struct usb_driver ua101_driver;
144
145static void abort_alsa_playback(struct ua101 *ua);
146static void abort_alsa_capture(struct ua101 *ua);
147
148/* allocate virtual buffer; may be called more than once */
149static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs,
150 size_t size)
151{
152 struct snd_pcm_runtime *runtime = subs->runtime;
153
154 if (runtime->dma_area) {
155 if (runtime->dma_bytes >= size)
156 return 0; /* already large enough */
157 vfree(runtime->dma_area);
158 }
159 runtime->dma_area = vmalloc_user(size);
160 if (!runtime->dma_area)
161 return -ENOMEM;
162 runtime->dma_bytes = size;
163 return 0;
164}
165
166/* free virtual buffer; may be called more than once */
167static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs)
168{
169 struct snd_pcm_runtime *runtime = subs->runtime;
170
171 vfree(runtime->dma_area);
172 runtime->dma_area = NULL;
173 return 0;
174}
175
176/* get the physical page pointer at the given offset */
177static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs,
178 unsigned long offset)
179{
180 void *pageptr = subs->runtime->dma_area + offset;
181 return vmalloc_to_page(pageptr);
182}
183
184static const char *usb_error_string(int err)
185{
186 switch (err) {
187 case -ENODEV:
188 return "no device";
189 case -ENOENT:
190 return "endpoint not enabled";
191 case -EPIPE:
192 return "endpoint stalled";
193 case -ENOSPC:
194 return "not enough bandwidth";
195 case -ESHUTDOWN:
196 return "device disabled";
197 case -EHOSTUNREACH:
198 return "device suspended";
199 case -EINVAL:
200 case -EAGAIN:
201 case -EFBIG:
202 case -EMSGSIZE:
203 return "internal error";
204 default:
205 return "unknown error";
206 }
207}
208
209static void abort_usb_capture(struct ua101 *ua)
210{
211 if (test_and_clear_bit(USB_CAPTURE_RUNNING, &ua->states)) {
212 wake_up(&ua->alsa_capture_wait);
213 wake_up(&ua->rate_feedback_wait);
214 }
215}
216
217static void abort_usb_playback(struct ua101 *ua)
218{
219 if (test_and_clear_bit(USB_PLAYBACK_RUNNING, &ua->states))
220 wake_up(&ua->alsa_playback_wait);
221}
222
223static void playback_urb_complete(struct urb *usb_urb)
224{
225 struct ua101_urb *urb = (struct ua101_urb *)usb_urb;
226 struct ua101 *ua = urb->urb.context;
227 unsigned long flags;
228
229 if (unlikely(urb->urb.status == -ENOENT || /* unlinked */
230 urb->urb.status == -ENODEV || /* device removed */
231 urb->urb.status == -ECONNRESET || /* unlinked */
232 urb->urb.status == -ESHUTDOWN)) { /* device disabled */
233 abort_usb_playback(ua);
234 abort_alsa_playback(ua);
235 return;
236 }
237
238 if (test_bit(USB_PLAYBACK_RUNNING, &ua->states)) {
239 /* append URB to FIFO */
240 spin_lock_irqsave(&ua->lock, flags);
241 list_add_tail(&urb->ready_list, &ua->ready_playback_urbs);
242 if (ua->rate_feedback_count > 0)
243 tasklet_schedule(&ua->playback_tasklet);
244 ua->playback.substream->runtime->delay -=
245 urb->urb.iso_frame_desc[0].length /
246 ua->playback.frame_bytes;
247 spin_unlock_irqrestore(&ua->lock, flags);
248 }
249}
250
251static void first_playback_urb_complete(struct urb *urb)
252{
253 struct ua101 *ua = urb->context;
254
255 urb->complete = playback_urb_complete;
256 playback_urb_complete(urb);
257
258 set_bit(PLAYBACK_URB_COMPLETED, &ua->states);
259 wake_up(&ua->alsa_playback_wait);
260}
261
262/* copy data from the ALSA ring buffer into the URB buffer */
263static bool copy_playback_data(struct ua101_stream *stream, struct urb *urb,
264 unsigned int frames)
265{
266 struct snd_pcm_runtime *runtime;
267 unsigned int frame_bytes, frames1;
268 const u8 *source;
269
270 runtime = stream->substream->runtime;
271 frame_bytes = stream->frame_bytes;
272 source = runtime->dma_area + stream->buffer_pos * frame_bytes;
273 if (stream->buffer_pos + frames <= runtime->buffer_size) {
274 memcpy(urb->transfer_buffer, source, frames * frame_bytes);
275 } else {
276 /* wrap around at end of ring buffer */
277 frames1 = runtime->buffer_size - stream->buffer_pos;
278 memcpy(urb->transfer_buffer, source, frames1 * frame_bytes);
279 memcpy(urb->transfer_buffer + frames1 * frame_bytes,
280 runtime->dma_area, (frames - frames1) * frame_bytes);
281 }
282
283 stream->buffer_pos += frames;
284 if (stream->buffer_pos >= runtime->buffer_size)
285 stream->buffer_pos -= runtime->buffer_size;
286 stream->period_pos += frames;
287 if (stream->period_pos >= runtime->period_size) {
288 stream->period_pos -= runtime->period_size;
289 return true;
290 }
291 return false;
292}
293
294static inline void add_with_wraparound(struct ua101 *ua,
295 unsigned int *value, unsigned int add)
296{
297 *value += add;
298 if (*value >= ua->playback.queue_length)
299 *value -= ua->playback.queue_length;
300}
301
302static void playback_tasklet(unsigned long data)
303{
304 struct ua101 *ua = (void *)data;
305 unsigned long flags;
306 unsigned int frames;
307 struct ua101_urb *urb;
308 bool do_period_elapsed = false;
309 int err;
310
311 if (unlikely(!test_bit(USB_PLAYBACK_RUNNING, &ua->states)))
312 return;
313
314 /*
315 * Synchronizing the playback rate to the capture rate is done by using
316 * the same sequence of packet sizes for both streams.
317 * Submitting a playback URB therefore requires both a ready URB and
318 * the size of the corresponding capture packet, i.e., both playback
319 * and capture URBs must have been completed. Since the USB core does
320 * not guarantee that playback and capture complete callbacks are
321 * called alternately, we use two FIFOs for packet sizes and read URBs;
322 * submitting playback URBs is possible as long as both FIFOs are
323 * nonempty.
324 */
325 spin_lock_irqsave(&ua->lock, flags);
326 while (ua->rate_feedback_count > 0 &&
327 !list_empty(&ua->ready_playback_urbs)) {
328 /* take packet size out of FIFO */
329 frames = ua->rate_feedback[ua->rate_feedback_start];
330 add_with_wraparound(ua, &ua->rate_feedback_start, 1);
331 ua->rate_feedback_count--;
332
333 /* take URB out of FIFO */
334 urb = list_first_entry(&ua->ready_playback_urbs,
335 struct ua101_urb, ready_list);
336 list_del(&urb->ready_list);
337
338 /* fill packet with data or silence */
339 urb->urb.iso_frame_desc[0].length =
340 frames * ua->playback.frame_bytes;
341 if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
342 do_period_elapsed |= copy_playback_data(&ua->playback,
343 &urb->urb,
344 frames);
345 else
346 memset(urb->urb.transfer_buffer, 0,
347 urb->urb.iso_frame_desc[0].length);
348
349 /* and off you go ... */
350 err = usb_submit_urb(&urb->urb, GFP_ATOMIC);
351 if (unlikely(err < 0)) {
352 spin_unlock_irqrestore(&ua->lock, flags);
353 abort_usb_playback(ua);
354 abort_alsa_playback(ua);
355 dev_err(&ua->dev->dev, "USB request error %d: %s\n",
356 err, usb_error_string(err));
357 return;
358 }
359 ua->playback.substream->runtime->delay += frames;
360 }
361 spin_unlock_irqrestore(&ua->lock, flags);
362 if (do_period_elapsed)
363 snd_pcm_period_elapsed(ua->playback.substream);
364}
365
366/* copy data from the URB buffer into the ALSA ring buffer */
367static bool copy_capture_data(struct ua101_stream *stream, struct urb *urb,
368 unsigned int frames)
369{
370 struct snd_pcm_runtime *runtime;
371 unsigned int frame_bytes, frames1;
372 u8 *dest;
373
374 runtime = stream->substream->runtime;
375 frame_bytes = stream->frame_bytes;
376 dest = runtime->dma_area + stream->buffer_pos * frame_bytes;
377 if (stream->buffer_pos + frames <= runtime->buffer_size) {
378 memcpy(dest, urb->transfer_buffer, frames * frame_bytes);
379 } else {
380 /* wrap around at end of ring buffer */
381 frames1 = runtime->buffer_size - stream->buffer_pos;
382 memcpy(dest, urb->transfer_buffer, frames1 * frame_bytes);
383 memcpy(runtime->dma_area,
384 urb->transfer_buffer + frames1 * frame_bytes,
385 (frames - frames1) * frame_bytes);
386 }
387
388 stream->buffer_pos += frames;
389 if (stream->buffer_pos >= runtime->buffer_size)
390 stream->buffer_pos -= runtime->buffer_size;
391 stream->period_pos += frames;
392 if (stream->period_pos >= runtime->period_size) {
393 stream->period_pos -= runtime->period_size;
394 return true;
395 }
396 return false;
397}
398
399static void capture_urb_complete(struct urb *urb)
400{
401 struct ua101 *ua = urb->context;
402 struct ua101_stream *stream = &ua->capture;
403 unsigned long flags;
404 unsigned int frames, write_ptr;
405 bool do_period_elapsed;
406 int err;
407
408 if (unlikely(urb->status == -ENOENT || /* unlinked */
409 urb->status == -ENODEV || /* device removed */
410 urb->status == -ECONNRESET || /* unlinked */
411 urb->status == -ESHUTDOWN)) /* device disabled */
412 goto stream_stopped;
413
414 if (urb->status >= 0 && urb->iso_frame_desc[0].status >= 0)
415 frames = urb->iso_frame_desc[0].actual_length /
416 stream->frame_bytes;
417 else
418 frames = 0;
419
420 spin_lock_irqsave(&ua->lock, flags);
421
422 if (frames > 0 && test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
423 do_period_elapsed = copy_capture_data(stream, urb, frames);
424 else
425 do_period_elapsed = false;
426
427 if (test_bit(USB_CAPTURE_RUNNING, &ua->states)) {
428 err = usb_submit_urb(urb, GFP_ATOMIC);
429 if (unlikely(err < 0)) {
430 spin_unlock_irqrestore(&ua->lock, flags);
431 dev_err(&ua->dev->dev, "USB request error %d: %s\n",
432 err, usb_error_string(err));
433 goto stream_stopped;
434 }
435
436 /* append packet size to FIFO */
437 write_ptr = ua->rate_feedback_start;
438 add_with_wraparound(ua, &write_ptr, ua->rate_feedback_count);
439 ua->rate_feedback[write_ptr] = frames;
440 if (ua->rate_feedback_count < ua->playback.queue_length) {
441 ua->rate_feedback_count++;
442 if (ua->rate_feedback_count ==
443 ua->playback.queue_length)
444 wake_up(&ua->rate_feedback_wait);
445 } else {
446 /*
447 * Ring buffer overflow; this happens when the playback
448 * stream is not running. Throw away the oldest entry,
449 * so that the playback stream, when it starts, sees
450 * the most recent packet sizes.
451 */
452 add_with_wraparound(ua, &ua->rate_feedback_start, 1);
453 }
454 if (test_bit(USB_PLAYBACK_RUNNING, &ua->states) &&
455 !list_empty(&ua->ready_playback_urbs))
456 tasklet_schedule(&ua->playback_tasklet);
457 }
458
459 spin_unlock_irqrestore(&ua->lock, flags);
460
461 if (do_period_elapsed)
462 snd_pcm_period_elapsed(stream->substream);
463
464 /* for debugging: measure the sample rate relative to the USB clock */
465 ua->fps[ua->frame_counter++ / ua->packets_per_second] += frames;
466 if (ua->frame_counter >= ARRAY_SIZE(ua->fps) * ua->packets_per_second) {
467 printk(KERN_DEBUG "capture rate:");
468 for (frames = 0; frames < ARRAY_SIZE(ua->fps); ++frames)
469 printk(KERN_CONT " %u", ua->fps[frames]);
470 printk(KERN_CONT "\n");
471 memset(ua->fps, 0, sizeof(ua->fps));
472 ua->frame_counter = 0;
473 }
474 return;
475
476stream_stopped:
477 abort_usb_playback(ua);
478 abort_usb_capture(ua);
479 abort_alsa_playback(ua);
480 abort_alsa_capture(ua);
481}
482
483static void first_capture_urb_complete(struct urb *urb)
484{
485 struct ua101 *ua = urb->context;
486
487 urb->complete = capture_urb_complete;
488 capture_urb_complete(urb);
489
490 set_bit(CAPTURE_URB_COMPLETED, &ua->states);
491 wake_up(&ua->alsa_capture_wait);
492}
493
494static int submit_stream_urbs(struct ua101 *ua, struct ua101_stream *stream)
495{
496 unsigned int i;
497
498 for (i = 0; i < stream->queue_length; ++i) {
499 int err = usb_submit_urb(&stream->urbs[i]->urb, GFP_KERNEL);
500 if (err < 0) {
501 dev_err(&ua->dev->dev, "USB request error %d: %s\n",
502 err, usb_error_string(err));
503 return err;
504 }
505 }
506 return 0;
507}
508
509static void kill_stream_urbs(struct ua101_stream *stream)
510{
511 unsigned int i;
512
513 for (i = 0; i < stream->queue_length; ++i)
514 usb_kill_urb(&stream->urbs[i]->urb);
515}
516
517static int enable_iso_interface(struct ua101 *ua, unsigned int intf_index)
518{
519 struct usb_host_interface *alts;
520
521 alts = ua->intf[intf_index]->cur_altsetting;
522 if (alts->desc.bAlternateSetting != 1) {
523 int err = usb_set_interface(ua->dev,
524 alts->desc.bInterfaceNumber, 1);
525 if (err < 0) {
526 dev_err(&ua->dev->dev,
527 "cannot initialize interface; error %d: %s\n",
528 err, usb_error_string(err));
529 return err;
530 }
531 }
532 return 0;
533}
534
535static void disable_iso_interface(struct ua101 *ua, unsigned int intf_index)
536{
537 struct usb_host_interface *alts;
538
539 alts = ua->intf[intf_index]->cur_altsetting;
540 if (alts->desc.bAlternateSetting != 0) {
541 int err = usb_set_interface(ua->dev,
542 alts->desc.bInterfaceNumber, 0);
543 if (err < 0 && !test_bit(DISCONNECTED, &ua->states))
544 dev_warn(&ua->dev->dev,
545 "interface reset failed; error %d: %s\n",
546 err, usb_error_string(err));
547 }
548}
549
550static void stop_usb_capture(struct ua101 *ua)
551{
552 clear_bit(USB_CAPTURE_RUNNING, &ua->states);
553
554 kill_stream_urbs(&ua->capture);
555
556 disable_iso_interface(ua, INTF_CAPTURE);
557}
558
559static int start_usb_capture(struct ua101 *ua)
560{
561 int err;
562
563 if (test_bit(DISCONNECTED, &ua->states))
564 return -ENODEV;
565
566 if (test_bit(USB_CAPTURE_RUNNING, &ua->states))
567 return 0;
568
569 kill_stream_urbs(&ua->capture);
570
571 err = enable_iso_interface(ua, INTF_CAPTURE);
572 if (err < 0)
573 return err;
574
575 clear_bit(CAPTURE_URB_COMPLETED, &ua->states);
576 ua->capture.urbs[0]->urb.complete = first_capture_urb_complete;
577 ua->rate_feedback_start = 0;
578 ua->rate_feedback_count = 0;
579
580 set_bit(USB_CAPTURE_RUNNING, &ua->states);
581 err = submit_stream_urbs(ua, &ua->capture);
582 if (err < 0)
583 stop_usb_capture(ua);
584 return err;
585}
586
587static void stop_usb_playback(struct ua101 *ua)
588{
589 clear_bit(USB_PLAYBACK_RUNNING, &ua->states);
590
591 kill_stream_urbs(&ua->playback);
592
593 tasklet_kill(&ua->playback_tasklet);
594
595 disable_iso_interface(ua, INTF_PLAYBACK);
596}
597
598static int start_usb_playback(struct ua101 *ua)
599{
600 unsigned int i, frames;
601 struct urb *urb;
602 int err = 0;
603
604 if (test_bit(DISCONNECTED, &ua->states))
605 return -ENODEV;
606
607 if (test_bit(USB_PLAYBACK_RUNNING, &ua->states))
608 return 0;
609
610 kill_stream_urbs(&ua->playback);
611 tasklet_kill(&ua->playback_tasklet);
612
613 err = enable_iso_interface(ua, INTF_PLAYBACK);
614 if (err < 0)
615 return err;
616
617 clear_bit(PLAYBACK_URB_COMPLETED, &ua->states);
618 ua->playback.urbs[0]->urb.complete =
619 first_playback_urb_complete;
620 spin_lock_irq(&ua->lock);
621 INIT_LIST_HEAD(&ua->ready_playback_urbs);
622 spin_unlock_irq(&ua->lock);
623
624 /*
625 * We submit the initial URBs all at once, so we have to wait for the
626 * packet size FIFO to be full.
627 */
628 wait_event(ua->rate_feedback_wait,
629 ua->rate_feedback_count >= ua->playback.queue_length ||
630 !test_bit(USB_CAPTURE_RUNNING, &ua->states) ||
631 test_bit(DISCONNECTED, &ua->states));
632 if (test_bit(DISCONNECTED, &ua->states)) {
633 stop_usb_playback(ua);
634 return -ENODEV;
635 }
636 if (!test_bit(USB_CAPTURE_RUNNING, &ua->states)) {
637 stop_usb_playback(ua);
638 return -EIO;
639 }
640
641 for (i = 0; i < ua->playback.queue_length; ++i) {
642 /* all initial URBs contain silence */
643 spin_lock_irq(&ua->lock);
644 frames = ua->rate_feedback[ua->rate_feedback_start];
645 add_with_wraparound(ua, &ua->rate_feedback_start, 1);
646 ua->rate_feedback_count--;
647 spin_unlock_irq(&ua->lock);
648 urb = &ua->playback.urbs[i]->urb;
649 urb->iso_frame_desc[0].length =
650 frames * ua->playback.frame_bytes;
651 memset(urb->transfer_buffer, 0,
652 urb->iso_frame_desc[0].length);
653 }
654
655 set_bit(USB_PLAYBACK_RUNNING, &ua->states);
656 err = submit_stream_urbs(ua, &ua->playback);
657 if (err < 0)
658 stop_usb_playback(ua);
659 return err;
660}
661
662static void abort_alsa_capture(struct ua101 *ua)
663{
664 if (test_bit(ALSA_CAPTURE_RUNNING, &ua->states))
665 snd_pcm_stop(ua->capture.substream, SNDRV_PCM_STATE_XRUN);
666}
667
668static void abort_alsa_playback(struct ua101 *ua)
669{
670 if (test_bit(ALSA_PLAYBACK_RUNNING, &ua->states))
671 snd_pcm_stop(ua->playback.substream, SNDRV_PCM_STATE_XRUN);
672}
673
674static int set_stream_hw(struct ua101 *ua, struct snd_pcm_substream *substream,
675 unsigned int channels)
676{
677 int err;
678
679 substream->runtime->hw.info =
680 SNDRV_PCM_INFO_MMAP |
681 SNDRV_PCM_INFO_MMAP_VALID |
682 SNDRV_PCM_INFO_BATCH |
683 SNDRV_PCM_INFO_INTERLEAVED |
684 SNDRV_PCM_INFO_BLOCK_TRANSFER |
685 SNDRV_PCM_INFO_FIFO_IN_FRAMES;
686 substream->runtime->hw.formats = ua->format_bit;
687 substream->runtime->hw.rates = snd_pcm_rate_to_rate_bit(ua->rate);
688 substream->runtime->hw.rate_min = ua->rate;
689 substream->runtime->hw.rate_max = ua->rate;
690 substream->runtime->hw.channels_min = channels;
691 substream->runtime->hw.channels_max = channels;
692 substream->runtime->hw.buffer_bytes_max = 45000 * 1024;
693 substream->runtime->hw.period_bytes_min = 1;
694 substream->runtime->hw.period_bytes_max = UINT_MAX;
695 substream->runtime->hw.periods_min = 2;
696 substream->runtime->hw.periods_max = UINT_MAX;
697 err = snd_pcm_hw_constraint_minmax(substream->runtime,
698 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
699 1500000 / ua->packets_per_second,
700 8192000);
701 if (err < 0)
702 return err;
703 err = snd_pcm_hw_constraint_msbits(substream->runtime, 0, 32, 24);
704 return err;
705}
706
707static int capture_pcm_open(struct snd_pcm_substream *substream)
708{
709 struct ua101 *ua = substream->private_data;
710 int err;
711
712 ua->capture.substream = substream;
713 err = set_stream_hw(ua, substream, ua->capture.channels);
714 if (err < 0)
715 return err;
716 substream->runtime->hw.fifo_size =
717 DIV_ROUND_CLOSEST(ua->rate, ua->packets_per_second);
718 substream->runtime->delay = substream->runtime->hw.fifo_size;
719
720 mutex_lock(&ua->mutex);
721 err = start_usb_capture(ua);
722 if (err >= 0)
723 set_bit(ALSA_CAPTURE_OPEN, &ua->states);
724 mutex_unlock(&ua->mutex);
725 return err;
726}
727
728static int playback_pcm_open(struct snd_pcm_substream *substream)
729{
730 struct ua101 *ua = substream->private_data;
731 int err;
732
733 ua->playback.substream = substream;
734 err = set_stream_hw(ua, substream, ua->playback.channels);
735 if (err < 0)
736 return err;
737 substream->runtime->hw.fifo_size =
738 DIV_ROUND_CLOSEST(ua->rate * ua->playback.queue_length,
739 ua->packets_per_second);
740
741 mutex_lock(&ua->mutex);
742 err = start_usb_capture(ua);
743 if (err < 0)
744 goto error;
745 err = start_usb_playback(ua);
746 if (err < 0) {
747 if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states))
748 stop_usb_capture(ua);
749 goto error;
750 }
751 set_bit(ALSA_PLAYBACK_OPEN, &ua->states);
752error:
753 mutex_unlock(&ua->mutex);
754 return err;
755}
756
757static int capture_pcm_close(struct snd_pcm_substream *substream)
758{
759 struct ua101 *ua = substream->private_data;
760
761 mutex_lock(&ua->mutex);
762 clear_bit(ALSA_CAPTURE_OPEN, &ua->states);
763 if (!test_bit(ALSA_PLAYBACK_OPEN, &ua->states))
764 stop_usb_capture(ua);
765 mutex_unlock(&ua->mutex);
766 return 0;
767}
768
769static int playback_pcm_close(struct snd_pcm_substream *substream)
770{
771 struct ua101 *ua = substream->private_data;
772
773 mutex_lock(&ua->mutex);
774 stop_usb_playback(ua);
775 clear_bit(ALSA_PLAYBACK_OPEN, &ua->states);
776 if (!test_bit(ALSA_CAPTURE_OPEN, &ua->states))
777 stop_usb_capture(ua);
778 mutex_unlock(&ua->mutex);
779 return 0;
780}
781
782static int capture_pcm_hw_params(struct snd_pcm_substream *substream,
783 struct snd_pcm_hw_params *hw_params)
784{
785 struct ua101 *ua = substream->private_data;
786 int err;
787
788 mutex_lock(&ua->mutex);
789 err = start_usb_capture(ua);
790 mutex_unlock(&ua->mutex);
791 if (err < 0)
792 return err;
793
794 return snd_pcm_alloc_vmalloc_buffer(substream,
795 params_buffer_bytes(hw_params));
796}
797
798static int playback_pcm_hw_params(struct snd_pcm_substream *substream,
799 struct snd_pcm_hw_params *hw_params)
800{
801 struct ua101 *ua = substream->private_data;
802 int err;
803
804 mutex_lock(&ua->mutex);
805 err = start_usb_capture(ua);
806 if (err >= 0)
807 err = start_usb_playback(ua);
808 mutex_unlock(&ua->mutex);
809 if (err < 0)
810 return err;
811
812 return snd_pcm_alloc_vmalloc_buffer(substream,
813 params_buffer_bytes(hw_params));
814}
815
816static int ua101_pcm_hw_free(struct snd_pcm_substream *substream)
817{
818 snd_pcm_free_vmalloc_buffer(substream);
819 return 0;
820}
821
822static int capture_pcm_prepare(struct snd_pcm_substream *substream)
823{
824 struct ua101 *ua = substream->private_data;
825 int err;
826
827 mutex_lock(&ua->mutex);
828 err = start_usb_capture(ua);
829 mutex_unlock(&ua->mutex);
830 if (err < 0)
831 return err;
832
833 /*
834 * The EHCI driver schedules the first packet of an iso stream at 10 ms
835 * in the future, i.e., no data is actually captured for that long.
836 * Take the wait here so that the stream is known to be actually
837 * running when the start trigger has been called.
838 */
839 wait_event(ua->alsa_capture_wait,
840 test_bit(CAPTURE_URB_COMPLETED, &ua->states) ||
841 !test_bit(USB_CAPTURE_RUNNING, &ua->states));
842 if (test_bit(DISCONNECTED, &ua->states))
843 return -ENODEV;
844 if (!test_bit(USB_CAPTURE_RUNNING, &ua->states))
845 return -EIO;
846
847 ua->capture.period_pos = 0;
848 ua->capture.buffer_pos = 0;
849 return 0;
850}
851
852static int playback_pcm_prepare(struct snd_pcm_substream *substream)
853{
854 struct ua101 *ua = substream->private_data;
855 int err;
856
857 mutex_lock(&ua->mutex);
858 err = start_usb_capture(ua);
859 if (err >= 0)
860 err = start_usb_playback(ua);
861 mutex_unlock(&ua->mutex);
862 if (err < 0)
863 return err;
864
865 /* see the comment in capture_pcm_prepare() */
866 wait_event(ua->alsa_playback_wait,
867 test_bit(PLAYBACK_URB_COMPLETED, &ua->states) ||
868 !test_bit(USB_PLAYBACK_RUNNING, &ua->states));
869 if (test_bit(DISCONNECTED, &ua->states))
870 return -ENODEV;
871 if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states))
872 return -EIO;
873
874 substream->runtime->delay = 0;
875 ua->playback.period_pos = 0;
876 ua->playback.buffer_pos = 0;
877 return 0;
878}
879
880static int capture_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
881{
882 struct ua101 *ua = substream->private_data;
883
884 switch (cmd) {
885 case SNDRV_PCM_TRIGGER_START:
886 if (!test_bit(USB_CAPTURE_RUNNING, &ua->states))
887 return -EIO;
888 set_bit(ALSA_CAPTURE_RUNNING, &ua->states);
889 return 0;
890 case SNDRV_PCM_TRIGGER_STOP:
891 clear_bit(ALSA_CAPTURE_RUNNING, &ua->states);
892 return 0;
893 default:
894 return -EINVAL;
895 }
896}
897
898static int playback_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
899{
900 struct ua101 *ua = substream->private_data;
901
902 switch (cmd) {
903 case SNDRV_PCM_TRIGGER_START:
904 if (!test_bit(USB_PLAYBACK_RUNNING, &ua->states))
905 return -EIO;
906 set_bit(ALSA_PLAYBACK_RUNNING, &ua->states);
907 return 0;
908 case SNDRV_PCM_TRIGGER_STOP:
909 clear_bit(ALSA_PLAYBACK_RUNNING, &ua->states);
910 return 0;
911 default:
912 return -EINVAL;
913 }
914}
915
916static inline snd_pcm_uframes_t ua101_pcm_pointer(struct ua101 *ua,
917 struct ua101_stream *stream)
918{
919 unsigned long flags;
920 unsigned int pos;
921
922 spin_lock_irqsave(&ua->lock, flags);
923 pos = stream->buffer_pos;
924 spin_unlock_irqrestore(&ua->lock, flags);
925 return pos;
926}
927
928static snd_pcm_uframes_t capture_pcm_pointer(struct snd_pcm_substream *subs)
929{
930 struct ua101 *ua = subs->private_data;
931
932 return ua101_pcm_pointer(ua, &ua->capture);
933}
934
935static snd_pcm_uframes_t playback_pcm_pointer(struct snd_pcm_substream *subs)
936{
937 struct ua101 *ua = subs->private_data;
938
939 return ua101_pcm_pointer(ua, &ua->playback);
940}
941
942static struct snd_pcm_ops capture_pcm_ops = {
943 .open = capture_pcm_open,
944 .close = capture_pcm_close,
945 .ioctl = snd_pcm_lib_ioctl,
946 .hw_params = capture_pcm_hw_params,
947 .hw_free = ua101_pcm_hw_free,
948 .prepare = capture_pcm_prepare,
949 .trigger = capture_pcm_trigger,
950 .pointer = capture_pcm_pointer,
951 .page = snd_pcm_get_vmalloc_page,
952};
953
954static struct snd_pcm_ops playback_pcm_ops = {
955 .open = playback_pcm_open,
956 .close = playback_pcm_close,
957 .ioctl = snd_pcm_lib_ioctl,
958 .hw_params = playback_pcm_hw_params,
959 .hw_free = ua101_pcm_hw_free,
960 .prepare = playback_pcm_prepare,
961 .trigger = playback_pcm_trigger,
962 .pointer = playback_pcm_pointer,
963 .page = snd_pcm_get_vmalloc_page,
964};
965
966static const struct uac_format_type_i_discrete_descriptor *
967find_format_descriptor(struct usb_interface *interface)
968{
969 struct usb_host_interface *alt;
970 u8 *extra;
971 int extralen;
972
973 if (interface->num_altsetting != 2) {
974 dev_err(&interface->dev, "invalid num_altsetting\n");
975 return NULL;
976 }
977
978 alt = &interface->altsetting[0];
979 if (alt->desc.bNumEndpoints != 0) {
980 dev_err(&interface->dev, "invalid bNumEndpoints\n");
981 return NULL;
982 }
983
984 alt = &interface->altsetting[1];
985 if (alt->desc.bNumEndpoints != 1) {
986 dev_err(&interface->dev, "invalid bNumEndpoints\n");
987 return NULL;
988 }
989
990 extra = alt->extra;
991 extralen = alt->extralen;
992 while (extralen >= sizeof(struct usb_descriptor_header)) {
993 struct uac_format_type_i_discrete_descriptor *desc;
994
995 desc = (struct uac_format_type_i_discrete_descriptor *)extra;
996 if (desc->bLength > extralen) {
997 dev_err(&interface->dev, "descriptor overflow\n");
998 return NULL;
999 }
1000 if (desc->bLength == UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(1) &&
1001 desc->bDescriptorType == USB_DT_CS_INTERFACE &&
1002 desc->bDescriptorSubtype == UAC_FORMAT_TYPE) {
1003 if (desc->bFormatType != UAC_FORMAT_TYPE_I_PCM ||
1004 desc->bSamFreqType != 1) {
1005 dev_err(&interface->dev,
1006 "invalid format type\n");
1007 return NULL;
1008 }
1009 return desc;
1010 }
1011 extralen -= desc->bLength;
1012 extra += desc->bLength;
1013 }
1014 dev_err(&interface->dev, "sample format descriptor not found\n");
1015 return NULL;
1016}
1017
1018static int detect_usb_format(struct ua101 *ua)
1019{
1020 const struct uac_format_type_i_discrete_descriptor *fmt_capture;
1021 const struct uac_format_type_i_discrete_descriptor *fmt_playback;
1022 const struct usb_endpoint_descriptor *epd;
1023 unsigned int rate2;
1024
1025 fmt_capture = find_format_descriptor(ua->intf[INTF_CAPTURE]);
1026 fmt_playback = find_format_descriptor(ua->intf[INTF_PLAYBACK]);
1027 if (!fmt_capture || !fmt_playback)
1028 return -ENXIO;
1029
1030 switch (fmt_capture->bSubframeSize) {
1031 case 3:
1032 ua->format_bit = SNDRV_PCM_FMTBIT_S24_3LE;
1033 break;
1034 case 4:
1035 ua->format_bit = SNDRV_PCM_FMTBIT_S32_LE;
1036 break;
1037 default:
1038 dev_err(&ua->dev->dev, "sample width is not 24 or 32 bits\n");
1039 return -ENXIO;
1040 }
1041 if (fmt_capture->bSubframeSize != fmt_playback->bSubframeSize) {
1042 dev_err(&ua->dev->dev,
1043 "playback/capture sample widths do not match\n");
1044 return -ENXIO;
1045 }
1046
1047 if (fmt_capture->bBitResolution != 24 ||
1048 fmt_playback->bBitResolution != 24) {
1049 dev_err(&ua->dev->dev, "sample width is not 24 bits\n");
1050 return -ENXIO;
1051 }
1052
1053 ua->rate = combine_triple(fmt_capture->tSamFreq[0]);
1054 rate2 = combine_triple(fmt_playback->tSamFreq[0]);
1055 if (ua->rate != rate2) {
1056 dev_err(&ua->dev->dev,
1057 "playback/capture rates do not match: %u/%u\n",
1058 rate2, ua->rate);
1059 return -ENXIO;
1060 }
1061
1062 switch (ua->dev->speed) {
1063 case USB_SPEED_FULL:
1064 ua->packets_per_second = 1000;
1065 break;
1066 case USB_SPEED_HIGH:
1067 ua->packets_per_second = 8000;
1068 break;
1069 default:
1070 dev_err(&ua->dev->dev, "unknown device speed\n");
1071 return -ENXIO;
1072 }
1073
1074 ua->capture.channels = fmt_capture->bNrChannels;
1075 ua->playback.channels = fmt_playback->bNrChannels;
1076 ua->capture.frame_bytes =
1077 fmt_capture->bSubframeSize * ua->capture.channels;
1078 ua->playback.frame_bytes =
1079 fmt_playback->bSubframeSize * ua->playback.channels;
1080
1081 epd = &ua->intf[INTF_CAPTURE]->altsetting[1].endpoint[0].desc;
1082 if (!usb_endpoint_is_isoc_in(epd)) {
1083 dev_err(&ua->dev->dev, "invalid capture endpoint\n");
1084 return -ENXIO;
1085 }
1086 ua->capture.usb_pipe = usb_rcvisocpipe(ua->dev, usb_endpoint_num(epd));
1087 ua->capture.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize);
1088
1089 epd = &ua->intf[INTF_PLAYBACK]->altsetting[1].endpoint[0].desc;
1090 if (!usb_endpoint_is_isoc_out(epd)) {
1091 dev_err(&ua->dev->dev, "invalid playback endpoint\n");
1092 return -ENXIO;
1093 }
1094 ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, usb_endpoint_num(epd));
1095 ua->playback.max_packet_bytes = le16_to_cpu(epd->wMaxPacketSize);
1096 return 0;
1097}
1098
1099static int alloc_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
1100{
1101 unsigned int remaining_packets, packets, packets_per_page, i;
1102 size_t size;
1103
1104 stream->queue_length = queue_length;
1105 stream->queue_length = max(stream->queue_length,
1106 (unsigned int)MIN_QUEUE_LENGTH);
1107 stream->queue_length = min(stream->queue_length,
1108 (unsigned int)MAX_QUEUE_LENGTH);
1109
1110 /*
1111 * The cache pool sizes used by usb_buffer_alloc() (128, 512, 2048) are
1112 * quite bad when used with the packet sizes of this device (e.g. 280,
1113 * 520, 624). Therefore, we allocate and subdivide entire pages, using
1114 * a smaller buffer only for the last chunk.
1115 */
1116 remaining_packets = stream->queue_length;
1117 packets_per_page = PAGE_SIZE / stream->max_packet_bytes;
1118 for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i) {
1119 packets = min(remaining_packets, packets_per_page);
1120 size = packets * stream->max_packet_bytes;
1121 stream->buffers[i].addr =
1122 usb_buffer_alloc(ua->dev, size, GFP_KERNEL,
1123 &stream->buffers[i].dma);
1124 if (!stream->buffers[i].addr)
1125 return -ENOMEM;
1126 stream->buffers[i].size = size;
1127 remaining_packets -= packets;
1128 if (!remaining_packets)
1129 break;
1130 }
1131 if (remaining_packets) {
1132 dev_err(&ua->dev->dev, "too many packets\n");
1133 return -ENXIO;
1134 }
1135 return 0;
1136}
1137
1138static void free_stream_buffers(struct ua101 *ua, struct ua101_stream *stream)
1139{
1140 unsigned int i;
1141
1142 for (i = 0; i < ARRAY_SIZE(stream->buffers); ++i)
1143 usb_buffer_free(ua->dev,
1144 stream->buffers[i].size,
1145 stream->buffers[i].addr,
1146 stream->buffers[i].dma);
1147}
1148
1149static int alloc_stream_urbs(struct ua101 *ua, struct ua101_stream *stream,
1150 void (*urb_complete)(struct urb *))
1151{
1152 unsigned max_packet_size = stream->max_packet_bytes;
1153 struct ua101_urb *urb;
1154 unsigned int b, u = 0;
1155
1156 for (b = 0; b < ARRAY_SIZE(stream->buffers); ++b) {
1157 unsigned int size = stream->buffers[b].size;
1158 u8 *addr = stream->buffers[b].addr;
1159 dma_addr_t dma = stream->buffers[b].dma;
1160
1161 while (size >= max_packet_size) {
1162 if (u >= stream->queue_length)
1163 goto bufsize_error;
1164 urb = kmalloc(sizeof(*urb), GFP_KERNEL);
1165 if (!urb)
1166 return -ENOMEM;
1167 usb_init_urb(&urb->urb);
1168 urb->urb.dev = ua->dev;
1169 urb->urb.pipe = stream->usb_pipe;
1170 urb->urb.transfer_flags = URB_ISO_ASAP |
1171 URB_NO_TRANSFER_DMA_MAP;
1172 urb->urb.transfer_buffer = addr;
1173 urb->urb.transfer_dma = dma;
1174 urb->urb.transfer_buffer_length = max_packet_size;
1175 urb->urb.number_of_packets = 1;
1176 urb->urb.interval = 1;
1177 urb->urb.context = ua;
1178 urb->urb.complete = urb_complete;
1179 urb->urb.iso_frame_desc[0].offset = 0;
1180 urb->urb.iso_frame_desc[0].length = max_packet_size;
1181 stream->urbs[u++] = urb;
1182 size -= max_packet_size;
1183 addr += max_packet_size;
1184 dma += max_packet_size;
1185 }
1186 }
1187 if (u == stream->queue_length)
1188 return 0;
1189bufsize_error:
1190 dev_err(&ua->dev->dev, "internal buffer size error\n");
1191 return -ENXIO;
1192}
1193
1194static void free_stream_urbs(struct ua101_stream *stream)
1195{
1196 unsigned int i;
1197
1198 for (i = 0; i < stream->queue_length; ++i)
1199 kfree(stream->urbs[i]);
1200}
1201
1202static void free_usb_related_resources(struct ua101 *ua,
1203 struct usb_interface *interface)
1204{
1205 unsigned int i;
1206
1207 free_stream_urbs(&ua->capture);
1208 free_stream_urbs(&ua->playback);
1209 free_stream_buffers(ua, &ua->capture);
1210 free_stream_buffers(ua, &ua->playback);
1211
1212 for (i = 0; i < ARRAY_SIZE(ua->intf); ++i)
1213 if (ua->intf[i]) {
1214 usb_set_intfdata(ua->intf[i], NULL);
1215 if (ua->intf[i] != interface)
1216 usb_driver_release_interface(&ua101_driver,
1217 ua->intf[i]);
1218 }
1219}
1220
1221static void ua101_card_free(struct snd_card *card)
1222{
1223 struct ua101 *ua = card->private_data;
1224
1225 mutex_destroy(&ua->mutex);
1226}
1227
1228static int ua101_probe(struct usb_interface *interface,
1229 const struct usb_device_id *usb_id)
1230{
1231 static const struct snd_usb_midi_endpoint_info midi_ep = {
1232 .out_cables = 0x0001,
1233 .in_cables = 0x0001
1234 };
1235 static const struct snd_usb_audio_quirk midi_quirk = {
1236 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1237 .data = &midi_ep
1238 };
1239 struct snd_card *card;
1240 struct ua101 *ua;
1241 unsigned int card_index, i;
1242 char usb_path[32];
1243 int err;
1244
1245 if (interface->altsetting->desc.bInterfaceNumber != 0)
1246 return -ENODEV;
1247
1248 mutex_lock(&devices_mutex);
1249
1250 for (card_index = 0; card_index < SNDRV_CARDS; ++card_index)
1251 if (enable[card_index] && !(devices_used & (1 << card_index)))
1252 break;
1253 if (card_index >= SNDRV_CARDS) {
1254 mutex_unlock(&devices_mutex);
1255 return -ENOENT;
1256 }
1257 err = snd_card_create(index[card_index], id[card_index], THIS_MODULE,
1258 sizeof(*ua), &card);
1259 if (err < 0) {
1260 mutex_unlock(&devices_mutex);
1261 return err;
1262 }
1263 card->private_free = ua101_card_free;
1264 ua = card->private_data;
1265 ua->dev = interface_to_usbdev(interface);
1266 ua->card = card;
1267 ua->card_index = card_index;
1268 INIT_LIST_HEAD(&ua->midi_list);
1269 spin_lock_init(&ua->lock);
1270 mutex_init(&ua->mutex);
1271 INIT_LIST_HEAD(&ua->ready_playback_urbs);
1272 tasklet_init(&ua->playback_tasklet,
1273 playback_tasklet, (unsigned long)ua);
1274 init_waitqueue_head(&ua->alsa_capture_wait);
1275 init_waitqueue_head(&ua->rate_feedback_wait);
1276 init_waitqueue_head(&ua->alsa_playback_wait);
1277
1278#ifdef UA1A_HACK
1279 if (ua->dev->descriptor.idProduct == cpu_to_le16(0x0018)) {
1280 ua->intf[2] = interface;
1281 ua->intf[0] = usb_ifnum_to_if(ua->dev, 1);
1282 ua->intf[1] = usb_ifnum_to_if(ua->dev, 2);
1283 usb_driver_claim_interface(&ua101_driver, ua->intf[0], ua);
1284 usb_driver_claim_interface(&ua101_driver, ua->intf[1], ua);
1285 } else {
1286#endif
1287 ua->intf[0] = interface;
1288 for (i = 1; i < ARRAY_SIZE(ua->intf); ++i) {
1289 ua->intf[i] = usb_ifnum_to_if(ua->dev, i);
1290 if (!ua->intf[i]) {
1291 dev_err(&ua->dev->dev, "interface %u not found\n", i);
1292 err = -ENXIO;
1293 goto probe_error;
1294 }
1295 err = usb_driver_claim_interface(&ua101_driver,
1296 ua->intf[i], ua);
1297 if (err < 0) {
1298 ua->intf[i] = NULL;
1299 err = -EBUSY;
1300 goto probe_error;
1301 }
1302 }
1303#ifdef UA1A_HACK
1304 }
1305#endif
1306
1307 snd_card_set_dev(card, &interface->dev);
1308
1309#ifdef UA1A_HACK
1310 if (ua->dev->descriptor.idProduct == cpu_to_le16(0x0018)) {
1311 ua->format_bit = SNDRV_PCM_FMTBIT_S16_LE;
1312 ua->rate = 44100;
1313 ua->packets_per_second = 1000;
1314 ua->capture.channels = 2;
1315 ua->playback.channels = 2;
1316 ua->capture.frame_bytes = 4;
1317 ua->playback.frame_bytes = 4;
1318 ua->capture.usb_pipe = usb_rcvisocpipe(ua->dev, 2);
1319 ua->playback.usb_pipe = usb_sndisocpipe(ua->dev, 1);
1320 ua->capture.max_packet_bytes = 192;
1321 ua->playback.max_packet_bytes = 192;
1322 } else {
1323#endif
1324 err = detect_usb_format(ua);
1325 if (err < 0)
1326 goto probe_error;
1327#ifdef UA1A_HACK
1328 }
1329#endif
1330
1331 strcpy(card->driver, "UA-101");
1332 strcpy(card->shortname, "UA-101");
1333 usb_make_path(ua->dev, usb_path, sizeof(usb_path));
1334 snprintf(ua->card->longname, sizeof(ua->card->longname),
1335 "EDIROL UA-101 (serial %s), %u Hz at %s, %s speed",
1336 ua->dev->serial ? ua->dev->serial : "?", ua->rate, usb_path,
1337 ua->dev->speed == USB_SPEED_HIGH ? "high" : "full");
1338
1339 err = alloc_stream_buffers(ua, &ua->capture);
1340 if (err < 0)
1341 goto probe_error;
1342 err = alloc_stream_buffers(ua, &ua->playback);
1343 if (err < 0)
1344 goto probe_error;
1345
1346 err = alloc_stream_urbs(ua, &ua->capture, capture_urb_complete);
1347 if (err < 0)
1348 goto probe_error;
1349 err = alloc_stream_urbs(ua, &ua->playback, playback_urb_complete);
1350 if (err < 0)
1351 goto probe_error;
1352
1353 err = snd_pcm_new(card, "UA-101", 0, 1, 1, &ua->pcm);
1354 if (err < 0)
1355 goto probe_error;
1356 ua->pcm->private_data = ua;
1357 strcpy(ua->pcm->name, "UA-101");
1358 snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_pcm_ops);
1359 snd_pcm_set_ops(ua->pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_pcm_ops);
1360
1361#ifdef UA1A_HACK
1362 if (ua->dev->descriptor.idProduct != cpu_to_le16(0x0018)) {
1363#endif
1364 err = snd_usbmidi_create(card, ua->intf[INTF_MIDI],
1365 &ua->midi_list, &midi_quirk);
1366 if (err < 0)
1367 goto probe_error;
1368#ifdef UA1A_HACK
1369 }
1370#endif
1371
1372 err = snd_card_register(card);
1373 if (err < 0)
1374 goto probe_error;
1375
1376 usb_set_intfdata(interface, ua);
1377 devices_used |= 1 << card_index;
1378
1379 mutex_unlock(&devices_mutex);
1380 return 0;
1381
1382probe_error:
1383 free_usb_related_resources(ua, interface);
1384 snd_card_free(card);
1385 mutex_unlock(&devices_mutex);
1386 return err;
1387}
1388
1389static void ua101_disconnect(struct usb_interface *interface)
1390{
1391 struct ua101 *ua = usb_get_intfdata(interface);
1392 struct list_head *midi;
1393
1394 if (!ua)
1395 return;
1396
1397 mutex_lock(&devices_mutex);
1398
1399 set_bit(DISCONNECTED, &ua->states);
1400 wake_up(&ua->rate_feedback_wait);
1401
1402 /* make sure that userspace cannot create new requests */
1403 snd_card_disconnect(ua->card);
1404
1405 /* make sure that there are no pending USB requests */
1406 __list_for_each(midi, &ua->midi_list)
1407 snd_usbmidi_disconnect(midi);
1408 abort_alsa_playback(ua);
1409 abort_alsa_capture(ua);
1410 mutex_lock(&ua->mutex);
1411 stop_usb_playback(ua);
1412 stop_usb_capture(ua);
1413 mutex_unlock(&ua->mutex);
1414
1415 free_usb_related_resources(ua, interface);
1416
1417 devices_used &= ~(1 << ua->card_index);
1418
1419 snd_card_free_when_closed(ua->card);
1420
1421 mutex_unlock(&devices_mutex);
1422}
1423
1424static struct usb_device_id ua101_ids[] = {
1425#ifdef UA1A_HACK
1426 { USB_DEVICE(0x0582, 0x0018) },
1427#endif
1428 { USB_DEVICE(0x0582, 0x007d) },
1429 { USB_DEVICE(0x0582, 0x008d) },
1430 { }
1431};
1432MODULE_DEVICE_TABLE(usb, ua101_ids);
1433
1434static struct usb_driver ua101_driver = {
1435 .name = "snd-ua101",
1436 .id_table = ua101_ids,
1437 .probe = ua101_probe,
1438 .disconnect = ua101_disconnect,
1439#if 0
1440 .suspend = ua101_suspend,
1441 .resume = ua101_resume,
1442#endif
1443};
1444
1445static int __init alsa_card_ua101_init(void)
1446{
1447 return usb_register(&ua101_driver);
1448}
1449
1450static void __exit alsa_card_ua101_exit(void)
1451{
1452 usb_deregister(&ua101_driver);
1453 mutex_destroy(&devices_mutex);
1454}
1455
1456module_init(alsa_card_ua101_init);
1457module_exit(alsa_card_ua101_exit);
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index 4963defee18a..af8869a8a79e 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -3142,59 +3142,6 @@ static int create_ua1000_quirk(struct snd_usb_audio *chip,
3142 return 0; 3142 return 0;
3143} 3143}
3144 3144
3145/*
3146 * Create a stream for an Edirol UA-101 interface.
3147 * Copy, paste and modify from Edirol UA-1000
3148 */
3149static int create_ua101_quirk(struct snd_usb_audio *chip,
3150 struct usb_interface *iface,
3151 const struct snd_usb_audio_quirk *quirk)
3152{
3153 static const struct audioformat ua101_format = {
3154 .format = SNDRV_PCM_FORMAT_S32_LE,
3155 .fmt_type = USB_FORMAT_TYPE_I,
3156 .altsetting = 1,
3157 .altset_idx = 1,
3158 .attributes = 0,
3159 .rates = SNDRV_PCM_RATE_CONTINUOUS,
3160 };
3161 struct usb_host_interface *alts;
3162 struct usb_interface_descriptor *altsd;
3163 struct audioformat *fp;
3164 int stream, err;
3165
3166 if (iface->num_altsetting != 2)
3167 return -ENXIO;
3168 alts = &iface->altsetting[1];
3169 altsd = get_iface_desc(alts);
3170 if (alts->extralen != 18 || alts->extra[1] != USB_DT_CS_INTERFACE ||
3171 altsd->bNumEndpoints != 1)
3172 return -ENXIO;
3173
3174 fp = kmemdup(&ua101_format, sizeof(*fp), GFP_KERNEL);
3175 if (!fp)
3176 return -ENOMEM;
3177
3178 fp->channels = alts->extra[11];
3179 fp->iface = altsd->bInterfaceNumber;
3180 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
3181 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
3182 fp->datainterval = parse_datainterval(chip, alts);
3183 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
3184 fp->rate_max = fp->rate_min = combine_triple(&alts->extra[15]);
3185
3186 stream = (fp->endpoint & USB_DIR_IN)
3187 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
3188 err = add_audio_endpoint(chip, stream, fp);
3189 if (err < 0) {
3190 kfree(fp);
3191 return err;
3192 }
3193 /* FIXME: playback must be synchronized to capture */
3194 usb_set_interface(chip->dev, fp->iface, 0);
3195 return 0;
3196}
3197
3198static int snd_usb_create_quirk(struct snd_usb_audio *chip, 3145static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3199 struct usb_interface *iface, 3146 struct usb_interface *iface,
3200 const struct snd_usb_audio_quirk *quirk); 3147 const struct snd_usb_audio_quirk *quirk);
@@ -3406,7 +3353,6 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3406 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, 3353 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
3407 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 3354 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
3408 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk, 3355 [QUIRK_AUDIO_EDIROL_UA1000] = create_ua1000_quirk,
3409 [QUIRK_AUDIO_EDIROL_UA101] = create_ua101_quirk,
3410 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk 3356 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk
3411 }; 3357 };
3412 3358
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 40ba8115fb81..9826337c76b8 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -159,7 +159,6 @@ enum quirk_type {
159 QUIRK_AUDIO_STANDARD_INTERFACE, 159 QUIRK_AUDIO_STANDARD_INTERFACE,
160 QUIRK_AUDIO_FIXED_ENDPOINT, 160 QUIRK_AUDIO_FIXED_ENDPOINT,
161 QUIRK_AUDIO_EDIROL_UA1000, 161 QUIRK_AUDIO_EDIROL_UA1000,
162 QUIRK_AUDIO_EDIROL_UA101,
163 QUIRK_AUDIO_EDIROL_UAXX, 162 QUIRK_AUDIO_EDIROL_UAXX,
164 163
165 QUIRK_TYPE_COUNT 164 QUIRK_TYPE_COUNT
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index a892bda03df9..bd6706c2d534 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -1266,37 +1266,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1266 } 1266 }
1267 } 1267 }
1268}, 1268},
1269/* Roland UA-101 in High-Speed Mode only */
1270{
1271 USB_DEVICE(0x0582, 0x007d),
1272 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1273 .vendor_name = "Roland",
1274 .product_name = "UA-101",
1275 .ifnum = QUIRK_ANY_INTERFACE,
1276 .type = QUIRK_COMPOSITE,
1277 .data = (const struct snd_usb_audio_quirk[]) {
1278 {
1279 .ifnum = 0,
1280 .type = QUIRK_AUDIO_EDIROL_UA101
1281 },
1282 {
1283 .ifnum = 1,
1284 .type = QUIRK_AUDIO_EDIROL_UA101
1285 },
1286 {
1287 .ifnum = 2,
1288 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1289 .data = & (const struct snd_usb_midi_endpoint_info) {
1290 .out_cables = 0x0001,
1291 .in_cables = 0x0001
1292 }
1293 },
1294 {
1295 .ifnum = -1
1296 }
1297 }
1298 }
1299},
1300{ 1269{
1301 /* has ID 0x0081 when not in "Advanced Driver" mode */ 1270 /* has ID 0x0081 when not in "Advanced Driver" mode */
1302 USB_DEVICE(0x0582, 0x0080), 1271 USB_DEVICE(0x0582, 0x0080),