1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * motu.h - a part of driver for MOTU FireWire series
5 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
8 #ifndef SOUND_FIREWIRE_MOTU_H_INCLUDED
9 #define SOUND_FIREWIRE_MOTU_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/control.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/info.h>
25 #include <sound/rawmidi.h>
26 #include <sound/firewire.h>
27 #include <sound/hwdep.h>
30 #include "../amdtp-stream.h"
31 #include "../iso-resources.h"
33 struct snd_motu_packet_format
{
34 unsigned char midi_flag_offset
;
35 unsigned char midi_byte_offset
;
36 unsigned char pcm_byte_offset
;
38 unsigned char msg_chunks
;
39 unsigned char pcm_chunks
[3];
43 struct snd_card
*card
;
49 struct delayed_work dwork
;
51 /* Model dependent information. */
52 const struct snd_motu_spec
*spec
;
54 /* For packet streaming */
55 struct snd_motu_packet_format tx_packet_formats
;
56 struct snd_motu_packet_format rx_packet_formats
;
57 struct amdtp_stream tx_stream
;
58 struct amdtp_stream rx_stream
;
59 struct fw_iso_resources tx_resources
;
60 struct fw_iso_resources rx_resources
;
61 unsigned int substreams_counter
;
63 /* For notification. */
64 struct fw_address_handler async_handler
;
69 bool dev_lock_changed
;
70 wait_queue_head_t hwdep_wait
;
72 struct amdtp_domain domain
;
75 enum snd_motu_spec_flags
{
76 SND_MOTU_SPEC_RX_MIDI_2ND_Q
= 0x0001,
77 SND_MOTU_SPEC_RX_MIDI_3RD_Q
= 0x0002,
78 SND_MOTU_SPEC_TX_MIDI_2ND_Q
= 0x0004,
79 SND_MOTU_SPEC_TX_MIDI_3RD_Q
= 0x0008,
82 #define SND_MOTU_CLOCK_RATE_COUNT 6
83 extern const unsigned int snd_motu_clock_rates
[SND_MOTU_CLOCK_RATE_COUNT
];
85 enum snd_motu_clock_source
{
86 SND_MOTU_CLOCK_SOURCE_INTERNAL
,
87 SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB
,
88 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT
,
89 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A
,
90 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B
,
91 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT
,
92 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A
,
93 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B
,
94 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX
,
95 SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR
,
96 SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC
,
97 SND_MOTU_CLOCK_SOURCE_SPH
,
98 SND_MOTU_CLOCK_SOURCE_UNKNOWN
,
101 enum snd_motu_protocol_version
{
102 SND_MOTU_PROTOCOL_V2
,
103 SND_MOTU_PROTOCOL_V3
,
106 struct snd_motu_spec
{
107 const char *const name
;
108 enum snd_motu_protocol_version protocol_version
;
109 enum snd_motu_spec_flags flags
;
111 unsigned char tx_fixed_pcm_chunks
[3];
112 unsigned char rx_fixed_pcm_chunks
[3];
115 extern const struct snd_motu_spec snd_motu_spec_828mk2
;
116 extern const struct snd_motu_spec snd_motu_spec_traveler
;
117 extern const struct snd_motu_spec snd_motu_spec_ultralite
;
118 extern const struct snd_motu_spec snd_motu_spec_8pre
;
120 extern const struct snd_motu_spec snd_motu_spec_828mk3
;
121 extern const struct snd_motu_spec snd_motu_spec_ultralite_mk3
;
122 extern const struct snd_motu_spec snd_motu_spec_audio_express
;
123 extern const struct snd_motu_spec snd_motu_spec_4pre
;
125 int amdtp_motu_init(struct amdtp_stream
*s
, struct fw_unit
*unit
,
126 enum amdtp_stream_direction dir
,
127 const struct snd_motu_spec
*spec
);
128 int amdtp_motu_set_parameters(struct amdtp_stream
*s
, unsigned int rate
,
129 unsigned int midi_ports
,
130 struct snd_motu_packet_format
*formats
);
131 int amdtp_motu_add_pcm_hw_constraints(struct amdtp_stream
*s
,
132 struct snd_pcm_runtime
*runtime
);
133 void amdtp_motu_midi_trigger(struct amdtp_stream
*s
, unsigned int port
,
134 struct snd_rawmidi_substream
*midi
);
136 int snd_motu_transaction_read(struct snd_motu
*motu
, u32 offset
, __be32
*reg
,
138 int snd_motu_transaction_write(struct snd_motu
*motu
, u32 offset
, __be32
*reg
,
140 int snd_motu_transaction_register(struct snd_motu
*motu
);
141 int snd_motu_transaction_reregister(struct snd_motu
*motu
);
142 void snd_motu_transaction_unregister(struct snd_motu
*motu
);
144 int snd_motu_stream_init_duplex(struct snd_motu
*motu
);
145 void snd_motu_stream_destroy_duplex(struct snd_motu
*motu
);
146 int snd_motu_stream_cache_packet_formats(struct snd_motu
*motu
);
147 int snd_motu_stream_reserve_duplex(struct snd_motu
*motu
, unsigned int rate
,
148 unsigned int frames_per_period
,
149 unsigned int frames_per_buffer
);
150 int snd_motu_stream_start_duplex(struct snd_motu
*motu
);
151 void snd_motu_stream_stop_duplex(struct snd_motu
*motu
);
152 int snd_motu_stream_lock_try(struct snd_motu
*motu
);
153 void snd_motu_stream_lock_release(struct snd_motu
*motu
);
155 void snd_motu_proc_init(struct snd_motu
*motu
);
157 int snd_motu_create_pcm_devices(struct snd_motu
*motu
);
159 int snd_motu_create_midi_devices(struct snd_motu
*motu
);
161 int snd_motu_create_hwdep_device(struct snd_motu
*motu
);
163 int snd_motu_protocol_v2_get_clock_rate(struct snd_motu
*motu
,
165 int snd_motu_protocol_v2_set_clock_rate(struct snd_motu
*motu
,
167 int snd_motu_protocol_v2_get_clock_source(struct snd_motu
*motu
,
168 enum snd_motu_clock_source
*src
);
169 int snd_motu_protocol_v2_switch_fetching_mode(struct snd_motu
*motu
,
171 int snd_motu_protocol_v2_cache_packet_formats(struct snd_motu
*motu
);
173 int snd_motu_protocol_v3_get_clock_rate(struct snd_motu
*motu
,
175 int snd_motu_protocol_v3_set_clock_rate(struct snd_motu
*motu
,
177 int snd_motu_protocol_v3_get_clock_source(struct snd_motu
*motu
,
178 enum snd_motu_clock_source
*src
);
179 int snd_motu_protocol_v3_switch_fetching_mode(struct snd_motu
*motu
,
181 int snd_motu_protocol_v3_cache_packet_formats(struct snd_motu
*motu
);
183 static inline int snd_motu_protocol_get_clock_rate(struct snd_motu
*motu
,
186 if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V2
)
187 return snd_motu_protocol_v2_get_clock_rate(motu
, rate
);
188 else if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V3
)
189 return snd_motu_protocol_v3_get_clock_rate(motu
, rate
);
194 static inline int snd_motu_protocol_set_clock_rate(struct snd_motu
*motu
,
197 if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V2
)
198 return snd_motu_protocol_v2_set_clock_rate(motu
, rate
);
199 else if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V3
)
200 return snd_motu_protocol_v3_set_clock_rate(motu
, rate
);
205 static inline int snd_motu_protocol_get_clock_source(struct snd_motu
*motu
,
206 enum snd_motu_clock_source
*source
)
208 if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V2
)
209 return snd_motu_protocol_v2_get_clock_source(motu
, source
);
210 else if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V3
)
211 return snd_motu_protocol_v3_get_clock_source(motu
, source
);
216 static inline int snd_motu_protocol_switch_fetching_mode(struct snd_motu
*motu
,
219 if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V2
)
220 return snd_motu_protocol_v2_switch_fetching_mode(motu
, enable
);
221 else if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V3
)
222 return snd_motu_protocol_v3_switch_fetching_mode(motu
, enable
);
227 static inline int snd_motu_protocol_cache_packet_formats(struct snd_motu
*motu
)
229 if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V2
)
230 return snd_motu_protocol_v2_cache_packet_formats(motu
);
231 else if (motu
->spec
->protocol_version
== SND_MOTU_PROTOCOL_V3
)
232 return snd_motu_protocol_v3_cache_packet_formats(motu
);