blob: 16ee6ea033e45f82c9d789e6c1c47687ad308ad5 [file] [log] [blame]
Clemens Ladisch31ef9132011-03-15 07:53:21 +01001/*
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +09002 * oxfw.c - a part of driver for OXFW970/971 based devices
Clemens Ladisch31ef9132011-03-15 07:53:21 +01003 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * Licensed under the terms of the GNU General Public License, version 2.
6 */
7
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +09008#include "oxfw.h"
Clemens Ladisch31ef9132011-03-15 07:53:21 +01009
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
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090017#define VENDOR_LOUD 0x000ff2
Clemens Ladisch31ef9132011-03-15 07:53:21 +010018#define VENDOR_GRIFFIN 0x001292
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090019#define VENDOR_BEHRINGER 0x001564
Clemens Ladisch31ef9132011-03-15 07:53:21 +010020#define VENDOR_LACIE 0x00d04b
Takashi Sakamoto759a2f42015-10-18 17:09:40 +090021#define VENDOR_TASCAM 0x00022e
Clemens Ladisch31ef9132011-03-15 07:53:21 +010022
Takashi Sakamoto13f3a462015-09-20 21:18:55 +090023#define MODEL_SATELLITE 0x00200f
24
Clemens Ladisch31ef9132011-03-15 07:53:21 +010025#define SPECIFIER_1394TA 0x00a02d
26#define VERSION_AVC 0x010001
27
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +090028MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
Clemens Ladisch31ef9132011-03-15 07:53:21 +010029MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
30MODULE_LICENSE("GPL v2");
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +090031MODULE_ALIAS("snd-firewire-speakers");
Clemens Ladisch31ef9132011-03-15 07:53:21 +010032
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090033static 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)
Dan Carpenter0d3aba32014-12-12 22:28:10 +030049 return false;
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090050
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
Takashi Sakamotofec7b752014-12-09 00:10:40 +090059static int name_card(struct snd_oxfw *oxfw)
Clemens Ladisch31ef9132011-03-15 07:53:21 +010060{
Takashi Sakamotofec7b752014-12-09 00:10:40 +090061 struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
Takashi Sakamoto27e66632015-12-15 23:56:20 +090062 const struct device_info *info;
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090063 char vendor[24];
64 char model[32];
Takashi Sakamotofec7b752014-12-09 00:10:40 +090065 const char *d, *v, *m;
66 u32 firmware;
Clemens Ladisch31ef9132011-03-15 07:53:21 +010067 int err;
68
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090069 /* 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
Takashi Sakamotofec7b752014-12-09 00:10:40 +090081 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
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090087 /* to apply card definitions */
Takashi Sakamoto27e66632015-12-15 23:56:20 +090088 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;
Takashi Sakamotoec4dba52014-12-09 00:10:45 +090094 } else {
95 d = "OXFW";
96 v = vendor;
97 m = model;
98 }
Takashi Sakamotofec7b752014-12-09 00:10:40 +090099
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);
109end:
110 return err;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100111}
112
Takashi Sakamoto12ed7192015-02-21 23:54:57 +0900113/*
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 */
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900119static void oxfw_card_free(struct snd_card *card)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100120{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900121 struct snd_oxfw *oxfw = card->private_data;
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900122 unsigned int i;
123
Takashi Sakamotodec84312015-02-21 23:55:00 +0900124 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
Takashi Sakamoto12ed7192015-02-21 23:54:57 +0900128 fw_unit_put(oxfw->unit);
129
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900130 for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
131 kfree(oxfw->tx_stream_formats[i]);
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900132 kfree(oxfw->rx_stream_formats[i]);
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900133 }
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100134
Takashi Sakamotoc582cc62015-12-16 20:37:54 +0900135 kfree(oxfw->spec);
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900136 mutex_destroy(&oxfw->mutex);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100137}
138
Takashi Sakamoto5ce8cc42015-12-15 23:56:21 +0900139static int detect_quirks(struct snd_oxfw *oxfw)
Takashi Sakamoto13f3a462015-09-20 21:18:55 +0900140{
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
Takashi Sakamoto27e66632015-12-15 23:56:20 +0900146 /*
Takashi Sakamoto5ce8cc42015-12-15 23:56:21 +0900147 * Add ALSA control elements for two models to keep compatibility to
148 * old firewire-speaker module.
149 */
Takashi Sakamoto3e2f4572015-12-16 20:37:56 +0900150 if (oxfw->entry->vendor_id == VENDOR_GRIFFIN)
151 return snd_oxfw_add_spkr(oxfw, false);
152 if (oxfw->entry->vendor_id == VENDOR_LACIE)
153 return snd_oxfw_add_spkr(oxfw, true);
Takashi Sakamoto5ce8cc42015-12-15 23:56:21 +0900154
155 /*
Takashi Sakamoto27e66632015-12-15 23:56:20 +0900156 * TASCAM FireOne has physical control and requires a pair of additional
157 * MIDI ports.
158 */
159 if (oxfw->entry->vendor_id == VENDOR_TASCAM) {
160 oxfw->midi_input_ports++;
161 oxfw->midi_output_ports++;
Takashi Sakamoto5ce8cc42015-12-15 23:56:21 +0900162 return 0;
Takashi Sakamoto27e66632015-12-15 23:56:20 +0900163 }
164
Takashi Sakamoto13f3a462015-09-20 21:18:55 +0900165 /* Seek from Root Directory of Config ROM. */
166 vendor = model = 0;
167 fw_csr_iterator_init(&it, fw_dev->config_rom + 5);
168 while (fw_csr_iterator_next(&it, &key, &val)) {
169 if (key == CSR_VENDOR)
170 vendor = val;
171 else if (key == CSR_MODEL)
172 model = val;
173 }
174
175 /*
176 * Mackie Onyx Satellite with base station has a quirk to report a wrong
177 * value in 'dbs' field of CIP header against its format information.
178 */
179 if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE)
180 oxfw->wrong_dbs = true;
Takashi Sakamoto5ce8cc42015-12-15 23:56:21 +0900181
182 return 0;
Takashi Sakamoto13f3a462015-09-20 21:18:55 +0900183}
184
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900185static int oxfw_probe(struct fw_unit *unit,
Takashi Sakamoto27e66632015-12-15 23:56:20 +0900186 const struct ieee1394_device_id *entry)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100187{
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100188 struct snd_card *card;
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900189 struct snd_oxfw *oxfw;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100190 int err;
191
Takashi Sakamoto27e66632015-12-15 23:56:20 +0900192 if (entry->vendor_id == VENDOR_LOUD && !detect_loud_models(unit))
Takashi Sakamotoec4dba52014-12-09 00:10:45 +0900193 return -ENODEV;
194
Takashi Iwai06b45f02014-01-29 14:23:55 +0100195 err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900196 sizeof(*oxfw), &card);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100197 if (err < 0)
198 return err;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100199
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900200 card->private_free = oxfw_card_free;
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900201 oxfw = card->private_data;
202 oxfw->card = card;
203 mutex_init(&oxfw->mutex);
Takashi Sakamoto12ed7192015-02-21 23:54:57 +0900204 oxfw->unit = fw_unit_get(unit);
Takashi Sakamoto27e66632015-12-15 23:56:20 +0900205 oxfw->entry = entry;
Takashi Sakamoto05588d32014-12-09 00:10:48 +0900206 spin_lock_init(&oxfw->lock);
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900207 init_waitqueue_head(&oxfw->hwdep_wait);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100208
Takashi Sakamoto5cd1d3f2014-12-09 00:10:42 +0900209 err = snd_oxfw_stream_discover(oxfw);
210 if (err < 0)
211 goto error;
212
Takashi Sakamoto5ce8cc42015-12-15 23:56:21 +0900213 err = detect_quirks(oxfw);
214 if (err < 0)
215 goto error;
Takashi Sakamoto13f3a462015-09-20 21:18:55 +0900216
Takashi Sakamotofec7b752014-12-09 00:10:40 +0900217 err = name_card(oxfw);
218 if (err < 0)
219 goto error;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100220
Takashi Sakamoto3713d932014-11-29 00:59:28 +0900221 err = snd_oxfw_create_pcm(oxfw);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100222 if (err < 0)
223 goto error;
224
Takashi Sakamoto3c961012014-12-09 00:10:43 +0900225 snd_oxfw_proc_init(oxfw);
226
Takashi Sakamoto05588d32014-12-09 00:10:48 +0900227 err = snd_oxfw_create_midi(oxfw);
228 if (err < 0)
229 goto error;
230
Takashi Sakamoto8985f4a2014-12-09 00:10:49 +0900231 err = snd_oxfw_create_hwdep(oxfw);
232 if (err < 0)
233 goto error;
234
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900235 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100236 if (err < 0)
237 goto error;
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900238 if (oxfw->has_output) {
239 err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
240 if (err < 0)
241 goto error;
242 }
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100243
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900244 err = snd_card_register(card);
245 if (err < 0) {
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900246 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
247 if (oxfw->has_output)
248 snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900249 goto error;
250 }
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900251 dev_set_drvdata(&unit->device, oxfw);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100252
253 return 0;
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100254error:
255 snd_card_free(card);
256 return err;
257}
258
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900259static void oxfw_bus_reset(struct fw_unit *unit)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100260{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900261 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100262
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900263 fcp_bus_reset(oxfw->unit);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100264
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900265 mutex_lock(&oxfw->mutex);
Takashi Sakamotob0ac0002014-12-09 00:10:46 +0900266
267 snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
268 if (oxfw->has_output)
269 snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
270
Takashi Sakamotoe2786ca2014-11-29 00:59:27 +0900271 mutex_unlock(&oxfw->mutex);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100272}
273
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900274static void oxfw_remove(struct fw_unit *unit)
Stefan Richter94a87152013-06-09 18:15:00 +0200275{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900276 struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
Stefan Richter94a87152013-06-09 18:15:00 +0200277
Takashi Sakamoto12ed7192015-02-21 23:54:57 +0900278 /* No need to wait for releasing card object in this context. */
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900279 snd_card_free_when_closed(oxfw->card);
Stefan Richter94a87152013-06-09 18:15:00 +0200280}
281
282static const struct device_info griffin_firewave = {
283 .driver_name = "FireWave",
Takashi Sakamotofec7b752014-12-09 00:10:40 +0900284 .vendor_name = "Griffin",
285 .model_name = "FireWave",
Stefan Richter94a87152013-06-09 18:15:00 +0200286};
287
288static const struct device_info lacie_speakers = {
289 .driver_name = "FWSpeakers",
Takashi Sakamotofec7b752014-12-09 00:10:40 +0900290 .vendor_name = "LaCie",
291 .model_name = "FireWire Speakers",
Stefan Richter94a87152013-06-09 18:15:00 +0200292};
293
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900294static const struct ieee1394_device_id oxfw_id_table[] = {
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100295 {
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,
Stefan Richter94a87152013-06-09 18:15:00 +0200304 .driver_data = (kernel_ulong_t)&griffin_firewave,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100305 },
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,
Stefan Richter94a87152013-06-09 18:15:00 +0200315 .driver_data = (kernel_ulong_t)&lacie_speakers,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100316 },
Takashi Sakamotoec4dba52014-12-09 00:10:45 +0900317 /* 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 },
Takashi Sakamoto759a2f42015-10-18 17:09:40 +0900342 /* 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 },
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100349 { }
350};
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900351MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100352
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900353static struct fw_driver oxfw_driver = {
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100354 .driver = {
355 .owner = THIS_MODULE,
356 .name = KBUILD_MODNAME,
357 .bus = &fw_bus_type,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100358 },
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900359 .probe = oxfw_probe,
360 .update = oxfw_bus_reset,
361 .remove = oxfw_remove,
362 .id_table = oxfw_id_table,
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100363};
364
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900365static int __init snd_oxfw_init(void)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100366{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900367 return driver_register(&oxfw_driver.driver);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100368}
369
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900370static void __exit snd_oxfw_exit(void)
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100371{
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900372 driver_unregister(&oxfw_driver.driver);
Clemens Ladisch31ef9132011-03-15 07:53:21 +0100373}
374
Takashi Sakamoto8832c5a2014-11-29 00:59:25 +0900375module_init(snd_oxfw_init);
376module_exit(snd_oxfw_exit);