]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - sound/firewire/bebob/bebob.c
ALSA: bebob: Prepare for device specific operations
[mirror_ubuntu-bionic-kernel.git] / sound / firewire / bebob / bebob.c
1 /*
2 * bebob.c - a part of driver for BeBoB based devices
3 *
4 * Copyright (c) 2013-2014 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9 /*
10 * BeBoB is 'BridgeCo enhanced Breakout Box'. This is installed to firewire
11 * devices with DM1000/DM1100/DM1500 chipset. It gives common way for host
12 * system to handle BeBoB based devices.
13 */
14
15 #include "bebob.h"
16
17 MODULE_DESCRIPTION("BridgeCo BeBoB driver");
18 MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
19 MODULE_LICENSE("GPL v2");
20
21 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
22 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
23 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
24
25 module_param_array(index, int, NULL, 0444);
26 MODULE_PARM_DESC(index, "card index");
27 module_param_array(id, charp, NULL, 0444);
28 MODULE_PARM_DESC(id, "ID string");
29 module_param_array(enable, bool, NULL, 0444);
30 MODULE_PARM_DESC(enable, "enable BeBoB sound card");
31
32 static DEFINE_MUTEX(devices_mutex);
33 static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
34
35 /* Offsets from information register. */
36 #define INFO_OFFSET_GUID 0x10
37 #define INFO_OFFSET_HW_MODEL_ID 0x18
38 #define INFO_OFFSET_HW_MODEL_REVISION 0x1c
39
40 #define VEN_EDIROL 0x000040ab
41 #define VEN_PRESONUS 0x00000a92
42 #define VEN_BRIDGECO 0x000007f5
43 #define VEN_MACKIE 0x0000000f
44 #define VEN_STANTON 0x00001260
45 #define VEN_TASCAM 0x0000022e
46 #define VEN_BEHRINGER 0x00001564
47 #define VEN_APOGEE 0x000003db
48 #define VEN_ESI 0x00000f1b
49 #define VEN_ACOUSTIC 0x00000002
50 #define VEN_CME 0x0000000a
51 #define VEN_PHONIC 0x00001496
52 #define VEN_LYNX 0x000019e5
53 #define VEN_ICON 0x00001a9e
54 #define VEN_PRISMSOUND 0x00001198
55
56 static int
57 name_device(struct snd_bebob *bebob, unsigned int vendor_id)
58 {
59 struct fw_device *fw_dev = fw_parent_device(bebob->unit);
60 char vendor[24] = {0};
61 char model[32] = {0};
62 u32 id;
63 u32 data[2] = {0};
64 u32 revision;
65 int err;
66
67 /* get vendor name from root directory */
68 err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
69 vendor, sizeof(vendor));
70 if (err < 0)
71 goto end;
72
73 /* get model name from unit directory */
74 err = fw_csr_string(bebob->unit->directory, CSR_MODEL,
75 model, sizeof(model));
76 if (err < 0)
77 goto end;
78
79 /* get hardware id */
80 err = snd_bebob_read_quad(bebob->unit, INFO_OFFSET_HW_MODEL_ID,
81 &id);
82 if (err < 0)
83 goto end;
84
85 /* get hardware revision */
86 err = snd_bebob_read_quad(bebob->unit, INFO_OFFSET_HW_MODEL_REVISION,
87 &revision);
88 if (err < 0)
89 goto end;
90
91 /* get GUID */
92 err = snd_bebob_read_block(bebob->unit, INFO_OFFSET_GUID,
93 data, sizeof(data));
94 if (err < 0)
95 goto end;
96
97 strcpy(bebob->card->driver, "BeBoB");
98 strcpy(bebob->card->shortname, model);
99 strcpy(bebob->card->mixername, model);
100 snprintf(bebob->card->longname, sizeof(bebob->card->longname),
101 "%s %s (id:%d, rev:%d), GUID %08x%08x at %s, S%d",
102 vendor, model, id, revision,
103 data[0], data[1], dev_name(&bebob->unit->device),
104 100 << fw_dev->max_speed);
105 end:
106 return err;
107 }
108
109 static void
110 bebob_card_free(struct snd_card *card)
111 {
112 struct snd_bebob *bebob = card->private_data;
113
114 if (bebob->card_index >= 0) {
115 mutex_lock(&devices_mutex);
116 clear_bit(bebob->card_index, devices_used);
117 mutex_unlock(&devices_mutex);
118 }
119
120 mutex_destroy(&bebob->mutex);
121 }
122
123 static int
124 bebob_probe(struct fw_unit *unit,
125 const struct ieee1394_device_id *entry)
126 {
127 struct snd_card *card;
128 struct snd_bebob *bebob;
129 const struct snd_bebob_spec *spec;
130 unsigned int card_index;
131 int err;
132
133 mutex_lock(&devices_mutex);
134
135 for (card_index = 0; card_index < SNDRV_CARDS; card_index++) {
136 if (!test_bit(card_index, devices_used) && enable[card_index])
137 break;
138 }
139 if (card_index >= SNDRV_CARDS) {
140 err = -ENOENT;
141 goto end;
142 }
143
144 spec = (const struct snd_bebob_spec *)entry->driver_data;
145 if (spec == NULL) {
146 err = -ENOSYS;
147 goto end;
148 }
149
150 err = snd_card_new(&unit->device, index[card_index], id[card_index],
151 THIS_MODULE, sizeof(struct snd_bebob), &card);
152 if (err < 0)
153 goto end;
154 bebob = card->private_data;
155 bebob->card_index = card_index;
156 set_bit(card_index, devices_used);
157 card->private_free = bebob_card_free;
158
159 bebob->card = card;
160 bebob->unit = unit;
161 bebob->spec = spec;
162 mutex_init(&bebob->mutex);
163 spin_lock_init(&bebob->lock);
164 init_waitqueue_head(&bebob->hwdep_wait);
165
166 err = name_device(bebob, entry->vendor_id);
167 if (err < 0)
168 goto error;
169
170 err = snd_bebob_stream_discover(bebob);
171 if (err < 0)
172 goto error;
173
174 snd_bebob_proc_init(bebob);
175
176 if ((bebob->midi_input_ports > 0) ||
177 (bebob->midi_output_ports > 0)) {
178 err = snd_bebob_create_midi_devices(bebob);
179 if (err < 0)
180 goto error;
181 }
182
183 err = snd_bebob_create_pcm_devices(bebob);
184 if (err < 0)
185 goto error;
186
187 err = snd_bebob_create_hwdep_device(bebob);
188 if (err < 0)
189 goto error;
190
191 err = snd_bebob_stream_init_duplex(bebob);
192 if (err < 0)
193 goto error;
194
195 err = snd_card_register(card);
196 if (err < 0) {
197 snd_bebob_stream_destroy_duplex(bebob);
198 goto error;
199 }
200
201 dev_set_drvdata(&unit->device, bebob);
202 end:
203 mutex_unlock(&devices_mutex);
204 return err;
205 error:
206 mutex_unlock(&devices_mutex);
207 snd_card_free(card);
208 return err;
209 }
210
211 static void
212 bebob_update(struct fw_unit *unit)
213 {
214 struct snd_bebob *bebob = dev_get_drvdata(&unit->device);
215 fcp_bus_reset(bebob->unit);
216 snd_bebob_stream_update_duplex(bebob);
217 }
218
219 static void bebob_remove(struct fw_unit *unit)
220 {
221 struct snd_bebob *bebob = dev_get_drvdata(&unit->device);
222 snd_bebob_stream_destroy_duplex(bebob);
223 snd_card_disconnect(bebob->card);
224 snd_card_free_when_closed(bebob->card);
225 }
226
227 struct snd_bebob_rate_spec normal_rate_spec = {
228 .get = &snd_bebob_stream_get_rate,
229 .set = &snd_bebob_stream_set_rate
230 };
231 static const struct snd_bebob_spec spec_normal = {
232 .clock = NULL,
233 .rate = &normal_rate_spec,
234 .meter = NULL
235 };
236
237 static const struct ieee1394_device_id bebob_id_table[] = {
238 /* Edirol, FA-66 */
239 SND_BEBOB_DEV_ENTRY(VEN_EDIROL, 0x00010049, &spec_normal),
240 /* Edirol, FA-101 */
241 SND_BEBOB_DEV_ENTRY(VEN_EDIROL, 0x00010048, &spec_normal),
242 /* Presonus, FIREBOX */
243 SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010000, &spec_normal),
244 /* PreSonus, FIREPOD/FP10 */
245 SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010066, &spec_normal),
246 /* PreSonus, Inspire1394 */
247 SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010001, &spec_normal),
248 /* BridgeCo, RDAudio1 */
249 SND_BEBOB_DEV_ENTRY(VEN_BRIDGECO, 0x00010048, &spec_normal),
250 /* BridgeCo, Audio5 */
251 SND_BEBOB_DEV_ENTRY(VEN_BRIDGECO, 0x00010049, &spec_normal),
252 /* Mackie, Onyx 1220/1620/1640 (Firewire I/O Card) */
253 SND_BEBOB_DEV_ENTRY(VEN_MACKIE, 0x00010065, &spec_normal),
254 /* Mackie, d.2 (Firewire Option) */
255 SND_BEBOB_DEV_ENTRY(VEN_MACKIE, 0x00010067, &spec_normal),
256 /* Stanton, ScratchAmp */
257 SND_BEBOB_DEV_ENTRY(VEN_STANTON, 0x00000001, &spec_normal),
258 /* Tascam, IF-FW DM */
259 SND_BEBOB_DEV_ENTRY(VEN_TASCAM, 0x00010067, &spec_normal),
260 /* Behringer, XENIX UFX 1204 */
261 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00001204, &spec_normal),
262 /* Behringer, XENIX UFX 1604 */
263 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00001604, &spec_normal),
264 /* Behringer, Digital Mixer X32 series (X-UF Card) */
265 SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00000006, &spec_normal),
266 /* Apogee Electronics, Rosetta 200/400 (X-FireWire card) */
267 /* Apogee Electronics, DA/AD/DD-16X (X-FireWire card) */
268 SND_BEBOB_DEV_ENTRY(VEN_APOGEE, 0x00010048, &spec_normal),
269 /* Apogee Electronics, Ensemble */
270 SND_BEBOB_DEV_ENTRY(VEN_APOGEE, 0x00001eee, &spec_normal),
271 /* ESI, Quatafire610 */
272 SND_BEBOB_DEV_ENTRY(VEN_ESI, 0x00010064, &spec_normal),
273 /* AcousticReality, eARMasterOne */
274 SND_BEBOB_DEV_ENTRY(VEN_ACOUSTIC, 0x00000002, &spec_normal),
275 /* CME, MatrixKFW */
276 SND_BEBOB_DEV_ENTRY(VEN_CME, 0x00030000, &spec_normal),
277 /* Phonic, Helix Board 12 MkII */
278 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00050000, &spec_normal),
279 /* Phonic, Helix Board 18 MkII */
280 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00060000, &spec_normal),
281 /* Phonic, Helix Board 24 MkII */
282 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00070000, &spec_normal),
283 /* Phonic, Helix Board 12 Universal/18 Universal/24 Universal */
284 SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00000000, &spec_normal),
285 /* Lynx, Aurora 8/16 (LT-FW) */
286 SND_BEBOB_DEV_ENTRY(VEN_LYNX, 0x00000001, &spec_normal),
287 /* ICON, FireXon */
288 SND_BEBOB_DEV_ENTRY(VEN_ICON, 0x00000001, &spec_normal),
289 /* PrismSound, Orpheus */
290 SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x00010048, &spec_normal),
291 /* PrismSound, ADA-8XR */
292 SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x0000ada8, &spec_normal),
293 /* IDs are unknown but able to be supported */
294 /* Apogee, Mini-ME Firewire */
295 /* Apogee, Mini-DAC Firewire */
296 /* Behringer, F-Control Audio 1616 */
297 /* Behringer, F-Control Audio 610 */
298 /* Cakawalk, Sonar Power Studio 66 */
299 /* CME, UF400e */
300 /* ESI, Quotafire XL */
301 /* Infrasonic, DewX */
302 /* Infrasonic, Windy6 */
303 /* Mackie, Digital X Bus x.200 */
304 /* Mackie, Digital X Bus x.400 */
305 /* Phonic, HB 12 */
306 /* Phonic, HB 24 */
307 /* Phonic, HB 18 */
308 /* Phonic, FireFly 202 */
309 /* Phonic, FireFly 302 */
310 /* Rolf Spuler, Firewire Guitar */
311 {}
312 };
313 MODULE_DEVICE_TABLE(ieee1394, bebob_id_table);
314
315 static struct fw_driver bebob_driver = {
316 .driver = {
317 .owner = THIS_MODULE,
318 .name = "snd-bebob",
319 .bus = &fw_bus_type,
320 },
321 .probe = bebob_probe,
322 .update = bebob_update,
323 .remove = bebob_remove,
324 .id_table = bebob_id_table,
325 };
326
327 static int __init
328 snd_bebob_init(void)
329 {
330 return driver_register(&bebob_driver.driver);
331 }
332
333 static void __exit
334 snd_bebob_exit(void)
335 {
336 driver_unregister(&bebob_driver.driver);
337 mutex_destroy(&devices_mutex);
338 }
339
340 module_init(snd_bebob_init);
341 module_exit(snd_bebob_exit);