]> Git Repo - linux.git/blob - sound/firewire/oxfw/oxfw.c
ALSA: oxfw: obsolete scs1x module
[linux.git] / sound / firewire / oxfw / oxfw.c
1 /*
2  * oxfw.c - a part of driver for OXFW970/971 based devices
3  *
4  * Copyright (c) Clemens Ladisch <[email protected]>
5  * Licensed under the terms of the GNU General Public License, version 2.
6  */
7
8 #include "oxfw.h"
9
10 #define OXFORD_FIRMWARE_ID_ADDRESS      (CSR_REGISTER_BASE + 0x50000)
11 /* 0x970?vvvv or 0x971?vvvv, where vvvv = firmware version */
12
13 #define OXFORD_HARDWARE_ID_ADDRESS      (CSR_REGISTER_BASE + 0x90020)
14 #define OXFORD_HARDWARE_ID_OXFW970      0x39443841
15 #define OXFORD_HARDWARE_ID_OXFW971      0x39373100
16
17 #define VENDOR_LOUD             0x000ff2
18 #define VENDOR_GRIFFIN          0x001292
19 #define VENDOR_BEHRINGER        0x001564
20 #define VENDOR_LACIE            0x00d04b
21 #define VENDOR_TASCAM           0x00022e
22 #define OUI_STANTON             0x001260
23
24 #define MODEL_SATELLITE         0x00200f
25
26 #define SPECIFIER_1394TA        0x00a02d
27 #define VERSION_AVC             0x010001
28
29 MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
30 MODULE_AUTHOR("Clemens Ladisch <[email protected]>");
31 MODULE_LICENSE("GPL v2");
32 MODULE_ALIAS("snd-firewire-speakers");
33 MODULE_ALIAS("snd-scs1x");
34
35 struct compat_info {
36         const char *driver_name;
37         const char *vendor_name;
38         const char *model_name;
39 };
40
41 static bool detect_loud_models(struct fw_unit *unit)
42 {
43         const char *const models[] = {
44                 "Onyxi",
45                 "Onyx-i",
46                 "d.Pro",
47                 "Mackie Onyx Satellite",
48                 "Tapco LINK.firewire 4x6",
49                 "U.420"};
50         char model[32];
51         unsigned int i;
52         int err;
53
54         err = fw_csr_string(unit->directory, CSR_MODEL,
55                             model, sizeof(model));
56         if (err < 0)
57                 return false;
58
59         for (i = 0; i < ARRAY_SIZE(models); i++) {
60                 if (strcmp(models[i], model) == 0)
61                         break;
62         }
63
64         return (i < ARRAY_SIZE(models));
65 }
66
67 static int name_card(struct snd_oxfw *oxfw)
68 {
69         struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
70         const struct compat_info *info;
71         char vendor[24];
72         char model[32];
73         const char *d, *v, *m;
74         u32 firmware;
75         int err;
76
77         /* get vendor name from root directory */
78         err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
79                             vendor, sizeof(vendor));
80         if (err < 0)
81                 goto end;
82
83         /* get model name from unit directory */
84         err = fw_csr_string(oxfw->unit->directory, CSR_MODEL,
85                             model, sizeof(model));
86         if (err < 0)
87                 goto end;
88
89         err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST,
90                                  OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0);
91         if (err < 0)
92                 goto end;
93         be32_to_cpus(&firmware);
94
95         /* to apply card definitions */
96         if (oxfw->entry->vendor_id == VENDOR_GRIFFIN ||
97             oxfw->entry->vendor_id == VENDOR_LACIE) {
98                 info = (const struct compat_info *)oxfw->entry->driver_data;
99                 d = info->driver_name;
100                 v = info->vendor_name;
101                 m = info->model_name;
102         } else {
103                 d = "OXFW";
104                 v = vendor;
105                 m = model;
106         }
107
108         strcpy(oxfw->card->driver, d);
109         strcpy(oxfw->card->mixername, m);
110         strcpy(oxfw->card->shortname, m);
111
112         snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
113                  "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
114                  v, m, firmware >> 20, firmware & 0xffff,
115                  fw_dev->config_rom[3], fw_dev->config_rom[4],
116                  dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
117 end:
118         return err;
119 }
120
121 /*
122  * This module releases the FireWire unit data after all ALSA character devices
123  * are released by applications. This is for releasing stream data or finishing
124  * transactions safely. Thus at returning from .remove(), this module still keep
125  * references for the unit.
126  */
127 static void oxfw_card_free(struct snd_card *card)
128 {
129         struct snd_oxfw *oxfw = card->private_data;
130         unsigned int i;
131
132         snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
133         if (oxfw->has_output)
134                 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
135
136         fw_unit_put(oxfw->unit);
137
138         for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
139                 kfree(oxfw->tx_stream_formats[i]);
140                 kfree(oxfw->rx_stream_formats[i]);
141         }
142
143         kfree(oxfw->spec);
144         mutex_destroy(&oxfw->mutex);
145 }
146
147 static int detect_quirks(struct snd_oxfw *oxfw)
148 {
149         struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
150         struct fw_csr_iterator it;
151         int key, val;
152         int vendor, model;
153
154         /*
155          * Add ALSA control elements for two models to keep compatibility to
156          * old firewire-speaker module.
157          */
158         if (oxfw->entry->vendor_id == VENDOR_GRIFFIN)
159                 return snd_oxfw_add_spkr(oxfw, false);
160         if (oxfw->entry->vendor_id == VENDOR_LACIE)
161                 return snd_oxfw_add_spkr(oxfw, true);
162
163         /*
164          * Stanton models supports asynchronous transactions for unique MIDI
165          * messages.
166          */
167         if (oxfw->entry->vendor_id == OUI_STANTON)
168                 return snd_oxfw_scs1x_add(oxfw);
169
170         /*
171          * TASCAM FireOne has physical control and requires a pair of additional
172          * MIDI ports.
173          */
174         if (oxfw->entry->vendor_id == VENDOR_TASCAM) {
175                 oxfw->midi_input_ports++;
176                 oxfw->midi_output_ports++;
177                 return 0;
178         }
179
180         /* Seek from Root Directory of Config ROM. */
181         vendor = model = 0;
182         fw_csr_iterator_init(&it, fw_dev->config_rom + 5);
183         while (fw_csr_iterator_next(&it, &key, &val)) {
184                 if (key == CSR_VENDOR)
185                         vendor = val;
186                 else if (key == CSR_MODEL)
187                         model = val;
188         }
189
190         /*
191          * Mackie Onyx Satellite with base station has a quirk to report a wrong
192          * value in 'dbs' field of CIP header against its format information.
193          */
194         if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE)
195                 oxfw->wrong_dbs = true;
196
197         return 0;
198 }
199
200 static int oxfw_probe(struct fw_unit *unit,
201                       const struct ieee1394_device_id *entry)
202 {
203         struct snd_card *card;
204         struct snd_oxfw *oxfw;
205         int err;
206
207         if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit))
208                 return -ENODEV;
209
210         err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
211                            sizeof(*oxfw), &card);
212         if (err < 0)
213                 return err;
214
215         card->private_free = oxfw_card_free;
216         oxfw = card->private_data;
217         oxfw->card = card;
218         mutex_init(&oxfw->mutex);
219         oxfw->unit = fw_unit_get(unit);
220         oxfw->entry = entry;
221         spin_lock_init(&oxfw->lock);
222         init_waitqueue_head(&oxfw->hwdep_wait);
223
224         err = snd_oxfw_stream_discover(oxfw);
225         if (err < 0)
226                 goto error;
227
228         err = name_card(oxfw);
229         if (err < 0)
230                 goto error;
231
232         err = detect_quirks(oxfw);
233         if (err < 0)
234                 goto error;
235
236         err = snd_oxfw_create_pcm(oxfw);
237         if (err < 0)
238                 goto error;
239
240         snd_oxfw_proc_init(oxfw);
241
242         err = snd_oxfw_create_midi(oxfw);
243         if (err < 0)
244                 goto error;
245
246         err = snd_oxfw_create_hwdep(oxfw);
247         if (err < 0)
248                 goto error;
249
250         err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream);
251         if (err < 0)
252                 goto error;
253         if (oxfw->has_output) {
254                 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
255                 if (err < 0)
256                         goto error;
257         }
258
259         err = snd_card_register(card);
260         if (err < 0) {
261                 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
262                 if (oxfw->has_output)
263                         snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
264                 goto error;
265         }
266         dev_set_drvdata(&unit->device, oxfw);
267
268         return 0;
269 error:
270         snd_card_free(card);
271         return err;
272 }
273
274 static void oxfw_bus_reset(struct fw_unit *unit)
275 {
276         struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
277
278         fcp_bus_reset(oxfw->unit);
279
280         mutex_lock(&oxfw->mutex);
281
282         snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
283         if (oxfw->has_output)
284                 snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
285
286         mutex_unlock(&oxfw->mutex);
287
288         if (oxfw->entry->vendor_id == OUI_STANTON)
289                 snd_oxfw_scs1x_update(oxfw);
290 }
291
292 static void oxfw_remove(struct fw_unit *unit)
293 {
294         struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
295
296         /* No need to wait for releasing card object in this context. */
297         snd_card_free_when_closed(oxfw->card);
298 }
299
300 static const struct compat_info griffin_firewave = {
301         .driver_name = "FireWave",
302         .vendor_name = "Griffin",
303         .model_name = "FireWave",
304 };
305
306 static const struct compat_info lacie_speakers = {
307         .driver_name = "FWSpeakers",
308         .vendor_name = "LaCie",
309         .model_name = "FireWire Speakers",
310 };
311
312 static const struct ieee1394_device_id oxfw_id_table[] = {
313         {
314                 .match_flags  = IEEE1394_MATCH_VENDOR_ID |
315                                 IEEE1394_MATCH_MODEL_ID |
316                                 IEEE1394_MATCH_SPECIFIER_ID |
317                                 IEEE1394_MATCH_VERSION,
318                 .vendor_id    = VENDOR_GRIFFIN,
319                 .model_id     = 0x00f970,
320                 .specifier_id = SPECIFIER_1394TA,
321                 .version      = VERSION_AVC,
322                 .driver_data  = (kernel_ulong_t)&griffin_firewave,
323         },
324         {
325                 .match_flags  = IEEE1394_MATCH_VENDOR_ID |
326                                 IEEE1394_MATCH_MODEL_ID |
327                                 IEEE1394_MATCH_SPECIFIER_ID |
328                                 IEEE1394_MATCH_VERSION,
329                 .vendor_id    = VENDOR_LACIE,
330                 .model_id     = 0x00f970,
331                 .specifier_id = SPECIFIER_1394TA,
332                 .version      = VERSION_AVC,
333                 .driver_data  = (kernel_ulong_t)&lacie_speakers,
334         },
335         /* Behringer,F-Control Audio 202 */
336         {
337                 .match_flags    = IEEE1394_MATCH_VENDOR_ID |
338                                   IEEE1394_MATCH_MODEL_ID,
339                 .vendor_id      = VENDOR_BEHRINGER,
340                 .model_id       = 0x00fc22,
341         },
342         /*
343          * Any Mackie(Loud) models (name string/model id):
344          *  Onyx-i series (former models):      0x081216
345          *  Mackie Onyx Satellite:              0x00200f
346          *  Tapco LINK.firewire 4x6:            0x000460
347          *  d.2 pro:                            Unknown
348          *  d.4 pro:                            Unknown
349          *  U.420:                              Unknown
350          *  U.420d:                             Unknown
351          */
352         {
353                 .match_flags    = IEEE1394_MATCH_VENDOR_ID |
354                                   IEEE1394_MATCH_SPECIFIER_ID |
355                                   IEEE1394_MATCH_VERSION,
356                 .vendor_id      = VENDOR_LOUD,
357                 .specifier_id   = SPECIFIER_1394TA,
358                 .version        = VERSION_AVC,
359         },
360         /* TASCAM, FireOne */
361         {
362                 .match_flags    = IEEE1394_MATCH_VENDOR_ID |
363                                   IEEE1394_MATCH_MODEL_ID,
364                 .vendor_id      = VENDOR_TASCAM,
365                 .model_id       = 0x800007,
366         },
367         /* Stanton, Stanton Controllers & Systems 1 Mixer (SCS.1m) */
368         {
369                 .match_flags    = IEEE1394_MATCH_VENDOR_ID |
370                                   IEEE1394_MATCH_MODEL_ID,
371                 .vendor_id      = OUI_STANTON,
372                 .model_id       = 0x001000,
373         },
374         /* Stanton, Stanton Controllers & Systems 1 Deck (SCS.1d) */
375         {
376                 .match_flags    = IEEE1394_MATCH_VENDOR_ID |
377                                   IEEE1394_MATCH_MODEL_ID,
378                 .vendor_id      = OUI_STANTON,
379                 .model_id       = 0x002000,
380         },
381         { }
382 };
383 MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
384
385 static struct fw_driver oxfw_driver = {
386         .driver   = {
387                 .owner  = THIS_MODULE,
388                 .name   = KBUILD_MODNAME,
389                 .bus    = &fw_bus_type,
390         },
391         .probe    = oxfw_probe,
392         .update   = oxfw_bus_reset,
393         .remove   = oxfw_remove,
394         .id_table = oxfw_id_table,
395 };
396
397 static int __init snd_oxfw_init(void)
398 {
399         return driver_register(&oxfw_driver.driver);
400 }
401
402 static void __exit snd_oxfw_exit(void)
403 {
404         driver_unregister(&oxfw_driver.driver);
405 }
406
407 module_init(snd_oxfw_init);
408 module_exit(snd_oxfw_exit);
This page took 0.062503 seconds and 4 git commands to generate.