0001
0002
0003
0004
0005
0006
0007
0008 #ifndef SOUND_FIREFACE_H_INCLUDED
0009 #define SOUND_FIREFACE_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/core.h>
0022 #include <sound/info.h>
0023 #include <sound/rawmidi.h>
0024 #include <sound/pcm.h>
0025 #include <sound/pcm_params.h>
0026 #include <sound/hwdep.h>
0027 #include <sound/firewire.h>
0028
0029 #include "../lib.h"
0030 #include "../amdtp-stream.h"
0031 #include "../iso-resources.h"
0032
0033 #define SND_FF_MAXIMIM_MIDI_QUADS 9
0034 #define SND_FF_IN_MIDI_PORTS 2
0035 #define SND_FF_OUT_MIDI_PORTS 2
0036
0037 enum snd_ff_unit_version {
0038 SND_FF_UNIT_VERSION_FF800 = 0x000001,
0039 SND_FF_UNIT_VERSION_FF400 = 0x000002,
0040 SND_FF_UNIT_VERSION_UFX = 0x000003,
0041 SND_FF_UNIT_VERSION_UCX = 0x000004,
0042 SND_FF_UNIT_VERSION_802 = 0x000005,
0043 };
0044
0045 enum snd_ff_stream_mode {
0046 SND_FF_STREAM_MODE_LOW = 0,
0047 SND_FF_STREAM_MODE_MID,
0048 SND_FF_STREAM_MODE_HIGH,
0049 SND_FF_STREAM_MODE_COUNT,
0050 };
0051
0052 struct snd_ff_protocol;
0053 struct snd_ff_spec {
0054 const unsigned int pcm_capture_channels[SND_FF_STREAM_MODE_COUNT];
0055 const unsigned int pcm_playback_channels[SND_FF_STREAM_MODE_COUNT];
0056
0057 unsigned int midi_in_ports;
0058 unsigned int midi_out_ports;
0059
0060 const struct snd_ff_protocol *protocol;
0061 u64 midi_high_addr;
0062 u8 midi_addr_range;
0063 u64 midi_rx_addrs[SND_FF_OUT_MIDI_PORTS];
0064 };
0065
0066 struct snd_ff {
0067 struct snd_card *card;
0068 struct fw_unit *unit;
0069 struct mutex mutex;
0070 spinlock_t lock;
0071
0072 enum snd_ff_unit_version unit_version;
0073 const struct snd_ff_spec *spec;
0074
0075
0076 struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
0077 struct fw_address_handler async_handler;
0078
0079
0080 struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
0081 bool on_sysex[SND_FF_OUT_MIDI_PORTS];
0082 __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
0083 struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
0084 struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
0085 ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
0086 bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
0087 unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
0088
0089 unsigned int substreams_counter;
0090 struct amdtp_stream tx_stream;
0091 struct amdtp_stream rx_stream;
0092 struct fw_iso_resources tx_resources;
0093 struct fw_iso_resources rx_resources;
0094
0095 int dev_lock_count;
0096 bool dev_lock_changed;
0097 wait_queue_head_t hwdep_wait;
0098
0099 struct amdtp_domain domain;
0100 };
0101
0102 enum snd_ff_clock_src {
0103 SND_FF_CLOCK_SRC_INTERNAL,
0104 SND_FF_CLOCK_SRC_SPDIF,
0105 SND_FF_CLOCK_SRC_ADAT1,
0106 SND_FF_CLOCK_SRC_ADAT2,
0107 SND_FF_CLOCK_SRC_WORD,
0108 SND_FF_CLOCK_SRC_LTC,
0109
0110 };
0111
0112 struct snd_ff_protocol {
0113 void (*handle_midi_msg)(struct snd_ff *ff, unsigned int offset,
0114 __le32 *buf, size_t length);
0115 int (*fill_midi_msg)(struct snd_ff *ff,
0116 struct snd_rawmidi_substream *substream,
0117 unsigned int port);
0118 int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
0119 enum snd_ff_clock_src *src);
0120 int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
0121 int (*allocate_resources)(struct snd_ff *ff, unsigned int rate);
0122 int (*begin_session)(struct snd_ff *ff, unsigned int rate);
0123 void (*finish_session)(struct snd_ff *ff);
0124 void (*dump_status)(struct snd_ff *ff, struct snd_info_buffer *buffer);
0125 };
0126
0127 extern const struct snd_ff_protocol snd_ff_protocol_ff800;
0128 extern const struct snd_ff_protocol snd_ff_protocol_ff400;
0129 extern const struct snd_ff_protocol snd_ff_protocol_latter;
0130
0131 int snd_ff_transaction_register(struct snd_ff *ff);
0132 int snd_ff_transaction_reregister(struct snd_ff *ff);
0133 void snd_ff_transaction_unregister(struct snd_ff *ff);
0134
0135 int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
0136 unsigned int pcm_channels);
0137 int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
0138 struct snd_pcm_runtime *runtime);
0139 int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
0140 enum amdtp_stream_direction dir);
0141
0142 int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
0143 enum snd_ff_stream_mode *mode);
0144 int snd_ff_stream_init_duplex(struct snd_ff *ff);
0145 void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
0146 int snd_ff_stream_reserve_duplex(struct snd_ff *ff, unsigned int rate,
0147 unsigned int frames_per_period,
0148 unsigned int frames_per_buffer);
0149 int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
0150 void snd_ff_stream_stop_duplex(struct snd_ff *ff);
0151 void snd_ff_stream_update_duplex(struct snd_ff *ff);
0152
0153 void snd_ff_stream_lock_changed(struct snd_ff *ff);
0154 int snd_ff_stream_lock_try(struct snd_ff *ff);
0155 void snd_ff_stream_lock_release(struct snd_ff *ff);
0156
0157 void snd_ff_proc_init(struct snd_ff *ff);
0158 const char *snd_ff_proc_get_clk_label(enum snd_ff_clock_src src);
0159
0160 int snd_ff_create_midi_devices(struct snd_ff *ff);
0161
0162 int snd_ff_create_pcm_devices(struct snd_ff *ff);
0163
0164 int snd_ff_create_hwdep_devices(struct snd_ff *ff);
0165
0166 #endif