blob: 7e42f5778a8a3767ef75318947df8ee52da2f070 [file] [log] [blame]
Thomas Gleixnerda607e12019-05-29 16:57:59 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +09002/*
3 * ff.h - a part of driver for RME Fireface series
4 *
5 * Copyright (c) 2015-2017 Takashi Sakamoto
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +09006 */
7
8#ifndef SOUND_FIREFACE_H_INCLUDED
9#define SOUND_FIREFACE_H_INCLUDED
10
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>
Takashi Sakamotof656edd2017-03-31 22:06:11 +090019#include <linux/sched/signal.h>
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +090020
21#include <sound/core.h>
Takashi Sakamoto53eb0862017-03-31 22:06:02 +090022#include <sound/info.h>
Takashi Sakamoto19174292017-03-31 22:06:03 +090023#include <sound/rawmidi.h>
Takashi Sakamoto4b316432017-03-31 22:06:10 +090024#include <sound/pcm.h>
25#include <sound/pcm_params.h>
Takashi Sakamotof656edd2017-03-31 22:06:11 +090026#include <sound/hwdep.h>
27#include <sound/firewire.h>
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +090028
Takashi Sakamoto324540c2017-03-31 22:06:00 +090029#include "../lib.h"
Takashi Sakamoto6fb7db92017-03-31 22:06:08 +090030#include "../amdtp-stream.h"
Takashi Sakamoto75d6d892017-03-31 22:06:09 +090031#include "../iso-resources.h"
Takashi Sakamoto324540c2017-03-31 22:06:00 +090032
Takashi Sakamoto19174292017-03-31 22:06:03 +090033#define SND_FF_MAXIMIM_MIDI_QUADS 9
34#define SND_FF_IN_MIDI_PORTS 2
35#define SND_FF_OUT_MIDI_PORTS 2
36
Takashi Sakamotoc52f2322020-05-10 16:42:58 +090037enum snd_ff_unit_version {
38 SND_FF_UNIT_VERSION_FF800 = 0x000001,
39 SND_FF_UNIT_VERSION_FF400 = 0x000002,
Takashi Sakamoto1f65e662020-05-10 16:43:01 +090040 SND_FF_UNIT_VERSION_UFX = 0x000003,
Takashi Sakamotoc52f2322020-05-10 16:42:58 +090041 SND_FF_UNIT_VERSION_UCX = 0x000004,
Takashi Sakamoto062bb452020-05-10 16:43:00 +090042 SND_FF_UNIT_VERSION_802 = 0x000005,
Takashi Sakamotoc52f2322020-05-10 16:42:58 +090043};
44
Takashi Sakamoto76ea4682018-12-16 17:32:30 +090045enum snd_ff_stream_mode {
46 SND_FF_STREAM_MODE_LOW = 0,
47 SND_FF_STREAM_MODE_MID,
48 SND_FF_STREAM_MODE_HIGH,
49 SND_FF_STREAM_MODE_COUNT,
50};
51
Takashi Sakamoto53eb0862017-03-31 22:06:02 +090052struct snd_ff_protocol;
Takashi Sakamotoed90f912017-03-31 22:06:01 +090053struct snd_ff_spec {
Takashi Sakamoto76ea4682018-12-16 17:32:30 +090054 const unsigned int pcm_capture_channels[SND_FF_STREAM_MODE_COUNT];
55 const unsigned int pcm_playback_channels[SND_FF_STREAM_MODE_COUNT];
Takashi Sakamotoed90f912017-03-31 22:06:01 +090056
57 unsigned int midi_in_ports;
58 unsigned int midi_out_ports;
Takashi Sakamoto53eb0862017-03-31 22:06:02 +090059
Takashi Sakamoto782fbec2017-08-22 22:58:15 +090060 const struct snd_ff_protocol *protocol;
Takashi Sakamoto6d1ef1b2018-12-16 17:32:33 +090061 u64 midi_high_addr;
Takashi Sakamoto90089672019-01-22 22:17:01 +090062 u8 midi_addr_range;
Takashi Sakamoto481e09a2019-01-22 22:17:03 +090063 u64 midi_rx_addrs[SND_FF_OUT_MIDI_PORTS];
Takashi Sakamotoed90f912017-03-31 22:06:01 +090064};
65
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +090066struct snd_ff {
67 struct snd_card *card;
68 struct fw_unit *unit;
69 struct mutex mutex;
Takashi Sakamotoff2c2932017-03-31 22:06:04 +090070 spinlock_t lock;
Takashi Sakamoto324540c2017-03-31 22:06:00 +090071
Takashi Sakamoto782222b2020-05-10 16:42:59 +090072 enum snd_ff_unit_version unit_version;
Takashi Sakamotoed90f912017-03-31 22:06:01 +090073 const struct snd_ff_spec *spec;
Takashi Sakamoto19174292017-03-31 22:06:03 +090074
75 /* To handle MIDI tx. */
76 struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
77 struct fw_address_handler async_handler;
78
79 /* TO handle MIDI rx. */
80 struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
Takashi Sakamotof0f9f492019-01-22 22:17:05 +090081 bool on_sysex[SND_FF_OUT_MIDI_PORTS];
Takashi Sakamoto19174292017-03-31 22:06:03 +090082 __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
83 struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
84 struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
85 ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
86 bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
87 unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
Takashi Sakamoto75d6d892017-03-31 22:06:09 +090088
89 unsigned int substreams_counter;
90 struct amdtp_stream tx_stream;
91 struct amdtp_stream rx_stream;
92 struct fw_iso_resources tx_resources;
93 struct fw_iso_resources rx_resources;
Takashi Sakamotof656edd2017-03-31 22:06:11 +090094
95 int dev_lock_count;
96 bool dev_lock_changed;
97 wait_queue_head_t hwdep_wait;
Takashi Sakamotoc9a9ce82019-08-04 15:21:37 +090098
99 struct amdtp_domain domain;
Takashi Sakamotoc31909f2023-01-12 21:09:53 +0900100
101 void *msg_parser;
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +0900102};
Takashi Sakamoto53eb0862017-03-31 22:06:02 +0900103
104enum snd_ff_clock_src {
105 SND_FF_CLOCK_SRC_INTERNAL,
106 SND_FF_CLOCK_SRC_SPDIF,
Takashi Sakamoto5bfb8412018-12-11 19:17:31 +0900107 SND_FF_CLOCK_SRC_ADAT1,
108 SND_FF_CLOCK_SRC_ADAT2,
Takashi Sakamoto53eb0862017-03-31 22:06:02 +0900109 SND_FF_CLOCK_SRC_WORD,
110 SND_FF_CLOCK_SRC_LTC,
Takashi Sakamoto5bfb8412018-12-11 19:17:31 +0900111 /* TODO: perhaps TCO exists. */
Takashi Sakamoto53eb0862017-03-31 22:06:02 +0900112};
113
114struct snd_ff_protocol {
Takashi Sakamotoc31909f2023-01-12 21:09:53 +0900115 size_t msg_parser_size;
116 bool (*has_msg)(struct snd_ff *ff);
117 long (*copy_msg_to_user)(struct snd_ff *ff, char __user *buf, long count);
Takashi Sakamoto50c597c2023-01-12 21:09:49 +0900118 void (*handle_msg)(struct snd_ff *ff, unsigned int offset, const __le32 *buf,
Takashi Sakamoto4bdcb8d2023-01-12 21:09:50 +0900119 size_t length, u32 tstamp);
Takashi Sakamoto82b62972019-01-22 22:17:04 +0900120 int (*fill_midi_msg)(struct snd_ff *ff,
121 struct snd_rawmidi_substream *substream,
122 unsigned int port);
Takashi Sakamotob1d0cb02019-01-20 17:25:50 +0900123 int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
124 enum snd_ff_clock_src *src);
Takashi Sakamotoae3053c22019-01-20 17:25:49 +0900125 int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
Takashi Sakamoto47b87c82019-06-02 16:12:52 +0900126 int (*allocate_resources)(struct snd_ff *ff, unsigned int rate);
Takashi Sakamoto53eb0862017-03-31 22:06:02 +0900127 int (*begin_session)(struct snd_ff *ff, unsigned int rate);
128 void (*finish_session)(struct snd_ff *ff);
Takashi Sakamotoe9e29cf2019-01-20 17:25:48 +0900129 void (*dump_status)(struct snd_ff *ff, struct snd_info_buffer *buffer);
Takashi Sakamoto53eb0862017-03-31 22:06:02 +0900130};
131
Takashi Sakamotoa91f6762018-12-11 19:17:35 +0900132extern const struct snd_ff_protocol snd_ff_protocol_ff800;
Takashi Sakamoto782fbec2017-08-22 22:58:15 +0900133extern const struct snd_ff_protocol snd_ff_protocol_ff400;
Takashi Sakamotofd1cc9d2019-01-20 17:25:53 +0900134extern const struct snd_ff_protocol snd_ff_protocol_latter;
Takashi Sakamoto76fdb3a92017-03-31 22:06:12 +0900135
Takashi Sakamoto19174292017-03-31 22:06:03 +0900136int snd_ff_transaction_register(struct snd_ff *ff);
137int snd_ff_transaction_reregister(struct snd_ff *ff);
138void snd_ff_transaction_unregister(struct snd_ff *ff);
139
Takashi Sakamoto6fb7db92017-03-31 22:06:08 +0900140int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
141 unsigned int pcm_channels);
142int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
143 struct snd_pcm_runtime *runtime);
144int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
145 enum amdtp_stream_direction dir);
146
Takashi Sakamoto76ea4682018-12-16 17:32:30 +0900147int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
148 enum snd_ff_stream_mode *mode);
Takashi Sakamoto75d6d892017-03-31 22:06:09 +0900149int snd_ff_stream_init_duplex(struct snd_ff *ff);
150void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
Takashi Sakamoto9d9ff582019-10-07 20:05:24 +0900151int snd_ff_stream_reserve_duplex(struct snd_ff *ff, unsigned int rate,
Takashi Sakamoto4de3eb02019-10-18 00:54:21 +0900152 unsigned int frames_per_period,
153 unsigned int frames_per_buffer);
Takashi Sakamoto75d6d892017-03-31 22:06:09 +0900154int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
155void snd_ff_stream_stop_duplex(struct snd_ff *ff);
156void snd_ff_stream_update_duplex(struct snd_ff *ff);
157
Takashi Sakamotof656edd2017-03-31 22:06:11 +0900158void snd_ff_stream_lock_changed(struct snd_ff *ff);
159int snd_ff_stream_lock_try(struct snd_ff *ff);
160void snd_ff_stream_lock_release(struct snd_ff *ff);
161
Takashi Sakamotod3fc7aa2017-03-31 22:06:05 +0900162void snd_ff_proc_init(struct snd_ff *ff);
Takashi Sakamoto4c4871a2019-01-20 17:25:52 +0900163const char *snd_ff_proc_get_clk_label(enum snd_ff_clock_src src);
Takashi Sakamotod3fc7aa2017-03-31 22:06:05 +0900164
Takashi Sakamotoff2c2932017-03-31 22:06:04 +0900165int snd_ff_create_midi_devices(struct snd_ff *ff);
166
Takashi Sakamoto4b316432017-03-31 22:06:10 +0900167int snd_ff_create_pcm_devices(struct snd_ff *ff);
168
Takashi Sakamotof656edd2017-03-31 22:06:11 +0900169int snd_ff_create_hwdep_devices(struct snd_ff *ff);
170
Takashi Sakamoto17c4e5e2017-03-31 22:05:59 +0900171#endif