fireworks.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * fireworks.h - a part of driver for Fireworks based devices
  4. *
  5. * Copyright (c) 2009-2010 Clemens Ladisch
  6. * Copyright (c) 2013-2014 Takashi Sakamoto
  7. */
  8. #ifndef SOUND_FIREWORKS_H_INCLUDED
  9. #define SOUND_FIREWORKS_H_INCLUDED
  10. #include <linux/compat.h>
  11. #include <linux/device.h>
  12. #include <linux/firewire.h>
  13. #include <linux/firewire-constants.h>
  14. #include <linux/module.h>
  15. #include <linux/mod_devicetable.h>
  16. #include <linux/delay.h>
  17. #include <linux/slab.h>
  18. #include <linux/sched/signal.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. /* for transaction */
  58. u32 seqnum;
  59. bool resp_addr_changable;
  60. /* for quirks */
  61. bool is_af9;
  62. bool is_fireworks3;
  63. u32 firmware_version;
  64. unsigned int midi_in_ports;
  65. unsigned int midi_out_ports;
  66. unsigned int supported_sampling_rate;
  67. unsigned int pcm_capture_channels[SND_EFW_MULTIPLIER_MODES];
  68. unsigned int pcm_playback_channels[SND_EFW_MULTIPLIER_MODES];
  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. unsigned int substreams_counter;
  74. /* hardware metering parameters */
  75. unsigned int phys_out;
  76. unsigned int phys_in;
  77. unsigned int phys_out_grp_count;
  78. unsigned int phys_in_grp_count;
  79. struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
  80. struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
  81. /* for uapi */
  82. int dev_lock_count;
  83. bool dev_lock_changed;
  84. wait_queue_head_t hwdep_wait;
  85. /* response queue */
  86. u8 *resp_buf;
  87. u8 *pull_ptr;
  88. u8 *push_ptr;
  89. struct amdtp_domain domain;
  90. };
  91. int snd_efw_transaction_cmd(struct fw_unit *unit,
  92. const void *cmd, unsigned int size);
  93. int snd_efw_transaction_run(struct fw_unit *unit,
  94. const void *cmd, unsigned int cmd_size,
  95. void *resp, unsigned int resp_size);
  96. int snd_efw_transaction_register(void);
  97. void snd_efw_transaction_unregister(void);
  98. void snd_efw_transaction_bus_reset(struct fw_unit *unit);
  99. void snd_efw_transaction_add_instance(struct snd_efw *efw);
  100. void snd_efw_transaction_remove_instance(struct snd_efw *efw);
  101. struct snd_efw_hwinfo {
  102. u32 flags;
  103. u32 guid_hi;
  104. u32 guid_lo;
  105. u32 type;
  106. u32 version;
  107. char vendor_name[HWINFO_NAME_SIZE_BYTES];
  108. char model_name[HWINFO_NAME_SIZE_BYTES];
  109. u32 supported_clocks;
  110. u32 amdtp_rx_pcm_channels;
  111. u32 amdtp_tx_pcm_channels;
  112. u32 phys_out;
  113. u32 phys_in;
  114. u32 phys_out_grp_count;
  115. struct snd_efw_phys_grp phys_out_grps[HWINFO_MAX_CAPS_GROUPS];
  116. u32 phys_in_grp_count;
  117. struct snd_efw_phys_grp phys_in_grps[HWINFO_MAX_CAPS_GROUPS];
  118. u32 midi_out_ports;
  119. u32 midi_in_ports;
  120. u32 max_sample_rate;
  121. u32 min_sample_rate;
  122. u32 dsp_version;
  123. u32 arm_version;
  124. u32 mixer_playback_channels;
  125. u32 mixer_capture_channels;
  126. u32 fpga_version;
  127. u32 amdtp_rx_pcm_channels_2x;
  128. u32 amdtp_tx_pcm_channels_2x;
  129. u32 amdtp_rx_pcm_channels_4x;
  130. u32 amdtp_tx_pcm_channels_4x;
  131. u32 reserved[16];
  132. } __packed;
  133. enum snd_efw_grp_type {
  134. SND_EFW_CH_TYPE_ANALOG = 0,
  135. SND_EFW_CH_TYPE_SPDIF = 1,
  136. SND_EFW_CH_TYPE_ADAT = 2,
  137. SND_EFW_CH_TYPE_SPDIF_OR_ADAT = 3,
  138. SND_EFW_CH_TYPE_ANALOG_MIRRORING = 4,
  139. SND_EFW_CH_TYPE_HEADPHONES = 5,
  140. SND_EFW_CH_TYPE_I2S = 6,
  141. SND_EFW_CH_TYPE_GUITAR = 7,
  142. SND_EFW_CH_TYPE_PIEZO_GUITAR = 8,
  143. SND_EFW_CH_TYPE_GUITAR_STRING = 9,
  144. SND_EFW_CH_TYPE_DUMMY
  145. };
  146. struct snd_efw_phys_meters {
  147. u32 status; /* guitar state/midi signal/clock input detect */
  148. u32 reserved0;
  149. u32 reserved1;
  150. u32 reserved2;
  151. u32 reserved3;
  152. u32 out_meters;
  153. u32 in_meters;
  154. u32 reserved4;
  155. u32 reserved5;
  156. u32 values[];
  157. } __packed;
  158. enum snd_efw_clock_source {
  159. SND_EFW_CLOCK_SOURCE_INTERNAL = 0,
  160. // Unused.
  161. SND_EFW_CLOCK_SOURCE_WORDCLOCK = 2,
  162. SND_EFW_CLOCK_SOURCE_SPDIF = 3,
  163. SND_EFW_CLOCK_SOURCE_ADAT_1 = 4,
  164. SND_EFW_CLOCK_SOURCE_ADAT_2 = 5,
  165. SND_EFW_CLOCK_SOURCE_CONTINUOUS = 6 /* internal variable clock */
  166. };
  167. enum snd_efw_transport_mode {
  168. SND_EFW_TRANSPORT_MODE_WINDOWS = 0,
  169. SND_EFW_TRANSPORT_MODE_IEC61883 = 1,
  170. };
  171. int snd_efw_command_set_resp_addr(struct snd_efw *efw,
  172. u16 addr_high, u32 addr_low);
  173. int snd_efw_command_set_tx_mode(struct snd_efw *efw,
  174. enum snd_efw_transport_mode mode);
  175. int snd_efw_command_get_hwinfo(struct snd_efw *efw,
  176. struct snd_efw_hwinfo *hwinfo);
  177. int snd_efw_command_get_phys_meters(struct snd_efw *efw,
  178. struct snd_efw_phys_meters *meters,
  179. unsigned int len);
  180. int snd_efw_command_get_clock_source(struct snd_efw *efw,
  181. enum snd_efw_clock_source *source);
  182. int snd_efw_command_get_sampling_rate(struct snd_efw *efw, unsigned int *rate);
  183. int snd_efw_command_set_sampling_rate(struct snd_efw *efw, unsigned int rate);
  184. int snd_efw_stream_init_duplex(struct snd_efw *efw);
  185. int snd_efw_stream_reserve_duplex(struct snd_efw *efw, unsigned int rate,
  186. unsigned int frames_per_period,
  187. unsigned int frames_per_buffer);
  188. int snd_efw_stream_start_duplex(struct snd_efw *efw);
  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. #endif