fireworks.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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.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. /* for transaction */
  58. u32 seqnum;
  59. bool resp_addr_changable;
  60. /* for quirks */
  61. bool is_af9;
  62. u32 firmware_version;
  63. unsigned int midi_in_ports;
  64. unsigned int midi_out_ports;
  65. unsigned int supported_sampling_rate;
  66. unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
  67. unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
  68. struct amdtp_stream *master;
  69. struct amdtp_stream tx_stream;
  70. struct amdtp_stream rx_stream;
  71. struct cmp_connection out_conn;
  72. struct cmp_connection in_conn;
  73. atomic_t capture_substreams;
  74. atomic_t playback_substreams;
  75. /* hardware metering parameters */
  76. unsigned int phys_out;
  77. unsigned int phys_in;
  78. unsigned int phys_out_grp_count;
  79. unsigned int phys_in_grp_count;
  80. struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
  81. struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
  82. /* for uapi */
  83. int dev_lock_count;
  84. bool dev_lock_changed;
  85. wait_queue_head_t hwdep_wait;
  86. /* response queue */
  87. u8 *resp_buf;
  88. u8 *pull_ptr;
  89. u8 *push_ptr;
  90. unsigned int resp_queues;
  91. };
  92. int snd_efw_transaction_cmd(struct fw_unit *unit,
  93. const void *cmd, unsigned int size);
  94. int snd_efw_transaction_run(struct fw_unit *unit,
  95. const void *cmd, unsigned int cmd_size,
  96. void *resp, unsigned int resp_size);
  97. int snd_efw_transaction_register(void);
  98. void snd_efw_transaction_unregister(void);
  99. void snd_efw_transaction_bus_reset(struct fw_unit *unit);
  100. void snd_efw_transaction_add_instance(struct snd_efw *efw);
  101. void snd_efw_transaction_remove_instance(struct snd_efw *efw);
  102. struct snd_efw_hwinfo {
  103. u32 flags;
  104. u32 guid_hi;
  105. u32 guid_lo;
  106. u32 type;
  107. u32 version;
  108. char vendor_name[HWINFO_NAME_SIZE_BYTES];
  109. char model_name[HWINFO_NAME_SIZE_BYTES];
  110. u32 supported_clocks;
  111. u32 amdtp_rx_pcm_channels;
  112. u32 amdtp_tx_pcm_channels;
  113. u32 phys_out;
  114. u32 phys_in;
  115. u32 phys_out_grp_count;
  116. struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
  117. u32 phys_in_grp_count;
  118. struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
  119. u32 midi_out_ports;
  120. u32 midi_in_ports;
  121. u32 max_sample_rate;
  122. u32 min_sample_rate;
  123. u32 dsp_version;
  124. u32 arm_version;
  125. u32 mixer_playback_channels;
  126. u32 mixer_capture_channels;
  127. u32 fpga_version;
  128. u32 amdtp_rx_pcm_channels_2x;
  129. u32 amdtp_tx_pcm_channels_2x;
  130. u32 amdtp_rx_pcm_channels_4x;
  131. u32 amdtp_tx_pcm_channels_4x;
  132. u32 reserved[16];
  133. } __packed;
  134. enum snd_efw_grp_type {
  135. SND_EFW_CH_TYPE_ANALOG = 0,
  136. SND_EFW_CH_TYPE_SPDIF = 1,
  137. SND_EFW_CH_TYPE_ADAT = 2,
  138. SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3,
  139. SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4,
  140. SND_EFW_CH_TYPE_HEADPHONES = 5,
  141. SND_EFW_CH_TYPE_I2S = 6,
  142. SND_EFW_CH_TYPE_GUITAR = 7,
  143. SND_EFW_CH_TYPE_PIEZO_GUITAR = 8,
  144. SND_EFW_CH_TYPE_GUITAR_STRING = 9,
  145. SND_EFW_CH_TYPE_DUMMY
  146. };
  147. struct snd_efw_phys_meters {
  148. u32 status; /* guitar state/midi signal/clock input detect */
  149. u32 reserved0;
  150. u32 reserved1;
  151. u32 reserved2;
  152. u32 reserved3;
  153. u32 out_meters;
  154. u32 in_meters;
  155. u32 reserved4;
  156. u32 reserved5;
  157. u32 values[0];
  158. } __packed;
  159. enum snd_efw_clock_source {
  160. SND_EFW_CLOCK_SOURCE_INTERNAL = 0,
  161. SND_EFW_CLOCK_SOURCE_SYTMATCH = 1,
  162. SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2,
  163. SND_EFW_CLOCK_SOURCE_SPDIF = 3,
  164. SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
  165. SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
  166. SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
  167. };
  168. enum snd_efw_transport_mode {
  169. SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
  170. SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
  171. };
  172. int snd_efw_command_set_resp_addr(struct snd_efw *efw,
  173. u16 addr_high, u32 addr_low);
  174. int snd_efw_command_set_tx_mode(struct snd_efw *efw,
  175. enum snd_efw_transport_mode mode);
  176. int snd_efw_command_get_hwinfo(struct snd_efw *efw,
  177. struct snd_efw_hwinfo *hwinfo);
  178. int snd_efw_command_get_phys_meters(struct snd_efw *efw,
  179. struct snd_efw_phys_meters *meters,
  180. unsigned int len);
  181. int snd_efw_command_get_clock_source(struct snd_efw *efw,
  182. enum snd_efw_clock_source *source);
  183. int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
  184. int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
  185. int snd_efw_stream_init_duplex(struct snd_efw *efw);
  186. int snd_efw_stream_start_duplex(struct snd_efw *efw, unsigned int rate);
  187. void snd_efw_stream_stop_duplex(struct snd_efw *efw);
  188. void snd_efw_stream_update_duplex(struct snd_efw *efw);
  189. void snd_efw_stream_destroy_duplex(struct snd_efw *efw);
  190. void snd_efw_stream_lock_changed(struct snd_efw *efw);
  191. int snd_efw_stream_lock_try(struct snd_efw *efw);
  192. void snd_efw_stream_lock_release(struct snd_efw *efw);
  193. void snd_efw_proc_init(struct snd_efw *efw);
  194. int snd_efw_create_midi_devices(struct snd_efw *efw);
  195. int snd_efw_create_pcm_devices(struct snd_efw *efw);
  196. int snd_efw_get_multiplier_mode(unsigned int sampling_rate, unsigned int *mode);
  197. int snd_efw_create_hwdep_device(struct snd_efw *efw);
  198. #define SND_EFW_DEV_ENTRY(vendor, model) \
  199. { \
  200. .match_flags = IEEE1394_MATCH_VENDOR_ID | \
  201. IEEE1394_MATCH_MODEL_ID, \
  202. .vendor_id = vendor,\
  203. .model_id = model \
  204. }
  205. #endif