fireworks.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * fireworks.h - 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. #ifndef SOUND_FIREWORKS_H_INCLUDED
  10. #define SOUND_FIREWORKS_H_INCLUDED
  11. #include <linux/compat.h>
  12. #include <linux/device.h>
  13. #include <linux/firewire.h>
  14. #include <linux/firewire-constants.h>
  15. #include <linux/module.h>
  16. #include <linux/mod_devicetable.h>
  17. #include <linux/delay.h>
  18. #include <linux/slab.h>
  19. #include <sound/core.h>
  20. #include <sound/initval.h>
  21. #include <sound/pcm.h>
  22. #include <sound/info.h>
  23. #include <sound/rawmidi.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/firewire.h>
  26. #include <sound/hwdep.h>
  27. #include "../packets-buffer.h"
  28. #include "../iso-resources.h"
  29. #include "../amdtp-am824.h"
  30. #include "../cmp.h"
  31. #include "../lib.h"
  32. #define SND_EFW_MAX_MIDI_OUT_PORTS 2
  33. #define SND_EFW_MAX_MIDI_IN_PORTS 2
  34. #define SND_EFW_MULTIPLIER_MODES 3
  35. #define HWINFO_NAME_SIZE_BYTES 32
  36. #define HWINFO_MAX_CAPS_GROUPS 8
  37. /*
  38. * This should be greater than maximum bytes for EFW response content.
  39. * Currently response against command for isochronous channel mapping is
  40. * confirmed to be the maximum one. But for flexibility, use maximum data
  41. * payload for asynchronous primary packets at S100 (Cable base rate) in
  42. * IEEE Std 1394-1995.
  43. */
  44. #define SND_EFW_RESPONSE_MAXIMUM_BYTES 0x200U
  45. extern unsigned int snd_efw_resp_buf_size;
  46. extern bool snd_efw_resp_buf_debug;
  47. struct snd_efw_phys_grp {
  48. u8 type; /* see enum snd_efw_grp_type */
  49. u8 count;
  50. } __packed;
  51. struct snd_efw {
  52. struct snd_card *card;
  53. struct fw_unit *unit;
  54. int card_index;
  55. struct mutex mutex;
  56. spinlock_t lock;
  57. bool registered;
  58. struct delayed_work dwork;
  59. /* for transaction */
  60. u32 seqnum;
  61. bool resp_addr_changable;
  62. /* for quirks */
  63. bool is_af9;
  64. bool is_fireworks3;
  65. u32 firmware_version;
  66. unsigned int midi_in_ports;
  67. unsigned int midi_out_ports;
  68. unsigned int supported_sampling_rate;
  69. unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
  70. unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
  71. struct amdtp_stream tx_stream;
  72. struct amdtp_stream rx_stream;
  73. struct cmp_connection out_conn;
  74. struct cmp_connection in_conn;
  75. unsigned int capture_substreams;
  76. unsigned int playback_substreams;
  77. /* hardware metering parameters */
  78. unsigned int phys_out;
  79. unsigned int phys_in;
  80. unsigned int phys_out_grp_count;
  81. unsigned int phys_in_grp_count;
  82. struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
  83. struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
  84. /* for uapi */
  85. int dev_lock_count;
  86. bool dev_lock_changed;
  87. wait_queue_head_t hwdep_wait;
  88. /* response queue */
  89. u8 *resp_buf;
  90. u8 *pull_ptr;
  91. u8 *push_ptr;
  92. };
  93. int snd_efw_transaction_cmd(struct fw_unit *unit,
  94. const void *cmd, unsigned int size);
  95. int snd_efw_transaction_run(struct fw_unit *unit,
  96. const void *cmd, unsigned int cmd_size,
  97. void *resp, unsigned int resp_size);
  98. int snd_efw_transaction_register(void);
  99. void snd_efw_transaction_unregister(void);
  100. void snd_efw_transaction_bus_reset(struct fw_unit *unit);
  101. void snd_efw_transaction_add_instance(struct snd_efw *efw);
  102. void snd_efw_transaction_remove_instance(struct snd_efw *efw);
  103. struct snd_efw_hwinfo {
  104. u32 flags;
  105. u32 guid_hi;
  106. u32 guid_lo;
  107. u32 type;
  108. u32 version;
  109. char vendor_name[HWINFO_NAME_SIZE_BYTES];
  110. char model_name[HWINFO_NAME_SIZE_BYTES];
  111. u32 supported_clocks;
  112. u32 amdtp_rx_pcm_channels;
  113. u32 amdtp_tx_pcm_channels;
  114. u32 phys_out;
  115. u32 phys_in;
  116. u32 phys_out_grp_count;
  117. struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
  118. u32 phys_in_grp_count;
  119. struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
  120. u32 midi_out_ports;
  121. u32 midi_in_ports;
  122. u32 max_sample_rate;
  123. u32 min_sample_rate;
  124. u32 dsp_version;
  125. u32 arm_version;
  126. u32 mixer_playback_channels;
  127. u32 mixer_capture_channels;
  128. u32 fpga_version;
  129. u32 amdtp_rx_pcm_channels_2x;
  130. u32 amdtp_tx_pcm_channels_2x;
  131. u32 amdtp_rx_pcm_channels_4x;
  132. u32 amdtp_tx_pcm_channels_4x;
  133. u32 reserved[16];
  134. } __packed;
  135. enum snd_efw_grp_type {
  136. SND_EFW_CH_TYPE_ANALOG = 0,
  137. SND_EFW_CH_TYPE_SPDIF = 1,
  138. SND_EFW_CH_TYPE_ADAT = 2,
  139. SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3,
  140. SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4,
  141. SND_EFW_CH_TYPE_HEADPHONES = 5,
  142. SND_EFW_CH_TYPE_I2S = 6,
  143. SND_EFW_CH_TYPE_GUITAR = 7,
  144. SND_EFW_CH_TYPE_PIEZO_GUITAR = 8,
  145. SND_EFW_CH_TYPE_GUITAR_STRING = 9,
  146. SND_EFW_CH_TYPE_DUMMY
  147. };
  148. struct snd_efw_phys_meters {
  149. u32 status; /* guitar state/midi signal/clock input detect */
  150. u32 reserved0;
  151. u32 reserved1;
  152. u32 reserved2;
  153. u32 reserved3;
  154. u32 out_meters;
  155. u32 in_meters;
  156. u32 reserved4;
  157. u32 reserved5;
  158. u32 values[0];
  159. } __packed;
  160. enum snd_efw_clock_source {
  161. SND_EFW_CLOCK_SOURCE_INTERNAL = 0,
  162. SND_EFW_CLOCK_SOURCE_SYTMATCH = 1,
  163. SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2,
  164. SND_EFW_CLOCK_SOURCE_SPDIF = 3,
  165. SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
  166. SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
  167. SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
  168. };
  169. enum snd_efw_transport_mode {
  170. SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
  171. SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
  172. };
  173. int snd_efw_command_set_resp_addr(struct snd_efw *efw,
  174. u16 addr_high, u32 addr_low);
  175. int snd_efw_command_set_tx_mode(struct snd_efw *efw,
  176. enum snd_efw_transport_mode mode);
  177. int snd_efw_command_get_hwinfo(struct snd_efw *efw,
  178. struct snd_efw_hwinfo *hwinfo);
  179. int snd_efw_command_get_phys_meters(struct snd_efw *efw,
  180. struct snd_efw_phys_meters *meters,
  181. unsigned int len);
  182. int snd_efw_command_get_clock_source(struct snd_efw *efw,
  183. enum snd_efw_clock_source *source);
  184. int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
  185. int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
  186. int snd_efw_stream_init_duplex(struct snd_efw *efw);
  187. int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate);
  188. void snd_efw_stream_stop_duplex(struct snd_efw *efw);
  189. void snd_efw_stream_update_duplex(struct snd_efw *efw);
  190. void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
  191. void snd_efw_stream_lock_changed(struct snd_efw *efw);
  192. int snd_efw_stream_lock_try(struct snd_efw *efw);
  193. void snd_efw_stream_lock_release(struct snd_efw *efw);
  194. void snd_efw_proc_init(struct snd_efw *efw);
  195. int snd_efw_create_midi_devices(struct snd_efw *efw);
  196. int snd_efw_create_pcm_devices(struct snd_efw *efw);
  197. int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
  198. int snd_efw_create_hwdep_device(struct snd_efw *efw);
  199. #define SND_EFW_DEV_ENTRY(vendor, model) \
  200. { \
  201. .match_flags = IEEE1394_MATCH_VENDOR_ID | \
  202. IEEE1394_MATCH_MODEL_ID, \
  203. .vendor_id = vendor,\
  204. .model_id = model \
  205. }
  206. #endif