oxfw.c 10 KB

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