Commit | Line | Data |
---|---|---|
fd6f4b0d TS |
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 | unsigned int card_index; | |
130 | int err; | |
131 | ||
132 | mutex_lock(&devices_mutex); | |
133 | ||
134 | for (card_index = 0; card_index < SNDRV_CARDS; card_index++) { | |
135 | if (!test_bit(card_index, devices_used) && enable[card_index]) | |
136 | break; | |
137 | } | |
138 | if (card_index >= SNDRV_CARDS) { | |
139 | err = -ENOENT; | |
140 | goto end; | |
141 | } | |
142 | ||
143 | err = snd_card_new(&unit->device, index[card_index], id[card_index], | |
144 | THIS_MODULE, sizeof(struct snd_bebob), &card); | |
145 | if (err < 0) | |
146 | goto end; | |
147 | bebob = card->private_data; | |
148 | bebob->card_index = card_index; | |
149 | set_bit(card_index, devices_used); | |
150 | card->private_free = bebob_card_free; | |
151 | ||
152 | bebob->card = card; | |
153 | bebob->unit = unit; | |
154 | mutex_init(&bebob->mutex); | |
155 | spin_lock_init(&bebob->lock); | |
618eabea | 156 | init_waitqueue_head(&bebob->hwdep_wait); |
fd6f4b0d TS |
157 | |
158 | err = name_device(bebob, entry->vendor_id); | |
159 | if (err < 0) | |
160 | goto error; | |
161 | ||
eb7b3a05 | 162 | err = snd_bebob_stream_discover(bebob); |
fd6f4b0d TS |
163 | if (err < 0) |
164 | goto error; | |
eb7b3a05 | 165 | |
ad9697ba TS |
166 | snd_bebob_proc_init(bebob); |
167 | ||
248b7802 TS |
168 | if ((bebob->midi_input_ports > 0) || |
169 | (bebob->midi_output_ports > 0)) { | |
170 | err = snd_bebob_create_midi_devices(bebob); | |
171 | if (err < 0) | |
172 | goto error; | |
173 | } | |
174 | ||
fbbebd2c TS |
175 | err = snd_bebob_create_pcm_devices(bebob); |
176 | if (err < 0) | |
177 | goto error; | |
178 | ||
618eabea TS |
179 | err = snd_bebob_create_hwdep_device(bebob); |
180 | if (err < 0) | |
181 | goto error; | |
182 | ||
eb7b3a05 TS |
183 | err = snd_bebob_stream_init_duplex(bebob); |
184 | if (err < 0) | |
185 | goto error; | |
186 | ||
187 | err = snd_card_register(card); | |
188 | if (err < 0) { | |
189 | snd_bebob_stream_destroy_duplex(bebob); | |
190 | goto error; | |
191 | } | |
192 | ||
fd6f4b0d TS |
193 | dev_set_drvdata(&unit->device, bebob); |
194 | end: | |
195 | mutex_unlock(&devices_mutex); | |
196 | return err; | |
197 | error: | |
198 | mutex_unlock(&devices_mutex); | |
199 | snd_card_free(card); | |
200 | return err; | |
201 | } | |
202 | ||
203 | static void | |
204 | bebob_update(struct fw_unit *unit) | |
205 | { | |
206 | struct snd_bebob *bebob = dev_get_drvdata(&unit->device); | |
207 | fcp_bus_reset(bebob->unit); | |
eb7b3a05 | 208 | snd_bebob_stream_update_duplex(bebob); |
fd6f4b0d TS |
209 | } |
210 | ||
211 | static void bebob_remove(struct fw_unit *unit) | |
212 | { | |
213 | struct snd_bebob *bebob = dev_get_drvdata(&unit->device); | |
eb7b3a05 | 214 | snd_bebob_stream_destroy_duplex(bebob); |
fd6f4b0d TS |
215 | snd_card_disconnect(bebob->card); |
216 | snd_card_free_when_closed(bebob->card); | |
217 | } | |
218 | ||
219 | static const struct ieee1394_device_id bebob_id_table[] = { | |
220 | /* Edirol, FA-66 */ | |
221 | SND_BEBOB_DEV_ENTRY(VEN_EDIROL, 0x00010049), | |
222 | /* Edirol, FA-101 */ | |
223 | SND_BEBOB_DEV_ENTRY(VEN_EDIROL, 0x00010048), | |
224 | /* Presonus, FIREBOX */ | |
225 | SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010000), | |
226 | /* PreSonus, FIREPOD/FP10 */ | |
227 | SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010066), | |
228 | /* PreSonus, Inspire1394 */ | |
229 | SND_BEBOB_DEV_ENTRY(VEN_PRESONUS, 0x00010001), | |
230 | /* BridgeCo, RDAudio1 */ | |
231 | SND_BEBOB_DEV_ENTRY(VEN_BRIDGECO, 0x00010048), | |
232 | /* BridgeCo, Audio5 */ | |
233 | SND_BEBOB_DEV_ENTRY(VEN_BRIDGECO, 0x00010049), | |
234 | /* Mackie, Onyx 1220/1620/1640 (Firewire I/O Card) */ | |
235 | SND_BEBOB_DEV_ENTRY(VEN_MACKIE, 0x00010065), | |
236 | /* Mackie, d.2 (Firewire Option) */ | |
237 | SND_BEBOB_DEV_ENTRY(VEN_MACKIE, 0x00010067), | |
238 | /* Stanton, ScratchAmp */ | |
239 | SND_BEBOB_DEV_ENTRY(VEN_STANTON, 0x00000001), | |
240 | /* Tascam, IF-FW DM */ | |
241 | SND_BEBOB_DEV_ENTRY(VEN_TASCAM, 0x00010067), | |
242 | /* Behringer, XENIX UFX 1204 */ | |
243 | SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00001204), | |
244 | /* Behringer, XENIX UFX 1604 */ | |
245 | SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00001604), | |
246 | /* Behringer, Digital Mixer X32 series (X-UF Card) */ | |
247 | SND_BEBOB_DEV_ENTRY(VEN_BEHRINGER, 0x00000006), | |
248 | /* Apogee Electronics, Rosetta 200/400 (X-FireWire card) */ | |
249 | /* Apogee Electronics, DA/AD/DD-16X (X-FireWire card) */ | |
250 | SND_BEBOB_DEV_ENTRY(VEN_APOGEE, 0x00010048), | |
251 | /* Apogee Electronics, Ensemble */ | |
252 | SND_BEBOB_DEV_ENTRY(VEN_APOGEE, 0x00001eee), | |
253 | /* ESI, Quatafire610 */ | |
254 | SND_BEBOB_DEV_ENTRY(VEN_ESI, 0x00010064), | |
255 | /* AcousticReality, eARMasterOne */ | |
256 | SND_BEBOB_DEV_ENTRY(VEN_ACOUSTIC, 0x00000002), | |
257 | /* CME, MatrixKFW */ | |
258 | SND_BEBOB_DEV_ENTRY(VEN_CME, 0x00030000), | |
259 | /* Phonic, Helix Board 12 MkII */ | |
260 | SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00050000), | |
261 | /* Phonic, Helix Board 18 MkII */ | |
262 | SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00060000), | |
263 | /* Phonic, Helix Board 24 MkII */ | |
264 | SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00070000), | |
265 | /* Phonic, Helix Board 12 Universal/18 Universal/24 Universal */ | |
266 | SND_BEBOB_DEV_ENTRY(VEN_PHONIC, 0x00000000), | |
267 | /* Lynx, Aurora 8/16 (LT-FW) */ | |
268 | SND_BEBOB_DEV_ENTRY(VEN_LYNX, 0x00000001), | |
269 | /* ICON, FireXon */ | |
270 | SND_BEBOB_DEV_ENTRY(VEN_ICON, 0x00000001), | |
271 | /* PrismSound, Orpheus */ | |
272 | SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x00010048), | |
273 | /* PrismSound, ADA-8XR */ | |
274 | SND_BEBOB_DEV_ENTRY(VEN_PRISMSOUND, 0x0000ada8), | |
275 | /* IDs are unknown but able to be supported */ | |
276 | /* Apogee, Mini-ME Firewire */ | |
277 | /* Apogee, Mini-DAC Firewire */ | |
278 | /* Behringer, F-Control Audio 1616 */ | |
279 | /* Behringer, F-Control Audio 610 */ | |
280 | /* Cakawalk, Sonar Power Studio 66 */ | |
281 | /* CME, UF400e */ | |
282 | /* ESI, Quotafire XL */ | |
283 | /* Infrasonic, DewX */ | |
284 | /* Infrasonic, Windy6 */ | |
285 | /* Mackie, Digital X Bus x.200 */ | |
286 | /* Mackie, Digital X Bus x.400 */ | |
287 | /* Phonic, HB 12 */ | |
288 | /* Phonic, HB 24 */ | |
289 | /* Phonic, HB 18 */ | |
290 | /* Phonic, FireFly 202 */ | |
291 | /* Phonic, FireFly 302 */ | |
292 | /* Rolf Spuler, Firewire Guitar */ | |
293 | {} | |
294 | }; | |
295 | MODULE_DEVICE_TABLE(ieee1394, bebob_id_table); | |
296 | ||
297 | static struct fw_driver bebob_driver = { | |
298 | .driver = { | |
299 | .owner = THIS_MODULE, | |
300 | .name = "snd-bebob", | |
301 | .bus = &fw_bus_type, | |
302 | }, | |
303 | .probe = bebob_probe, | |
304 | .update = bebob_update, | |
305 | .remove = bebob_remove, | |
306 | .id_table = bebob_id_table, | |
307 | }; | |
308 | ||
309 | static int __init | |
310 | snd_bebob_init(void) | |
311 | { | |
312 | return driver_register(&bebob_driver.driver); | |
313 | } | |
314 | ||
315 | static void __exit | |
316 | snd_bebob_exit(void) | |
317 | { | |
318 | driver_unregister(&bebob_driver.driver); | |
319 | mutex_destroy(&devices_mutex); | |
320 | } | |
321 | ||
322 | module_init(snd_bebob_init); | |
323 | module_exit(snd_bebob_exit); |