oxfw.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 MODEL_SATELLITE 0x00200f
  19. #define SPECIFIER_1394TA 0x00a02d
  20. #define VERSION_AVC 0x010001
  21. MODULE_DESCRIPTION("Oxford Semiconductor FW970/971 driver");
  22. MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
  23. MODULE_LICENSE("GPL v2");
  24. MODULE_ALIAS("snd-firewire-speakers");
  25. static bool detect_loud_models(struct fw_unit *unit)
  26. {
  27. const char *const models[] = {
  28. "Onyxi",
  29. "Onyx-i",
  30. "d.Pro",
  31. "Mackie Onyx Satellite",
  32. "Tapco LINK.firewire 4x6",
  33. "U.420"};
  34. char model[32];
  35. unsigned int i;
  36. int err;
  37. err = fw_csr_string(unit->directory, CSR_MODEL,
  38. model, sizeof(model));
  39. if (err < 0)
  40. return false;
  41. for (i = 0; i < ARRAY_SIZE(models); i++) {
  42. if (strcmp(models[i], model) == 0)
  43. break;
  44. }
  45. return (i < ARRAY_SIZE(models));
  46. }
  47. static int name_card(struct snd_oxfw *oxfw)
  48. {
  49. struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
  50. char vendor[24];
  51. char model[32];
  52. const char *d, *v, *m;
  53. u32 firmware;
  54. int err;
  55. /* get vendor name from root directory */
  56. err = fw_csr_string(fw_dev->config_rom + 5, CSR_VENDOR,
  57. vendor, sizeof(vendor));
  58. if (err < 0)
  59. goto end;
  60. /* get model name from unit directory */
  61. err = fw_csr_string(oxfw->unit->directory, CSR_MODEL,
  62. model, sizeof(model));
  63. if (err < 0)
  64. goto end;
  65. err = snd_fw_transaction(oxfw->unit, TCODE_READ_QUADLET_REQUEST,
  66. OXFORD_FIRMWARE_ID_ADDRESS, &firmware, 4, 0);
  67. if (err < 0)
  68. goto end;
  69. be32_to_cpus(&firmware);
  70. /* to apply card definitions */
  71. if (oxfw->device_info) {
  72. d = oxfw->device_info->driver_name;
  73. v = oxfw->device_info->vendor_name;
  74. m = oxfw->device_info->model_name;
  75. } else {
  76. d = "OXFW";
  77. v = vendor;
  78. m = model;
  79. }
  80. strcpy(oxfw->card->driver, d);
  81. strcpy(oxfw->card->mixername, m);
  82. strcpy(oxfw->card->shortname, m);
  83. snprintf(oxfw->card->longname, sizeof(oxfw->card->longname),
  84. "%s %s (OXFW%x %04x), GUID %08x%08x at %s, S%d",
  85. v, m, firmware >> 20, firmware & 0xffff,
  86. fw_dev->config_rom[3], fw_dev->config_rom[4],
  87. dev_name(&oxfw->unit->device), 100 << fw_dev->max_speed);
  88. end:
  89. return err;
  90. }
  91. /*
  92. * This module releases the FireWire unit data after all ALSA character devices
  93. * are released by applications. This is for releasing stream data or finishing
  94. * transactions safely. Thus at returning from .remove(), this module still keep
  95. * references for the unit.
  96. */
  97. static void oxfw_card_free(struct snd_card *card)
  98. {
  99. struct snd_oxfw *oxfw = card->private_data;
  100. unsigned int i;
  101. snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
  102. if (oxfw->has_output)
  103. snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
  104. fw_unit_put(oxfw->unit);
  105. for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) {
  106. kfree(oxfw->tx_stream_formats[i]);
  107. kfree(oxfw->rx_stream_formats[i]);
  108. }
  109. mutex_destroy(&oxfw->mutex);
  110. }
  111. static void detect_quirks(struct snd_oxfw *oxfw)
  112. {
  113. struct fw_device *fw_dev = fw_parent_device(oxfw->unit);
  114. struct fw_csr_iterator it;
  115. int key, val;
  116. int vendor, model;
  117. /* Seek from Root Directory of Config ROM. */
  118. vendor = model = 0;
  119. fw_csr_iterator_init(&it, fw_dev->config_rom + 5);
  120. while (fw_csr_iterator_next(&it, &key, &val)) {
  121. if (key == CSR_VENDOR)
  122. vendor = val;
  123. else if (key == CSR_MODEL)
  124. model = val;
  125. }
  126. /*
  127. * Mackie Onyx Satellite with base station has a quirk to report a wrong
  128. * value in 'dbs' field of CIP header against its format information.
  129. */
  130. if (vendor == VENDOR_LOUD && model == MODEL_SATELLITE)
  131. oxfw->wrong_dbs = true;
  132. /*
  133. * TASCAM FireOne has physical control and requires a pair of additional
  134. * MIDI ports.
  135. */
  136. if (vendor == VENDOR_TASCAM) {
  137. oxfw->midi_input_ports++;
  138. oxfw->midi_output_ports++;
  139. }
  140. }
  141. static int oxfw_probe(struct fw_unit *unit,
  142. const struct ieee1394_device_id *id)
  143. {
  144. struct snd_card *card;
  145. struct snd_oxfw *oxfw;
  146. int err;
  147. if ((id->vendor_id == VENDOR_LOUD) && !detect_loud_models(unit))
  148. return -ENODEV;
  149. err = snd_card_new(&unit->device, -1, NULL, THIS_MODULE,
  150. sizeof(*oxfw), &card);
  151. if (err < 0)
  152. return err;
  153. card->private_free = oxfw_card_free;
  154. oxfw = card->private_data;
  155. oxfw->card = card;
  156. mutex_init(&oxfw->mutex);
  157. oxfw->unit = fw_unit_get(unit);
  158. oxfw->device_info = (const struct device_info *)id->driver_data;
  159. spin_lock_init(&oxfw->lock);
  160. init_waitqueue_head(&oxfw->hwdep_wait);
  161. err = snd_oxfw_stream_discover(oxfw);
  162. if (err < 0)
  163. goto error;
  164. detect_quirks(oxfw);
  165. err = name_card(oxfw);
  166. if (err < 0)
  167. goto error;
  168. err = snd_oxfw_create_pcm(oxfw);
  169. if (err < 0)
  170. goto error;
  171. if (oxfw->device_info) {
  172. err = snd_oxfw_create_mixer(oxfw);
  173. if (err < 0)
  174. goto error;
  175. }
  176. snd_oxfw_proc_init(oxfw);
  177. err = snd_oxfw_create_midi(oxfw);
  178. if (err < 0)
  179. goto error;
  180. err = snd_oxfw_create_hwdep(oxfw);
  181. if (err < 0)
  182. goto error;
  183. err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->rx_stream);
  184. if (err < 0)
  185. goto error;
  186. if (oxfw->has_output) {
  187. err = snd_oxfw_stream_init_simplex(oxfw, &oxfw->tx_stream);
  188. if (err < 0)
  189. goto error;
  190. }
  191. err = snd_card_register(card);
  192. if (err < 0) {
  193. snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->rx_stream);
  194. if (oxfw->has_output)
  195. snd_oxfw_stream_destroy_simplex(oxfw, &oxfw->tx_stream);
  196. goto error;
  197. }
  198. dev_set_drvdata(&unit->device, oxfw);
  199. return 0;
  200. error:
  201. snd_card_free(card);
  202. return err;
  203. }
  204. static void oxfw_bus_reset(struct fw_unit *unit)
  205. {
  206. struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
  207. fcp_bus_reset(oxfw->unit);
  208. mutex_lock(&oxfw->mutex);
  209. snd_oxfw_stream_update_simplex(oxfw, &oxfw->rx_stream);
  210. if (oxfw->has_output)
  211. snd_oxfw_stream_update_simplex(oxfw, &oxfw->tx_stream);
  212. mutex_unlock(&oxfw->mutex);
  213. }
  214. static void oxfw_remove(struct fw_unit *unit)
  215. {
  216. struct snd_oxfw *oxfw = dev_get_drvdata(&unit->device);
  217. /* No need to wait for releasing card object in this context. */
  218. snd_card_free_when_closed(oxfw->card);
  219. }
  220. static const struct device_info griffin_firewave = {
  221. .driver_name = "FireWave",
  222. .vendor_name = "Griffin",
  223. .model_name = "FireWave",
  224. .mixer_channels = 6,
  225. .mute_fb_id = 0x01,
  226. .volume_fb_id = 0x02,
  227. };
  228. static const struct device_info lacie_speakers = {
  229. .driver_name = "FWSpeakers",
  230. .vendor_name = "LaCie",
  231. .model_name = "FireWire Speakers",
  232. .mixer_channels = 1,
  233. .mute_fb_id = 0x01,
  234. .volume_fb_id = 0x01,
  235. };
  236. static const struct ieee1394_device_id oxfw_id_table[] = {
  237. {
  238. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  239. IEEE1394_MATCH_MODEL_ID |
  240. IEEE1394_MATCH_SPECIFIER_ID |
  241. IEEE1394_MATCH_VERSION,
  242. .vendor_id = VENDOR_GRIFFIN,
  243. .model_id = 0x00f970,
  244. .specifier_id = SPECIFIER_1394TA,
  245. .version = VERSION_AVC,
  246. .driver_data = (kernel_ulong_t)&griffin_firewave,
  247. },
  248. {
  249. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  250. IEEE1394_MATCH_MODEL_ID |
  251. IEEE1394_MATCH_SPECIFIER_ID |
  252. IEEE1394_MATCH_VERSION,
  253. .vendor_id = VENDOR_LACIE,
  254. .model_id = 0x00f970,
  255. .specifier_id = SPECIFIER_1394TA,
  256. .version = VERSION_AVC,
  257. .driver_data = (kernel_ulong_t)&lacie_speakers,
  258. },
  259. /* Behringer,F-Control Audio 202 */
  260. {
  261. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  262. IEEE1394_MATCH_MODEL_ID,
  263. .vendor_id = VENDOR_BEHRINGER,
  264. .model_id = 0x00fc22,
  265. },
  266. /*
  267. * Any Mackie(Loud) models (name string/model id):
  268. * Onyx-i series (former models): 0x081216
  269. * Mackie Onyx Satellite: 0x00200f
  270. * Tapco LINK.firewire 4x6: 0x000460
  271. * d.2 pro: Unknown
  272. * d.4 pro: Unknown
  273. * U.420: Unknown
  274. * U.420d: Unknown
  275. */
  276. {
  277. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  278. IEEE1394_MATCH_SPECIFIER_ID |
  279. IEEE1394_MATCH_VERSION,
  280. .vendor_id = VENDOR_LOUD,
  281. .specifier_id = SPECIFIER_1394TA,
  282. .version = VERSION_AVC,
  283. },
  284. /* TASCAM, FireOne */
  285. {
  286. .match_flags = IEEE1394_MATCH_VENDOR_ID |
  287. IEEE1394_MATCH_MODEL_ID,
  288. .vendor_id = VENDOR_TASCAM,
  289. .model_id = 0x800007,
  290. },
  291. { }
  292. };
  293. MODULE_DEVICE_TABLE(ieee1394, oxfw_id_table);
  294. static struct fw_driver oxfw_driver = {
  295. .driver = {
  296. .owner = THIS_MODULE,
  297. .name = KBUILD_MODNAME,
  298. .bus = &fw_bus_type,
  299. },
  300. .probe = oxfw_probe,
  301. .update = oxfw_bus_reset,
  302. .remove = oxfw_remove,
  303. .id_table = oxfw_id_table,
  304. };
  305. static int __init snd_oxfw_init(void)
  306. {
  307. return driver_register(&oxfw_driver.driver);
  308. }
  309. static void __exit snd_oxfw_exit(void)
  310. {
  311. driver_unregister(&oxfw_driver.driver);
  312. }
  313. module_init(snd_oxfw_init);
  314. module_exit(snd_oxfw_exit);