ALSA: firewire-motu: register the size of PCM period to AMDTP domain
[linux-2.6-block.git] / sound / firewire / motu / motu.h
CommitLineData
da607e19 1/* SPDX-License-Identifier: GPL-2.0-only */
6c3cef48
TS
2/*
3 * motu.h - a part of driver for MOTU FireWire series
4 *
5 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6c3cef48
TS
6 */
7
8#ifndef SOUND_FIREWIRE_MOTU_H_INCLUDED
9#define SOUND_FIREWIRE_MOTU_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>
71c37977
TS
18#include <linux/compat.h>
19#include <linux/sched/signal.h>
6c3cef48
TS
20
21#include <sound/control.h>
22#include <sound/core.h>
4641c939 23#include <sound/pcm.h>
4638ec6e 24#include <sound/info.h>
9e796e7d 25#include <sound/rawmidi.h>
71c37977
TS
26#include <sound/firewire.h>
27#include <sound/hwdep.h>
6c3cef48 28
8865a31e 29#include "../lib.h"
4641c939 30#include "../amdtp-stream.h"
9b2bb4f2 31#include "../iso-resources.h"
8865a31e 32
59f6482c 33struct snd_motu_packet_format {
9e796e7d
TS
34 unsigned char midi_flag_offset;
35 unsigned char midi_byte_offset;
59f6482c
TS
36 unsigned char pcm_byte_offset;
37
38 unsigned char msg_chunks;
39 unsigned char fixed_part_pcm_chunks[3];
40 unsigned char differed_part_pcm_chunks[3];
41};
42
6c3cef48
TS
43struct snd_motu {
44 struct snd_card *card;
45 struct fw_unit *unit;
46 struct mutex mutex;
9e796e7d 47 spinlock_t lock;
8865a31e
TS
48
49 bool registered;
50 struct delayed_work dwork;
5e03c33e
TS
51
52 /* Model dependent information. */
53 const struct snd_motu_spec *spec;
59f6482c
TS
54
55 /* For packet streaming */
56 struct snd_motu_packet_format tx_packet_formats;
57 struct snd_motu_packet_format rx_packet_formats;
4641c939
TS
58 struct amdtp_stream tx_stream;
59 struct amdtp_stream rx_stream;
9b2bb4f2
TS
60 struct fw_iso_resources tx_resources;
61 struct fw_iso_resources rx_resources;
18f26034 62 unsigned int substreams_counter;
2e76701b
TS
63
64 /* For notification. */
65 struct fw_address_handler async_handler;
66 u32 msg;
71c37977
TS
67
68 /* For uapi */
69 int dev_lock_count;
70 bool dev_lock_changed;
71 wait_queue_head_t hwdep_wait;
ccc6c1b0
TS
72
73 struct amdtp_domain domain;
5e03c33e
TS
74};
75
76enum snd_motu_spec_flags {
77 SND_MOTU_SPEC_SUPPORT_CLOCK_X2 = 0x0001,
78 SND_MOTU_SPEC_SUPPORT_CLOCK_X4 = 0x0002,
79 SND_MOTU_SPEC_TX_MICINST_CHUNK = 0x0004,
80 SND_MOTU_SPEC_TX_RETURN_CHUNK = 0x0008,
81 SND_MOTU_SPEC_TX_REVERB_CHUNK = 0x0010,
06ac0b6f 82 SND_MOTU_SPEC_HAS_AESEBU_IFACE = 0x0020,
5e03c33e
TS
83 SND_MOTU_SPEC_HAS_OPT_IFACE_A = 0x0040,
84 SND_MOTU_SPEC_HAS_OPT_IFACE_B = 0x0080,
8b460c76
TS
85 SND_MOTU_SPEC_RX_MIDI_2ND_Q = 0x0100,
86 SND_MOTU_SPEC_RX_MIDI_3RD_Q = 0x0200,
87 SND_MOTU_SPEC_TX_MIDI_2ND_Q = 0x0400,
88 SND_MOTU_SPEC_TX_MIDI_3RD_Q = 0x0800,
81720c6d 89 SND_MOTU_SPEC_RX_SEPARETED_MAIN = 0x1000,
5e03c33e
TS
90};
91
59f6482c
TS
92#define SND_MOTU_CLOCK_RATE_COUNT 6
93extern const unsigned int snd_motu_clock_rates[SND_MOTU_CLOCK_RATE_COUNT];
94
95enum snd_motu_clock_source {
96 SND_MOTU_CLOCK_SOURCE_INTERNAL,
97 SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB,
98 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT,
99 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A,
100 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B,
101 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT,
102 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A,
103 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B,
104 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX,
105 SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR,
106 SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC,
107 SND_MOTU_CLOCK_SOURCE_UNKNOWN,
108};
109
110struct snd_motu_protocol {
111 int (*get_clock_rate)(struct snd_motu *motu, unsigned int *rate);
112 int (*set_clock_rate)(struct snd_motu *motu, unsigned int rate);
113 int (*get_clock_source)(struct snd_motu *motu,
114 enum snd_motu_clock_source *source);
115 int (*switch_fetching_mode)(struct snd_motu *motu, bool enable);
116 int (*cache_packet_formats)(struct snd_motu *motu);
117};
118
5e03c33e
TS
119struct snd_motu_spec {
120 const char *const name;
121 enum snd_motu_spec_flags flags;
122
123 unsigned char analog_in_ports;
124 unsigned char analog_out_ports;
59f6482c
TS
125
126 const struct snd_motu_protocol *const protocol;
6c3cef48
TS
127};
128
949613e3 129extern const struct snd_motu_protocol snd_motu_protocol_v2;
5992e300 130extern const struct snd_motu_protocol snd_motu_protocol_v3;
949613e3 131
6c5e1ac0 132extern const struct snd_motu_spec snd_motu_spec_traveler;
35033d8c 133extern const struct snd_motu_spec snd_motu_spec_8pre;
6c5e1ac0 134
4641c939
TS
135int amdtp_motu_init(struct amdtp_stream *s, struct fw_unit *unit,
136 enum amdtp_stream_direction dir,
137 const struct snd_motu_protocol *const protocol);
138int amdtp_motu_set_parameters(struct amdtp_stream *s, unsigned int rate,
9e796e7d 139 unsigned int midi_ports,
4641c939
TS
140 struct snd_motu_packet_format *formats);
141int amdtp_motu_add_pcm_hw_constraints(struct amdtp_stream *s,
142 struct snd_pcm_runtime *runtime);
9e796e7d
TS
143void amdtp_motu_midi_trigger(struct amdtp_stream *s, unsigned int port,
144 struct snd_rawmidi_substream *midi);
2e76701b
TS
145
146int snd_motu_transaction_read(struct snd_motu *motu, u32 offset, __be32 *reg,
147 size_t size);
148int snd_motu_transaction_write(struct snd_motu *motu, u32 offset, __be32 *reg,
149 size_t size);
150int snd_motu_transaction_register(struct snd_motu *motu);
151int snd_motu_transaction_reregister(struct snd_motu *motu);
152void snd_motu_transaction_unregister(struct snd_motu *motu);
9b2bb4f2
TS
153
154int snd_motu_stream_init_duplex(struct snd_motu *motu);
155void snd_motu_stream_destroy_duplex(struct snd_motu *motu);
8b460c76 156int snd_motu_stream_cache_packet_formats(struct snd_motu *motu);
0d39cd0e
TS
157int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
158 unsigned int frames_per_period);
8edc56ec 159int snd_motu_stream_start_duplex(struct snd_motu *motu);
9b2bb4f2 160void snd_motu_stream_stop_duplex(struct snd_motu *motu);
71c37977
TS
161int snd_motu_stream_lock_try(struct snd_motu *motu);
162void snd_motu_stream_lock_release(struct snd_motu *motu);
4638ec6e
TS
163
164void snd_motu_proc_init(struct snd_motu *motu);
dd49b2d1
TS
165
166int snd_motu_create_pcm_devices(struct snd_motu *motu);
9e796e7d
TS
167
168int snd_motu_create_midi_devices(struct snd_motu *motu);
71c37977
TS
169
170int snd_motu_create_hwdep_device(struct snd_motu *motu);
6c3cef48 171#endif