0001
0002
0003
0004
0005
0006
0007
0008 #ifndef SOUND_FIREWIRE_MOTU_H_INCLUDED
0009 #define SOUND_FIREWIRE_MOTU_H_INCLUDED
0010
0011 #include <linux/device.h>
0012 #include <linux/firewire.h>
0013 #include <linux/firewire-constants.h>
0014 #include <linux/module.h>
0015 #include <linux/mod_devicetable.h>
0016 #include <linux/mutex.h>
0017 #include <linux/slab.h>
0018 #include <linux/compat.h>
0019 #include <linux/sched/signal.h>
0020
0021 #include <sound/control.h>
0022 #include <sound/core.h>
0023 #include <sound/pcm.h>
0024 #include <sound/info.h>
0025 #include <sound/rawmidi.h>
0026 #include <sound/firewire.h>
0027 #include <sound/hwdep.h>
0028
0029 #include "../lib.h"
0030 #include "../amdtp-stream.h"
0031 #include "../iso-resources.h"
0032
0033 struct snd_motu_packet_format {
0034 unsigned char midi_flag_offset;
0035 unsigned char midi_byte_offset;
0036 unsigned char pcm_byte_offset;
0037
0038 unsigned char msg_chunks;
0039 unsigned char pcm_chunks[3];
0040 };
0041
0042 struct amdtp_motu_cache {
0043 unsigned int *event_offsets;
0044 unsigned int size;
0045 unsigned int tail;
0046 unsigned int tx_cycle_count;
0047 unsigned int head;
0048 unsigned int rx_cycle_count;
0049 };
0050
0051 struct snd_motu {
0052 struct snd_card *card;
0053 struct fw_unit *unit;
0054 struct mutex mutex;
0055 spinlock_t lock;
0056
0057
0058 const struct snd_motu_spec *spec;
0059
0060
0061 struct snd_motu_packet_format tx_packet_formats;
0062 struct snd_motu_packet_format rx_packet_formats;
0063 struct amdtp_stream tx_stream;
0064 struct amdtp_stream rx_stream;
0065 struct fw_iso_resources tx_resources;
0066 struct fw_iso_resources rx_resources;
0067 unsigned int substreams_counter;
0068
0069
0070 struct fw_address_handler async_handler;
0071 u32 msg;
0072
0073
0074 int dev_lock_count;
0075 bool dev_lock_changed;
0076 wait_queue_head_t hwdep_wait;
0077 struct snd_hwdep *hwdep;
0078
0079 struct amdtp_domain domain;
0080
0081 struct amdtp_motu_cache cache;
0082
0083 void *message_parser;
0084 };
0085
0086 enum snd_motu_spec_flags {
0087 SND_MOTU_SPEC_RX_MIDI_2ND_Q = 0x0001,
0088 SND_MOTU_SPEC_RX_MIDI_3RD_Q = 0x0002,
0089 SND_MOTU_SPEC_TX_MIDI_2ND_Q = 0x0004,
0090 SND_MOTU_SPEC_TX_MIDI_3RD_Q = 0x0008,
0091 SND_MOTU_SPEC_REGISTER_DSP = 0x0010,
0092 SND_MOTU_SPEC_COMMAND_DSP = 0x0020,
0093 };
0094
0095 #define SND_MOTU_CLOCK_RATE_COUNT 6
0096 extern const unsigned int snd_motu_clock_rates[SND_MOTU_CLOCK_RATE_COUNT];
0097
0098 enum snd_motu_clock_source {
0099 SND_MOTU_CLOCK_SOURCE_INTERNAL,
0100 SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB,
0101 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT,
0102 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A,
0103 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B,
0104 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT,
0105 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A,
0106 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B,
0107 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX,
0108 SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR,
0109 SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC,
0110 SND_MOTU_CLOCK_SOURCE_SPH,
0111 SND_MOTU_CLOCK_SOURCE_UNKNOWN,
0112 };
0113
0114 enum snd_motu_protocol_version {
0115 SND_MOTU_PROTOCOL_V1,
0116 SND_MOTU_PROTOCOL_V2,
0117 SND_MOTU_PROTOCOL_V3,
0118 };
0119
0120 struct snd_motu_spec {
0121 const char *const name;
0122 enum snd_motu_protocol_version protocol_version;
0123
0124 unsigned int flags;
0125
0126 unsigned char tx_fixed_pcm_chunks[3];
0127 unsigned char rx_fixed_pcm_chunks[3];
0128 };
0129
0130 extern const struct snd_motu_spec snd_motu_spec_828;
0131 extern const struct snd_motu_spec snd_motu_spec_896;
0132
0133 extern const struct snd_motu_spec snd_motu_spec_828mk2;
0134 extern const struct snd_motu_spec snd_motu_spec_896hd;
0135 extern const struct snd_motu_spec snd_motu_spec_traveler;
0136 extern const struct snd_motu_spec snd_motu_spec_ultralite;
0137 extern const struct snd_motu_spec snd_motu_spec_8pre;
0138
0139 extern const struct snd_motu_spec snd_motu_spec_828mk3_fw;
0140 extern const struct snd_motu_spec snd_motu_spec_828mk3_hybrid;
0141 extern const struct snd_motu_spec snd_motu_spec_traveler_mk3;
0142 extern const struct snd_motu_spec snd_motu_spec_ultralite_mk3;
0143 extern const struct snd_motu_spec snd_motu_spec_audio_express;
0144 extern const struct snd_motu_spec snd_motu_spec_track16;
0145 extern const struct snd_motu_spec snd_motu_spec_4pre;
0146
0147 int amdtp_motu_init(struct amdtp_stream *s, struct fw_unit *unit,
0148 enum amdtp_stream_direction dir,
0149 const struct snd_motu_spec *spec,
0150 struct amdtp_motu_cache *cache);
0151 int amdtp_motu_set_parameters(struct amdtp_stream *s, unsigned int rate,
0152 unsigned int midi_ports,
0153 struct snd_motu_packet_format *formats);
0154 int amdtp_motu_add_pcm_hw_constraints(struct amdtp_stream *s,
0155 struct snd_pcm_runtime *runtime);
0156 void amdtp_motu_midi_trigger(struct amdtp_stream *s, unsigned int port,
0157 struct snd_rawmidi_substream *midi);
0158
0159 int snd_motu_transaction_read(struct snd_motu *motu, u32 offset, __be32 *reg,
0160 size_t size);
0161 int snd_motu_transaction_write(struct snd_motu *motu, u32 offset, __be32 *reg,
0162 size_t size);
0163 int snd_motu_transaction_register(struct snd_motu *motu);
0164 int snd_motu_transaction_reregister(struct snd_motu *motu);
0165 void snd_motu_transaction_unregister(struct snd_motu *motu);
0166
0167 int snd_motu_stream_init_duplex(struct snd_motu *motu);
0168 void snd_motu_stream_destroy_duplex(struct snd_motu *motu);
0169 int snd_motu_stream_cache_packet_formats(struct snd_motu *motu);
0170 int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
0171 unsigned int frames_per_period,
0172 unsigned int frames_per_buffer);
0173 int snd_motu_stream_start_duplex(struct snd_motu *motu);
0174 void snd_motu_stream_stop_duplex(struct snd_motu *motu);
0175 int snd_motu_stream_lock_try(struct snd_motu *motu);
0176 void snd_motu_stream_lock_release(struct snd_motu *motu);
0177
0178 void snd_motu_proc_init(struct snd_motu *motu);
0179
0180 int snd_motu_create_pcm_devices(struct snd_motu *motu);
0181
0182 int snd_motu_create_midi_devices(struct snd_motu *motu);
0183
0184 int snd_motu_create_hwdep_device(struct snd_motu *motu);
0185
0186 int snd_motu_protocol_v1_get_clock_rate(struct snd_motu *motu,
0187 unsigned int *rate);
0188 int snd_motu_protocol_v1_set_clock_rate(struct snd_motu *motu,
0189 unsigned int rate);
0190 int snd_motu_protocol_v1_get_clock_source(struct snd_motu *motu,
0191 enum snd_motu_clock_source *src);
0192 int snd_motu_protocol_v1_switch_fetching_mode(struct snd_motu *motu,
0193 bool enable);
0194 int snd_motu_protocol_v1_cache_packet_formats(struct snd_motu *motu);
0195
0196 int snd_motu_protocol_v2_get_clock_rate(struct snd_motu *motu,
0197 unsigned int *rate);
0198 int snd_motu_protocol_v2_set_clock_rate(struct snd_motu *motu,
0199 unsigned int rate);
0200 int snd_motu_protocol_v2_get_clock_source(struct snd_motu *motu,
0201 enum snd_motu_clock_source *src);
0202 int snd_motu_protocol_v2_switch_fetching_mode(struct snd_motu *motu,
0203 bool enable);
0204 int snd_motu_protocol_v2_cache_packet_formats(struct snd_motu *motu);
0205
0206 int snd_motu_protocol_v3_get_clock_rate(struct snd_motu *motu,
0207 unsigned int *rate);
0208 int snd_motu_protocol_v3_set_clock_rate(struct snd_motu *motu,
0209 unsigned int rate);
0210 int snd_motu_protocol_v3_get_clock_source(struct snd_motu *motu,
0211 enum snd_motu_clock_source *src);
0212 int snd_motu_protocol_v3_switch_fetching_mode(struct snd_motu *motu,
0213 bool enable);
0214 int snd_motu_protocol_v3_cache_packet_formats(struct snd_motu *motu);
0215
0216 static inline int snd_motu_protocol_get_clock_rate(struct snd_motu *motu,
0217 unsigned int *rate)
0218 {
0219 if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V2)
0220 return snd_motu_protocol_v2_get_clock_rate(motu, rate);
0221 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V3)
0222 return snd_motu_protocol_v3_get_clock_rate(motu, rate);
0223 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V1)
0224 return snd_motu_protocol_v1_get_clock_rate(motu, rate);
0225 else
0226 return -ENXIO;
0227 }
0228
0229 static inline int snd_motu_protocol_set_clock_rate(struct snd_motu *motu,
0230 unsigned int rate)
0231 {
0232 if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V2)
0233 return snd_motu_protocol_v2_set_clock_rate(motu, rate);
0234 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V3)
0235 return snd_motu_protocol_v3_set_clock_rate(motu, rate);
0236 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V1)
0237 return snd_motu_protocol_v1_set_clock_rate(motu, rate);
0238 else
0239 return -ENXIO;
0240 }
0241
0242 static inline int snd_motu_protocol_get_clock_source(struct snd_motu *motu,
0243 enum snd_motu_clock_source *source)
0244 {
0245 if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V2)
0246 return snd_motu_protocol_v2_get_clock_source(motu, source);
0247 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V3)
0248 return snd_motu_protocol_v3_get_clock_source(motu, source);
0249 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V1)
0250 return snd_motu_protocol_v1_get_clock_source(motu, source);
0251 else
0252 return -ENXIO;
0253 }
0254
0255 static inline int snd_motu_protocol_switch_fetching_mode(struct snd_motu *motu,
0256 bool enable)
0257 {
0258 if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V2)
0259 return snd_motu_protocol_v2_switch_fetching_mode(motu, enable);
0260 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V3)
0261 return snd_motu_protocol_v3_switch_fetching_mode(motu, enable);
0262 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V1)
0263 return snd_motu_protocol_v1_switch_fetching_mode(motu, enable);
0264 else
0265 return -ENXIO;
0266 }
0267
0268 static inline int snd_motu_protocol_cache_packet_formats(struct snd_motu *motu)
0269 {
0270 if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V2)
0271 return snd_motu_protocol_v2_cache_packet_formats(motu);
0272 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V3)
0273 return snd_motu_protocol_v3_cache_packet_formats(motu);
0274 else if (motu->spec->protocol_version == SND_MOTU_PROTOCOL_V1)
0275 return snd_motu_protocol_v1_cache_packet_formats(motu);
0276 else
0277 return -ENXIO;
0278 }
0279
0280 int snd_motu_register_dsp_message_parser_new(struct snd_motu *motu);
0281 int snd_motu_register_dsp_message_parser_init(struct snd_motu *motu);
0282 void snd_motu_register_dsp_message_parser_parse(struct snd_motu *motu, const struct pkt_desc *descs,
0283 unsigned int desc_count, unsigned int data_block_quadlets);
0284 void snd_motu_register_dsp_message_parser_copy_meter(struct snd_motu *motu,
0285 struct snd_firewire_motu_register_dsp_meter *meter);
0286 void snd_motu_register_dsp_message_parser_copy_parameter(struct snd_motu *motu,
0287 struct snd_firewire_motu_register_dsp_parameter *params);
0288 unsigned int snd_motu_register_dsp_message_parser_count_event(struct snd_motu *motu);
0289 bool snd_motu_register_dsp_message_parser_copy_event(struct snd_motu *motu, u32 *event);
0290
0291 int snd_motu_command_dsp_message_parser_new(struct snd_motu *motu);
0292 int snd_motu_command_dsp_message_parser_init(struct snd_motu *motu, enum cip_sfc sfc);
0293 void snd_motu_command_dsp_message_parser_parse(struct snd_motu *motu, const struct pkt_desc *descs,
0294 unsigned int desc_count, unsigned int data_block_quadlets);
0295 void snd_motu_command_dsp_message_parser_copy_meter(struct snd_motu *motu,
0296 struct snd_firewire_motu_command_dsp_meter *meter);
0297
0298 #endif