oxfw.c 11 KB

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