1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * ff.h - a part of driver for RME Fireface series
5 * Copyright (c) 2015-2017 Takashi Sakamoto
8 #ifndef SOUND_FIREFACE_H_INCLUDED
9 #define SOUND_FIREFACE_H_INCLUDED
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/mutex.h>
17 #include <linux/slab.h>
18 #include <linux/compat.h>
19 #include <linux/sched/signal.h>
21 #include <sound/core.h>
22 #include <sound/info.h>
23 #include <sound/rawmidi.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/hwdep.h>
27 #include <sound/firewire.h>
30 #include "../amdtp-stream.h"
31 #include "../iso-resources.h"
33 #define SND_FF_MAXIMIM_MIDI_QUADS 9
34 #define SND_FF_IN_MIDI_PORTS 2
35 #define SND_FF_OUT_MIDI_PORTS 2
37 enum snd_ff_stream_mode {
38 SND_FF_STREAM_MODE_LOW = 0,
39 SND_FF_STREAM_MODE_MID,
40 SND_FF_STREAM_MODE_HIGH,
41 SND_FF_STREAM_MODE_COUNT,
44 struct snd_ff_protocol;
46 const char *const name;
48 const unsigned int pcm_capture_channels[SND_FF_STREAM_MODE_COUNT];
49 const unsigned int pcm_playback_channels[SND_FF_STREAM_MODE_COUNT];
51 unsigned int midi_in_ports;
52 unsigned int midi_out_ports;
54 const struct snd_ff_protocol *protocol;
57 u64 midi_rx_addrs[SND_FF_OUT_MIDI_PORTS];
61 struct snd_card *card;
67 struct delayed_work dwork;
69 const struct snd_ff_spec *spec;
71 /* To handle MIDI tx. */
72 struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
73 struct fw_address_handler async_handler;
75 /* TO handle MIDI rx. */
76 struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
77 bool on_sysex[SND_FF_OUT_MIDI_PORTS];
78 __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
79 struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
80 struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
81 ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
82 bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
83 unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
85 unsigned int substreams_counter;
86 struct amdtp_stream tx_stream;
87 struct amdtp_stream rx_stream;
88 struct fw_iso_resources tx_resources;
89 struct fw_iso_resources rx_resources;
92 bool dev_lock_changed;
93 wait_queue_head_t hwdep_wait;
96 enum snd_ff_clock_src {
97 SND_FF_CLOCK_SRC_INTERNAL,
98 SND_FF_CLOCK_SRC_SPDIF,
99 SND_FF_CLOCK_SRC_ADAT1,
100 SND_FF_CLOCK_SRC_ADAT2,
101 SND_FF_CLOCK_SRC_WORD,
102 SND_FF_CLOCK_SRC_LTC,
103 /* TODO: perhaps TCO exists. */
106 struct snd_ff_protocol {
107 void (*handle_midi_msg)(struct snd_ff *ff, unsigned int offset,
108 __le32 *buf, size_t length);
109 int (*fill_midi_msg)(struct snd_ff *ff,
110 struct snd_rawmidi_substream *substream,
112 int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
113 enum snd_ff_clock_src *src);
114 int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
115 int (*allocate_resources)(struct snd_ff *ff, unsigned int rate);
116 int (*begin_session)(struct snd_ff *ff, unsigned int rate);
117 void (*finish_session)(struct snd_ff *ff);
118 void (*dump_status)(struct snd_ff *ff, struct snd_info_buffer *buffer);
121 extern const struct snd_ff_protocol snd_ff_protocol_ff800;
122 extern const struct snd_ff_protocol snd_ff_protocol_ff400;
123 extern const struct snd_ff_protocol snd_ff_protocol_latter;
125 int snd_ff_transaction_register(struct snd_ff *ff);
126 int snd_ff_transaction_reregister(struct snd_ff *ff);
127 void snd_ff_transaction_unregister(struct snd_ff *ff);
129 int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
130 unsigned int pcm_channels);
131 int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
132 struct snd_pcm_runtime *runtime);
133 int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
134 enum amdtp_stream_direction dir);
136 int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
137 enum snd_ff_stream_mode *mode);
138 int snd_ff_stream_init_duplex(struct snd_ff *ff);
139 void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
140 int snd_ff_stream_reserve_duplex(struct snd_ff *ff, unsigned int rate);
141 int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
142 void snd_ff_stream_stop_duplex(struct snd_ff *ff);
143 void snd_ff_stream_update_duplex(struct snd_ff *ff);
145 void snd_ff_stream_lock_changed(struct snd_ff *ff);
146 int snd_ff_stream_lock_try(struct snd_ff *ff);
147 void snd_ff_stream_lock_release(struct snd_ff *ff);
149 void snd_ff_proc_init(struct snd_ff *ff);
150 const char *snd_ff_proc_get_clk_label(enum snd_ff_clock_src src);
152 int snd_ff_create_midi_devices(struct snd_ff *ff);
154 int snd_ff_create_pcm_devices(struct snd_ff *ff);
156 int snd_ff_create_hwdep_devices(struct snd_ff *ff);