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