blob: 64df44beb95058ab42f51d195edc4f6497edea88 [file] [log] [blame]
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +09001/*
2 * ff.h - a part of driver for RME Fireface series
3 *
4 * Copyright (c) 2015-2017 Takashi Sakamoto
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#ifndef SOUND_FIREFACE_H_INCLUDED
10#define SOUND_FIREFACE_H_INCLUDED
11
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>
Takashi Sakamotof656edd2017-03-31 22:06:11 +090020#include <linux/sched/signal.h>
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +090021
22#include <sound/core.h>
Takashi Sakamoto53eb0862017-03-31 22:06:02 +090023#include <sound/info.h>
Takashi Sakamoto19174292017-03-31 22:06:03 +090024#include <sound/rawmidi.h>
Takashi Sakamoto4b316432017-03-31 22:06:10 +090025#include <sound/pcm.h>
26#include <sound/pcm_params.h>
Takashi Sakamotof656edd2017-03-31 22:06:11 +090027#include <sound/hwdep.h>
28#include <sound/firewire.h>
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +090029
Takashi Sakamoto324540c2017-03-31 22:06:00 +090030#include "../lib.h"
Takashi Sakamoto6fb7db92017-03-31 22:06:08 +090031#include "../amdtp-stream.h"
Takashi Sakamoto75d6d892017-03-31 22:06:09 +090032#include "../iso-resources.h"
Takashi Sakamoto324540c2017-03-31 22:06:00 +090033
Takashi Sakamotoed90f912017-03-31 22:06:01 +090034#define SND_FF_STREAM_MODES 3
35
Takashi Sakamoto19174292017-03-31 22:06:03 +090036#define SND_FF_MAXIMIM_MIDI_QUADS 9
37#define SND_FF_IN_MIDI_PORTS 2
38#define SND_FF_OUT_MIDI_PORTS 2
39
Takashi Sakamoto53eb0862017-03-31 22:06:02 +090040struct snd_ff_protocol;
Takashi Sakamotoed90f912017-03-31 22:06:01 +090041struct snd_ff_spec {
42 const char *const name;
43
44 const unsigned int pcm_capture_channels[SND_FF_STREAM_MODES];
45 const unsigned int pcm_playback_channels[SND_FF_STREAM_MODES];
46
47 unsigned int midi_in_ports;
48 unsigned int midi_out_ports;
Takashi Sakamoto53eb0862017-03-31 22:06:02 +090049
Takashi Sakamoto782fbec2017-08-22 22:58:15 +090050 const struct snd_ff_protocol *protocol;
Takashi Sakamotoed90f912017-03-31 22:06:01 +090051};
52
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +090053struct snd_ff {
54 struct snd_card *card;
55 struct fw_unit *unit;
56 struct mutex mutex;
Takashi Sakamotoff2c2932017-03-31 22:06:04 +090057 spinlock_t lock;
Takashi Sakamoto324540c2017-03-31 22:06:00 +090058
59 bool registered;
60 struct delayed_work dwork;
Takashi Sakamotoed90f912017-03-31 22:06:01 +090061
62 const struct snd_ff_spec *spec;
Takashi Sakamoto19174292017-03-31 22:06:03 +090063
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;
67
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];
Takashi Sakamoto75d6d892017-03-31 22:06:09 +090077
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;
Takashi Sakamotof656edd2017-03-31 22:06:11 +090083
84 int dev_lock_count;
85 bool dev_lock_changed;
86 wait_queue_head_t hwdep_wait;
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +090087};
Takashi Sakamoto53eb0862017-03-31 22:06:02 +090088
89enum 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. */
96};
97
98struct 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);
104
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);
109
110 u64 midi_high_addr_reg;
111 u64 midi_rx_port_0_reg;
112 u64 midi_rx_port_1_reg;
113};
114
Takashi Sakamoto782fbec2017-08-22 22:58:15 +0900115extern const struct snd_ff_protocol snd_ff_protocol_ff400;
Takashi Sakamoto76fdb3a92017-03-31 22:06:12 +0900116
Takashi Sakamoto19174292017-03-31 22:06:03 +0900117int snd_ff_transaction_register(struct snd_ff *ff);
118int snd_ff_transaction_reregister(struct snd_ff *ff);
119void snd_ff_transaction_unregister(struct snd_ff *ff);
120
Takashi Sakamoto6fb7db92017-03-31 22:06:08 +0900121int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
122 unsigned int pcm_channels);
123int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
124 struct snd_pcm_runtime *runtime);
125int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
126 enum amdtp_stream_direction dir);
127
Takashi Sakamoto75d6d892017-03-31 22:06:09 +0900128int snd_ff_stream_init_duplex(struct snd_ff *ff);
129void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
130int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
131void snd_ff_stream_stop_duplex(struct snd_ff *ff);
132void snd_ff_stream_update_duplex(struct snd_ff *ff);
133
Takashi Sakamotof656edd2017-03-31 22:06:11 +0900134void snd_ff_stream_lock_changed(struct snd_ff *ff);
135int snd_ff_stream_lock_try(struct snd_ff *ff);
136void snd_ff_stream_lock_release(struct snd_ff *ff);
137
Takashi Sakamotod3fc7aa2017-03-31 22:06:05 +0900138void snd_ff_proc_init(struct snd_ff *ff);
139
Takashi Sakamotoff2c2932017-03-31 22:06:04 +0900140int snd_ff_create_midi_devices(struct snd_ff *ff);
141
Takashi Sakamoto4b316432017-03-31 22:06:10 +0900142int snd_ff_create_pcm_devices(struct snd_ff *ff);
143
Takashi Sakamotof656edd2017-03-31 22:06:11 +0900144int snd_ff_create_hwdep_devices(struct snd_ff *ff);
145
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +0900146#endif