ALSA: oxfw: reuse driver entry to detect quirks
[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 mutex_destroy(&oxfw->mutex);
136 }
137
138 static void detect_quirks(struct snd_oxfw *oxfw)
139 {
140 struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
141 struct fw_csr_iterator it;
142 int key, val;
143 int vendor, model;
144
145 /*
146 * TASCAM FireOne has physical control and requires a pair of additional
147 * MIDI ports.
148 */
149 if (oxfw->entry->vendor_id == VENDOR_TASCAM) {
150 oxfw->midi_input_ports++;
151 oxfw->midi_output_ports++;
152 return;
153 }
154
155 /* Seek from Root Directory of Config ROM. */
156 vendor = model = 0;
157 fw_csr_iterator_init(&it, fw_dev->config_rom + 5);
158 while (fw_csr_iterator_next(&it, &key, &val)) {
159 if (key == CSR_VENDOR)
160 vendor = val;
161 else if (key == CSR_MODEL)
162 model = val;
163 }
164
165 /*
166 * Mackie Onyx Satellite with base station has a quirk to report a wrong
167 * value in 'dbs' field of CIP header against its format information.
168 */
169 if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE)
170 oxfw->wrong_dbs = true;
171 }
172
173 static int oxfw_probe(struct fw_unit *unit,
174 const struct ieee1394_device_id *entry)
175 {
176 struct snd_card *card;
177 struct snd_oxfw *oxfw;
178 int err;
179
180 if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit))
181 return -ENODEV;
182
183 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
184 sizeof(*oxfw), &card);
185 if (err < 0)
186 return err;
187
188 card->private_free = oxfw_card_free;
189 oxfw = card->private_data;
190 oxfw->card = card;
191 mutex_init(&oxfw->mutex);
192 oxfw->unit = fw_unit_get(unit);
193 oxfw->entry = entry;
194 spin_lock_init(&oxfw->lock);
195 init_waitqueue_head(&oxfw->hwdep_wait);
196
197 err = snd_oxfw_stream_discover(oxfw);
198 if (err < 0)
199 goto error;
200
201 detect_quirks(oxfw);
202
203 err = name_card(oxfw);
204 if (err < 0)
205 goto error;
206
207 err = snd_oxfw_create_pcm(oxfw);
208 if (err < 0)
209 goto error;
210
211 if (oxfw->device_info) {
212 oxfw->device_info =
213 (const struct device_info *)entry->driver_data;
214 err = snd_oxfw_add_spkr(oxfw);
215 if (err < 0)
216 goto error;
217 }
218
219 snd_oxfw_proc_init(oxfw);
220
221 err = snd_oxfw_create_midi(oxfw);
222 if (err < 0)
223 goto error;
224
225 err = snd_oxfw_create_hwdep(oxfw);
226 if (err < 0)
227 goto error;
228
229 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream);
230 if (err < 0)
231 goto error;
232 if (oxfw->has_output) {
233 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
234 if (err < 0)
235 goto error;
236 }
237
238 err = snd_card_register(card);
239 if (err < 0) {
240 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
241 if (oxfw->has_output)
242 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
243 goto error;
244 }
245 dev_set_drvdata(&unit->device, oxfw);
246
247 return 0;
248 error:
249 snd_card_free(card);
250 return err;
251 }
252
253 static void oxfw_bus_reset(struct fw_unit *unit)
254 {
255 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
256
257 fcp_bus_reset(oxfw->unit);
258
259 mutex_lock(&oxfw->mutex);
260
261 snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
262 if (oxfw->has_output)
263 snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
264
265 mutex_unlock(&oxfw->mutex);
266 }
267
268 static void oxfw_remove(struct fw_unit *unit)
269 {
270 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
271
272 /* No need to wait for releasing card object in this context. */
273 snd_card_free_when_closed(oxfw->card);
274 }
275
276 static const struct device_info griffin_firewave = {
277 .driver_name = "FireWave",
278 .vendor_name = "Griffin",
279 .model_name = "FireWave",
280 .mixer_channels = 6,
281 .mute_fb_id = 0x01,
282 .volume_fb_id = 0x02,
283 };
284
285 static const struct device_info lacie_speakers = {
286 .driver_name = "FWSpeakers",
287 .vendor_name = "LaCie",
288 .model_name = "FireWire Speakers",
289 .mixer_channels = 1,
290 .mute_fb_id = 0x01,
291 .volume_fb_id = 0x01,
292 };
293
294 static const struct ieee1394_device_id oxfw_id_table[] = {
295 {
296 .match_flags = IEEE1394_MATCH_VENDOR_ID |
297 IEEE1394_MATCH_MODEL_ID |
298 IEEE1394_MATCH_SPECIFIER_ID |
299 IEEE1394_MATCH_VERSION,
300 .vendor_id = VENDOR_GRIFFIN,
301 .model_id = 0x00f970,
302 .specifier_id = SPECIFIER_1394TA,
303 .version = VERSION_AVC,
304 .driver_data = (kernel_ulong_t)&griffin_firewave,
305 },
306 {
307 .match_flags = IEEE1394_MATCH_VENDOR_ID |
308 IEEE1394_MATCH_MODEL_ID |
309 IEEE1394_MATCH_SPECIFIER_ID |
310 IEEE1394_MATCH_VERSION,
311 .vendor_id = VENDOR_LACIE,
312 .model_id = 0x00f970,
313 .specifier_id = SPECIFIER_1394TA,
314 .version = VERSION_AVC,
315 .driver_data = (kernel_ulong_t)&lacie_speakers,
316 },
317 /* Behringer,F-Control Audio 202 */
318 {
319 .match_flags = IEEE1394_MATCH_VENDOR_ID |
320 IEEE1394_MATCH_MODEL_ID,
321 .vendor_id = VENDOR_BEHRINGER,
322 .model_id = 0x00fc22,
323 },
324 /*
325 * Any Mackie(Loud) models (name string/model id):
326 * Onyx-i series (former models): 0x081216
327 * Mackie Onyx Satellite: 0x00200f
328 * Tapco LINK.firewire 4x6: 0x000460
329 * d.2 pro: Unknown
330 * d.4 pro: Unknown
331 * U.420: Unknown
332 * U.420d: Unknown
333 */
334 {
335 .match_flags = IEEE1394_MATCH_VENDOR_ID |
336 IEEE1394_MATCH_SPECIFIER_ID |
337 IEEE1394_MATCH_VERSION,
338 .vendor_id = VENDOR_LOUD,
339 .specifier_id = SPECIFIER_1394TA,
340 .version = VERSION_AVC,
341 },
342 /* TASCAM, FireOne */
343 {
344 .match_flags = IEEE1394_MATCH_VENDOR_ID |
345 IEEE1394_MATCH_MODEL_ID,
346 .vendor_id = VENDOR_TASCAM,
347 .model_id = 0x800007,
348 },
349 { }
350 };
351 MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
352
353 static struct fw_driver oxfw_driver = {
354 .driver = {
355 .owner = THIS_MODULE,
356 .name = KBUILD_MODNAME,
357 .bus = &fw_bus_type,
358 },
359 .probe = oxfw_probe,
360 .update = oxfw_bus_reset,
361 .remove = oxfw_remove,
362 .id_table = oxfw_id_table,
363 };
364
365 static int __init snd_oxfw_init(void)
366 {
367 return driver_register(&oxfw_driver.driver);
368 }
369
370 static void __exit snd_oxfw_exit(void)
371 {
372 driver_unregister(&oxfw_driver.driver);
373 }
374
375 module_init(snd_oxfw_init);
376 module_exit(snd_oxfw_exit);
This page took 0.052519 seconds and 5 git commands to generate.