fireworks.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*
  2. * fireworks.c - a part of driver for Fireworks based devices
  3. *
  4. * Copyright (c) 2009-2010 Clemens Ladisch
  5. * Copyright (c) 2013-2014 Takashi Sakamoto
  6. *
  7. * Licensed under the terms of the GNU General Public License, version 2.
  8. */
  9. /*
  10. * Fireworks is a board module which Echo Audio produced. This module consists
  11. * of three chipsets:
  12. * - Communication chipset for IEEE1394 PHY/Link and IEC 61883-1/6
  13. * - DSP or/and FPGA for signal processing
  14. * - Flash Memory to store firmwares
  15. */
  16. #include "fireworks.h"
  17. MODULE_DESCRIPTION("Echo Fireworks driver");
  18. MODULE_AUTHOR("Takashi Sakamoto <o-takashi@sakamocchi.jp>");
  19. MODULE_LICENSE("GPL v2");
  20. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  21. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  22. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  23. unsigned int snd_efw_resp_buf_size = 1024;
  24. bool snd_efw_resp_buf_debug = false;
  25. module_param_array(index, int, NULL, 0444);
  26. MODULE_PARM_DESC(index, "card index");
  27. module_param_array(id, charp, NULL, 0444);
  28. MODULE_PARM_DESC(id, "ID string");
  29. module_param_array(enable, bool, NULL, 0444);
  30. MODULE_PARM_DESC(enable, "enable Fireworks sound card");
  31. module_param_named(resp_buf_size, snd_efw_resp_buf_size, uint, 0444);
  32. MODULE_PARM_DESC(resp_buf_size,
  33. "response buffer size (max 4096, default 1024)");
  34. module_param_named(resp_buf_debug, snd_efw_resp_buf_debug, bool, 0444);
  35. MODULE_PARM_DESC(resp_buf_debug, "store all responses to buffer");
  36. static DEFINE_MUTEX(devices_mutex);
  37. static DECLARE_BITMAP(devices_used, SNDRV_CARDS);
  38. #define VENDOR_LOUD 0x000ff2
  39. #define MODEL_MACKIE_400F 0x00400f
  40. #define MODEL_MACKIE_1200F 0x01200f
  41. #define VENDOR_ECHO 0x001486
  42. #define MODEL_ECHO_AUDIOFIRE_12 0x00af12
  43. #define MODEL_ECHO_AUDIOFIRE_12HD 0x0af12d
  44. #define MODEL_ECHO_AUDIOFIRE_12_APPLE 0x0af12a
  45. /* This is applied for AudioFire8 (until 2009 July) */
  46. #define MODEL_ECHO_AUDIOFIRE_8 0x000af8
  47. #define MODEL_ECHO_AUDIOFIRE_2 0x000af2
  48. #define MODEL_ECHO_AUDIOFIRE_4 0x000af4
  49. /* AudioFire9 is applied for AudioFire8(since 2009 July) and AudioFirePre8 */
  50. #define MODEL_ECHO_AUDIOFIRE_9 0x000af9
  51. /* unknown as product */
  52. #define MODEL_ECHO_FIREWORKS_8 0x0000f8
  53. #define MODEL_ECHO_FIREWORKS_HDMI 0x00afd1
  54. #define VENDOR_GIBSON 0x00075b
  55. /* for Robot Interface Pack of Dark Fire, Dusk Tiger, Les Paul Standard 2010 */
  56. #define MODEL_GIBSON_RIP 0x00afb2
  57. /* unknown as product */
  58. #define MODEL_GIBSON_GOLDTOP 0x00afb9
  59. /* part of hardware capability flags */
  60. #define FLAG_RESP_ADDR_CHANGABLE 0
  61. static int
  62. get_hardware_info(struct snd_efw *efw)
  63. {
  64. struct fw_device *fw_dev = fw_parent_device(efw->unit);
  65. struct snd_efw_hwinfo *hwinfo;
  66. char version[12] = {0};
  67. int err;
  68. hwinfo = kzalloc(sizeof(struct snd_efw_hwinfo), GFP_KERNEL);
  69. if (hwinfo == NULL)
  70. return -ENOMEM;
  71. err = snd_efw_command_get_hwinfo(efw, hwinfo);
  72. if (err < 0)
  73. goto end;
  74. /* firmware version for communication chipset */
  75. snprintf(version, sizeof(version), "%u.%u",
  76. (hwinfo->arm_version >> 24) & 0xff,
  77. (hwinfo->arm_version >> 16) & 0xff);
  78. efw->firmware_version = hwinfo->arm_version;
  79. strcpy(efw->card->driver, "Fireworks");
  80. strcpy(efw->card->shortname, hwinfo->model_name);
  81. strcpy(efw->card->mixername, hwinfo->model_name);
  82. snprintf(efw->card->longname, sizeof(efw->card->longname),
  83. "%s %s v%s, GUID %08x%08x at %s, S%d",
  84. hwinfo->vendor_name, hwinfo->model_name, version,
  85. hwinfo->guid_hi, hwinfo->guid_lo,
  86. dev_name(&efw->unit->device), 100 << fw_dev->max_speed);
  87. if (hwinfo->flags & BIT(FLAG_RESP_ADDR_CHANGABLE))
  88. efw->resp_addr_changable = true;
  89. efw->supported_sampling_rate = 0;
  90. if ((hwinfo->min_sample_rate <= 22050)
  91. && (22050 <= hwinfo->max_sample_rate))
  92. efw->supported_sampling_rate |= SNDRV_PCM_RATE_22050;
  93. if ((hwinfo->min_sample_rate <= 32000)
  94. && (32000 <= hwinfo->max_sample_rate))
  95. efw->supported_sampling_rate |= SNDRV_PCM_RATE_32000;
  96. if ((hwinfo->min_sample_rate <= 44100)
  97. && (44100 <= hwinfo->max_sample_rate))
  98. efw->supported_sampling_rate |= SNDRV_PCM_RATE_44100;
  99. if ((hwinfo->min_sample_rate <= 48000)
  100. && (48000 <= hwinfo->max_sample_rate))
  101. efw->supported_sampling_rate |= SNDRV_PCM_RATE_48000;
  102. if ((hwinfo->min_sample_rate <= 88200)
  103. && (88200 <= hwinfo->max_sample_rate))
  104. efw->supported_sampling_rate |= SNDRV_PCM_RATE_88200;
  105. if ((hwinfo->min_sample_rate <= 96000)
  106. && (96000 <= hwinfo->max_sample_rate))
  107. efw->supported_sampling_rate |= SNDRV_PCM_RATE_96000;
  108. if ((hwinfo->min_sample_rate <= 176400)
  109. && (176400 <= hwinfo->max_sample_rate))
  110. efw->supported_sampling_rate |= SNDRV_PCM_RATE_176400;
  111. if ((hwinfo->min_sample_rate <= 192000)
  112. && (192000 <= hwinfo->max_sample_rate))
  113. efw->supported_sampling_rate |= SNDRV_PCM_RATE_192000;
  114. /* the number of MIDI ports, not of MIDI conformant data channels */
  115. if (hwinfo->midi_out_ports > SND_EFW_MAX_MIDI_OUT_PORTS ||
  116. hwinfo->midi_in_ports > SND_EFW_MAX_MIDI_IN_PORTS) {
  117. err = -EIO;
  118. goto end;
  119. }
  120. efw->midi_out_ports = hwinfo->midi_out_ports;
  121. efw->midi_in_ports = hwinfo->midi_in_ports;
  122. if (hwinfo->amdtp_tx_pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM ||
  123. hwinfo->amdtp_tx_pcm_channels_2x > AMDTP_MAX_CHANNELS_FOR_PCM ||
  124. hwinfo->amdtp_tx_pcm_channels_4x > AMDTP_MAX_CHANNELS_FOR_PCM ||
  125. hwinfo->amdtp_rx_pcm_channels > AMDTP_MAX_CHANNELS_FOR_PCM ||
  126. hwinfo->amdtp_rx_pcm_channels_2x > AMDTP_MAX_CHANNELS_FOR_PCM ||
  127. hwinfo->amdtp_rx_pcm_channels_4x > AMDTP_MAX_CHANNELS_FOR_PCM) {
  128. err = -ENOSYS;
  129. goto end;
  130. }
  131. efw->pcm_capture_channels[0] = hwinfo->amdtp_tx_pcm_channels;
  132. efw->pcm_capture_channels[1] = hwinfo->amdtp_tx_pcm_channels_2x;
  133. efw->pcm_capture_channels[2] = hwinfo->amdtp_tx_pcm_channels_4x;
  134. efw->pcm_playback_channels[0] = hwinfo->amdtp_rx_pcm_channels;
  135. efw->pcm_playback_channels[1] = hwinfo->amdtp_rx_pcm_channels_2x;
  136. efw->pcm_playback_channels[2] = hwinfo->amdtp_rx_pcm_channels_4x;
  137. /* Hardware metering. */
  138. if (hwinfo->phys_in_grp_count > HWINFO_MAX_CAPS_GROUPS ||
  139. hwinfo->phys_out_grp_count > HWINFO_MAX_CAPS_GROUPS) {
  140. err = -EIO;
  141. goto end;
  142. }
  143. efw->phys_in = hwinfo->phys_in;
  144. efw->phys_out = hwinfo->phys_out;
  145. efw->phys_in_grp_count = hwinfo->phys_in_grp_count;
  146. efw->phys_out_grp_count = hwinfo->phys_out_grp_count;
  147. memcpy(&efw->phys_in_grps, hwinfo->phys_in_grps,
  148. sizeof(struct snd_efw_phys_grp) * hwinfo->phys_in_grp_count);
  149. memcpy(&efw->phys_out_grps, hwinfo->phys_out_grps,
  150. sizeof(struct snd_efw_phys_grp) * hwinfo->phys_out_grp_count);
  151. end:
  152. kfree(hwinfo);
  153. return err;
  154. }
  155. /*
  156. * This module releases the FireWire unit data after all ALSA character devices
  157. * are released by applications. This is for releasing stream data or finishing
  158. * transactions safely. Thus at returning from .remove(), this module still keep
  159. * references for the unit.
  160. */
  161. static void
  162. efw_card_free(struct snd_card *card)
  163. {
  164. struct snd_efw *efw = card->private_data;
  165. snd_efw_stream_destroy_duplex(efw);
  166. snd_efw_transaction_remove_instance(efw);
  167. fw_unit_put(efw->unit);
  168. kfree(efw->resp_buf);
  169. if (efw->card_index >= 0) {
  170. mutex_lock(&devices_mutex);
  171. clear_bit(efw->card_index, devices_used);
  172. mutex_unlock(&devices_mutex);
  173. }
  174. mutex_destroy(&efw->mutex);
  175. }
  176. static int
  177. efw_probe(struct fw_unit *unit,
  178. const struct ieee1394_device_id *entry)
  179. {
  180. struct snd_card *card;
  181. struct snd_efw *efw;
  182. int card_index, err;
  183. mutex_lock(&devices_mutex);
  184. /* check registered cards */
  185. for (card_index = 0; card_index < SNDRV_CARDS; ++card_index) {
  186. if (!test_bit(card_index, devices_used) && enable[card_index])
  187. break;
  188. }
  189. if (card_index >= SNDRV_CARDS) {
  190. err = -ENOENT;
  191. goto end;
  192. }
  193. err = snd_card_new(&unit->device, index[card_index], id[card_index],
  194. THIS_MODULE, sizeof(struct snd_efw), &card);
  195. if (err < 0)
  196. goto end;
  197. efw = card->private_data;
  198. efw->card_index = card_index;
  199. set_bit(card_index, devices_used);
  200. card->private_free = efw_card_free;
  201. efw->card = card;
  202. efw->unit = fw_unit_get(unit);
  203. mutex_init(&efw->mutex);
  204. spin_lock_init(&efw->lock);
  205. init_waitqueue_head(&efw->hwdep_wait);
  206. /* prepare response buffer */
  207. snd_efw_resp_buf_size = clamp(snd_efw_resp_buf_size,
  208. SND_EFW_RESPONSE_MAXIMUM_BYTES, 4096U);
  209. efw->resp_buf = kzalloc(snd_efw_resp_buf_size, GFP_KERNEL);
  210. if (efw->resp_buf == NULL) {
  211. err = -ENOMEM;
  212. goto error;
  213. }
  214. efw->pull_ptr = efw->push_ptr = efw->resp_buf;
  215. snd_efw_transaction_add_instance(efw);
  216. err = get_hardware_info(efw);
  217. if (err < 0)
  218. goto error;
  219. if (entry->model_id == MODEL_ECHO_AUDIOFIRE_9)
  220. efw->is_af9 = true;
  221. snd_efw_proc_init(efw);
  222. if (efw->midi_out_ports || efw->midi_in_ports) {
  223. err = snd_efw_create_midi_devices(efw);
  224. if (err < 0)
  225. goto error;
  226. }
  227. err = snd_efw_create_pcm_devices(efw);
  228. if (err < 0)
  229. goto error;
  230. err = snd_efw_create_hwdep_device(efw);
  231. if (err < 0)
  232. goto error;
  233. err = snd_efw_stream_init_duplex(efw);
  234. if (err < 0)
  235. goto error;
  236. err = snd_card_register(card);
  237. if (err < 0) {
  238. snd_efw_stream_destroy_duplex(efw);
  239. goto error;
  240. }
  241. dev_set_drvdata(&unit->device, efw);
  242. end:
  243. mutex_unlock(&devices_mutex);
  244. return err;
  245. error:
  246. snd_efw_transaction_remove_instance(efw);
  247. mutex_unlock(&devices_mutex);
  248. snd_card_free(card);
  249. return err;
  250. }
  251. static void efw_update(struct fw_unit *unit)
  252. {
  253. struct snd_efw *efw = dev_get_drvdata(&unit->device);
  254. snd_efw_transaction_bus_reset(efw->unit);
  255. snd_efw_stream_update_duplex(efw);
  256. }
  257. static void efw_remove(struct fw_unit *unit)
  258. {
  259. struct snd_efw *efw = dev_get_drvdata(&unit->device);
  260. /* No need to wait for releasing card object in this context. */
  261. snd_card_free_when_closed(efw->card);
  262. }
  263. static const struct ieee1394_device_id efw_id_table[] = {
  264. SND_EFW_DEV_ENTRY(VENDOR_LOUD, MODEL_MACKIE_400F),
  265. SND_EFW_DEV_ENTRY(VENDOR_LOUD, MODEL_MACKIE_1200F),
  266. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_8),
  267. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12),
  268. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12HD),
  269. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_12_APPLE),
  270. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_2),
  271. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_4),
  272. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_AUDIOFIRE_9),
  273. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_FIREWORKS_8),
  274. SND_EFW_DEV_ENTRY(VENDOR_ECHO, MODEL_ECHO_FIREWORKS_HDMI),
  275. SND_EFW_DEV_ENTRY(VENDOR_GIBSON, MODEL_GIBSON_RIP),
  276. SND_EFW_DEV_ENTRY(VENDOR_GIBSON, MODEL_GIBSON_GOLDTOP),
  277. {}
  278. };
  279. MODULE_DEVICE_TABLE(ieee1394, efw_id_table);
  280. static struct fw_driver efw_driver = {
  281. .driver = {
  282. .owner = THIS_MODULE,
  283. .name = "snd-fireworks",
  284. .bus = &fw_bus_type,
  285. },
  286. .probe = efw_probe,
  287. .update = efw_update,
  288. .remove = efw_remove,
  289. .id_table = efw_id_table,
  290. };
  291. static int __init snd_efw_init(void)
  292. {
  293. int err;
  294. err = snd_efw_transaction_register();
  295. if (err < 0)
  296. goto end;
  297. err = driver_register(&efw_driver.driver);
  298. if (err < 0)
  299. snd_efw_transaction_unregister();
  300. end:
  301. return err;
  302. }
  303. static void __exit snd_efw_exit(void)
  304. {
  305. snd_efw_transaction_unregister();
  306. driver_unregister(&efw_driver.driver);
  307. }
  308. module_init(snd_efw_init);
  309. module_exit(snd_efw_exit);