oxfw.c 7.6 KB

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