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