oxfw.c 11 KB

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