ALSA: fireface: register the size of PCM period to AMDTP domain
[linux-2.6-block.git] / sound / firewire / fireface / ff.h
CommitLineData
da607e19 1/* SPDX-License-Identifier: GPL-2.0-only */
17c4e5ea
TS
2/*
3 * ff.h - a part of driver for RME Fireface series
4 *
5 * Copyright (c) 2015-2017 Takashi Sakamoto
17c4e5ea
TS
6 */
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>
f656edd5 19#include <linux/sched/signal.h>
17c4e5ea
TS
20
21#include <sound/core.h>
53eb0867 22#include <sound/info.h>
19174295 23#include <sound/rawmidi.h>
4b316436
TS
24#include <sound/pcm.h>
25#include <sound/pcm_params.h>
f656edd5
TS
26#include <sound/hwdep.h>
27#include <sound/firewire.h>
17c4e5ea 28
324540c4 29#include "../lib.h"
6fb7db90 30#include "../amdtp-stream.h"
75d6d898 31#include "../iso-resources.h"
324540c4 32
19174295
TS
33#define SND_FF_MAXIMIM_MIDI_QUADS 9
34#define SND_FF_IN_MIDI_PORTS 2
35#define SND_FF_OUT_MIDI_PORTS 2
36
76ea4688
TS
37enum snd_ff_stream_mode {
38 SND_FF_STREAM_MODE_LOW = 0,
39 SND_FF_STREAM_MODE_MID,
40 SND_FF_STREAM_MODE_HIGH,
41 SND_FF_STREAM_MODE_COUNT,
42};
43
53eb0867 44struct snd_ff_protocol;
ed90f91a
TS
45struct snd_ff_spec {
46 const char *const name;
47
76ea4688
TS
48 const unsigned int pcm_capture_channels[SND_FF_STREAM_MODE_COUNT];
49 const unsigned int pcm_playback_channels[SND_FF_STREAM_MODE_COUNT];
ed90f91a
TS
50
51 unsigned int midi_in_ports;
52 unsigned int midi_out_ports;
53eb0867 53
782fbec7 54 const struct snd_ff_protocol *protocol;
6d1ef1bb 55 u64 midi_high_addr;
90089677 56 u8 midi_addr_range;
481e09ac 57 u64 midi_rx_addrs[SND_FF_OUT_MIDI_PORTS];
ed90f91a
TS
58};
59
17c4e5ea
TS
60struct snd_ff {
61 struct snd_card *card;
62 struct fw_unit *unit;
63 struct mutex mutex;
ff2c293e 64 spinlock_t lock;
324540c4
TS
65
66 bool registered;
67 struct delayed_work dwork;
ed90f91a
TS
68
69 const struct snd_ff_spec *spec;
19174295
TS
70
71 /* To handle MIDI tx. */
72 struct snd_rawmidi_substream *tx_midi_substreams[SND_FF_IN_MIDI_PORTS];
73 struct fw_address_handler async_handler;
74
75 /* TO handle MIDI rx. */
76 struct snd_rawmidi_substream *rx_midi_substreams[SND_FF_OUT_MIDI_PORTS];
f0f9f497 77 bool on_sysex[SND_FF_OUT_MIDI_PORTS];
19174295
TS
78 __le32 msg_buf[SND_FF_OUT_MIDI_PORTS][SND_FF_MAXIMIM_MIDI_QUADS];
79 struct work_struct rx_midi_work[SND_FF_OUT_MIDI_PORTS];
80 struct fw_transaction transactions[SND_FF_OUT_MIDI_PORTS];
81 ktime_t next_ktime[SND_FF_OUT_MIDI_PORTS];
82 bool rx_midi_error[SND_FF_OUT_MIDI_PORTS];
83 unsigned int rx_bytes[SND_FF_OUT_MIDI_PORTS];
75d6d898
TS
84
85 unsigned int substreams_counter;
86 struct amdtp_stream tx_stream;
87 struct amdtp_stream rx_stream;
88 struct fw_iso_resources tx_resources;
89 struct fw_iso_resources rx_resources;
f656edd5
TS
90
91 int dev_lock_count;
92 bool dev_lock_changed;
93 wait_queue_head_t hwdep_wait;
c9a9ce89
TS
94
95 struct amdtp_domain domain;
17c4e5ea 96};
53eb0867
TS
97
98enum snd_ff_clock_src {
99 SND_FF_CLOCK_SRC_INTERNAL,
100 SND_FF_CLOCK_SRC_SPDIF,
5bfb841e
TS
101 SND_FF_CLOCK_SRC_ADAT1,
102 SND_FF_CLOCK_SRC_ADAT2,
53eb0867
TS
103 SND_FF_CLOCK_SRC_WORD,
104 SND_FF_CLOCK_SRC_LTC,
5bfb841e 105 /* TODO: perhaps TCO exists. */
53eb0867
TS
106};
107
108struct snd_ff_protocol {
6c644e4e
TS
109 void (*handle_midi_msg)(struct snd_ff *ff, unsigned int offset,
110 __le32 *buf, size_t length);
82b6297b
TS
111 int (*fill_midi_msg)(struct snd_ff *ff,
112 struct snd_rawmidi_substream *substream,
113 unsigned int port);
b1d0cb0a
TS
114 int (*get_clock)(struct snd_ff *ff, unsigned int *rate,
115 enum snd_ff_clock_src *src);
ae3053c2 116 int (*switch_fetching_mode)(struct snd_ff *ff, bool enable);
47b87c8e 117 int (*allocate_resources)(struct snd_ff *ff, unsigned int rate);
53eb0867
TS
118 int (*begin_session)(struct snd_ff *ff, unsigned int rate);
119 void (*finish_session)(struct snd_ff *ff);
e9e29cf8 120 void (*dump_status)(struct snd_ff *ff, struct snd_info_buffer *buffer);
53eb0867
TS
121};
122
a91f6760 123extern const struct snd_ff_protocol snd_ff_protocol_ff800;
782fbec7 124extern const struct snd_ff_protocol snd_ff_protocol_ff400;
fd1cc9de 125extern const struct snd_ff_protocol snd_ff_protocol_latter;
76fdb3a9 126
19174295
TS
127int snd_ff_transaction_register(struct snd_ff *ff);
128int snd_ff_transaction_reregister(struct snd_ff *ff);
129void snd_ff_transaction_unregister(struct snd_ff *ff);
130
6fb7db90
TS
131int amdtp_ff_set_parameters(struct amdtp_stream *s, unsigned int rate,
132 unsigned int pcm_channels);
133int amdtp_ff_add_pcm_hw_constraints(struct amdtp_stream *s,
134 struct snd_pcm_runtime *runtime);
135int amdtp_ff_init(struct amdtp_stream *s, struct fw_unit *unit,
136 enum amdtp_stream_direction dir);
137
76ea4688
TS
138int snd_ff_stream_get_multiplier_mode(enum cip_sfc sfc,
139 enum snd_ff_stream_mode *mode);
75d6d898
TS
140int snd_ff_stream_init_duplex(struct snd_ff *ff);
141void snd_ff_stream_destroy_duplex(struct snd_ff *ff);
9d9ff58c
TS
142int snd_ff_stream_reserve_duplex(struct snd_ff *ff, unsigned int rate,
143 unsigned int frames_per_period);
75d6d898
TS
144int snd_ff_stream_start_duplex(struct snd_ff *ff, unsigned int rate);
145void snd_ff_stream_stop_duplex(struct snd_ff *ff);
146void snd_ff_stream_update_duplex(struct snd_ff *ff);
147
f656edd5
TS
148void snd_ff_stream_lock_changed(struct snd_ff *ff);
149int snd_ff_stream_lock_try(struct snd_ff *ff);
150void snd_ff_stream_lock_release(struct snd_ff *ff);
151
d3fc7aac 152void snd_ff_proc_init(struct snd_ff *ff);
4c4871a8 153const char *snd_ff_proc_get_clk_label(enum snd_ff_clock_src src);
d3fc7aac 154
ff2c293e
TS
155int snd_ff_create_midi_devices(struct snd_ff *ff);
156
4b316436
TS
157int snd_ff_create_pcm_devices(struct snd_ff *ff);
158
f656edd5
TS
159int snd_ff_create_hwdep_devices(struct snd_ff *ff);
160
17c4e5ea 161#endif