2 * ff.h - a part of driver for RME Fireface series
4 * Copyright (c) 2015-2017 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
9 #ifndef SOUND_FIREFACE_H_INCLUDED
10 #define SOUND_FIREFACE_H_INCLUDED
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/mutex.h>
18 #include <linux/slab.h>
19 #include <linux/compat.h>
20 #include <linux/sched/signal.h>
22 #include <sound/core.h>
23 #include <sound/info.h>
24 #include <sound/rawmidi.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/hwdep.h>
28 #include <sound/firewire.h>
31 #include "../amdtp-stream.h"
32 #include "../iso-resources.h"
34 #define SND_FF_STREAM_MODES 3
36 #define SND_FF_MAXIMIM_MIDI_QUADS 9
37 #define SND_FF_IN_MIDI_PORTS 2
38 #define SND_FF_OUT_MIDI_PORTS 2
40 #define SND_FF_REG_SYNC_STATUS 0x0000801c0000ull
41 /* For block wriet request. */
42 #define SND_FF_REG_FETCH_PCM_FRAMES 0x0000801c0000ull
43 #define SND_FF_REG_CLOCK_CONFIG 0x0000801c0004ull
45 struct snd_ff_protocol;
47 const char *const name;
49 const unsigned int pcm_capture_channels[SND_FF_STREAM_MODES];
50 const unsigned int pcm_playback_channels[SND_FF_STREAM_MODES];
52 unsigned int midi_in_ports;
53 unsigned int midi_out_ports;
55 const struct snd_ff_protocol *protocol;
59 struct snd_card *card;
65 struct delayed_work dwork;
67 const struct snd_ff_spec *spec;
69 /* To handle MIDI tx. */
70 struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
71 struct fw_address_handler async_handler;
73 /* TO handle MIDI rx. */
74 struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
75 u8 running_status[SND_FF_OUT_MIDI_PORTS];
76 __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
77 struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
78 struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
79 ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
80 bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
81 unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
83 unsigned int substreams_counter;
84 struct amdtp_stream tx_stream;
85 struct amdtp_stream rx_stream;
86 struct fw_iso_resources tx_resources;
87 struct fw_iso_resources rx_resources;
90 bool dev_lock_changed;
91 wait_queue_head_t hwdep_wait;
94 enum snd_ff_clock_src {
95 SND_FF_CLOCK_SRC_INTERNAL,
96 SND_FF_CLOCK_SRC_SPDIF,
97 SND_FF_CLOCK_SRC_ADAT1,
98 SND_FF_CLOCK_SRC_ADAT2,
99 SND_FF_CLOCK_SRC_WORD,
100 SND_FF_CLOCK_SRC_LTC,
101 /* TODO: perhaps TCO exists. */
104 struct snd_ff_protocol {
105 int (*begin_session)(struct snd_ff *ff, unsigned int rate);
106 void (*finish_session)(struct snd_ff *ff);
107 int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
109 u64 midi_high_addr_reg;
110 u64 midi_rx_port_0_reg;
111 u64 midi_rx_port_1_reg;
114 extern const struct snd_ff_protocol snd_ff_protocol_ff400;
116 int snd_ff_transaction_get_clock(struct snd_ff *ff, unsigned int *rate,
117 enum snd_ff_clock_src *src);
118 int snd_ff_transaction_register(struct snd_ff *ff);
119 int snd_ff_transaction_reregister(struct snd_ff *ff);
120 void snd_ff_transaction_unregister(struct snd_ff *ff);
122 int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
123 unsigned int pcm_channels);
124 int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
125 struct snd_pcm_runtime *runtime);
126 int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
127 enum amdtp_stream_direction dir);
129 int snd_ff_stream_init_duplex(struct snd_ff *ff);
130 void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
131 int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
132 void snd_ff_stream_stop_duplex(struct snd_ff *ff);
133 void snd_ff_stream_update_duplex(struct snd_ff *ff);
135 void snd_ff_stream_lock_changed(struct snd_ff *ff);
136 int snd_ff_stream_lock_try(struct snd_ff *ff);
137 void snd_ff_stream_lock_release(struct snd_ff *ff);
139 void snd_ff_proc_init(struct snd_ff *ff);
141 int snd_ff_create_midi_devices(struct snd_ff *ff);
143 int snd_ff_create_pcm_devices(struct snd_ff *ff);
145 int snd_ff_create_hwdep_devices(struct snd_ff *ff);