Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux/fpc-iii.git] / sound / firewire / fireface / ff.h
blob64df44beb95058ab42f51d195edc4f6497edea88
1 /*
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.
7 */
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>
30 #include "../lib.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 struct snd_ff_protocol;
41 struct snd_ff_spec {
42 const char *const name;
44 const unsigned int pcm_capture_channels[SND_FF_STREAM_MODES];
45 const unsigned int pcm_playback_channels[SND_FF_STREAM_MODES];
47 unsigned int midi_in_ports;
48 unsigned int midi_out_ports;
50 const struct snd_ff_protocol *protocol;
53 struct snd_ff {
54 struct snd_card *card;
55 struct fw_unit *unit;
56 struct mutex mutex;
57 spinlock_t lock;
59 bool registered;
60 struct delayed_work dwork;
62 const struct snd_ff_spec *spec;
64 /* To handle MIDI tx. */
65 struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
66 struct fw_address_handler async_handler;
68 /* TO handle MIDI rx. */
69 struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
70 u8 running_status[SND_FF_OUT_MIDI_PORTS];
71 __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
72 struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
73 struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
74 ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
75 bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
76 unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
78 unsigned int substreams_counter;
79 struct amdtp_stream tx_stream;
80 struct amdtp_stream rx_stream;
81 struct fw_iso_resources tx_resources;
82 struct fw_iso_resources rx_resources;
84 int dev_lock_count;
85 bool dev_lock_changed;
86 wait_queue_head_t hwdep_wait;
89 enum snd_ff_clock_src {
90 SND_FF_CLOCK_SRC_INTERNAL,
91 SND_FF_CLOCK_SRC_SPDIF,
92 SND_FF_CLOCK_SRC_ADAT,
93 SND_FF_CLOCK_SRC_WORD,
94 SND_FF_CLOCK_SRC_LTC,
95 /* TODO: perhaps ADAT2 and TCO exists. */
98 struct snd_ff_protocol {
99 int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
100 enum snd_ff_clock_src *src);
101 int (*begin_session)(struct snd_ff *ff, unsigned int rate);
102 void (*finish_session)(struct snd_ff *ff);
103 int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
105 void (*dump_sync_status)(struct snd_ff *ff,
106 struct snd_info_buffer *buffer);
107 void (*dump_clock_config)(struct snd_ff *ff,
108 struct snd_info_buffer *buffer);
110 u64 midi_high_addr_reg;
111 u64 midi_rx_port_0_reg;
112 u64 midi_rx_port_1_reg;
115 extern const struct snd_ff_protocol snd_ff_protocol_ff400;
117 int snd_ff_transaction_register(struct snd_ff *ff);
118 int snd_ff_transaction_reregister(struct snd_ff *ff);
119 void snd_ff_transaction_unregister(struct snd_ff *ff);
121 int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
122 unsigned int pcm_channels);
123 int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
124 struct snd_pcm_runtime *runtime);
125 int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
126 enum amdtp_stream_direction dir);
128 int snd_ff_stream_init_duplex(struct snd_ff *ff);
129 void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
130 int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
131 void snd_ff_stream_stop_duplex(struct snd_ff *ff);
132 void snd_ff_stream_update_duplex(struct snd_ff *ff);
134 void snd_ff_stream_lock_changed(struct snd_ff *ff);
135 int snd_ff_stream_lock_try(struct snd_ff *ff);
136 void snd_ff_stream_lock_release(struct snd_ff *ff);
138 void snd_ff_proc_init(struct snd_ff *ff);
140 int snd_ff_create_midi_devices(struct snd_ff *ff);
142 int snd_ff_create_pcm_devices(struct snd_ff *ff);
144 int snd_ff_create_hwdep_devices(struct snd_ff *ff);
146 #endif