blob: 4d079d66cf7718e3f6cca2c3efd9eb571c34f754 [file] [log] [blame]
Takashi Sakamoto6c3cef42017-03-22 21:30:11 +09001/*
2 * motu.h - a part of driver for MOTU FireWire series
3 *
4 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#ifndef SOUND_FIREWIRE_MOTU_H_INCLUDED
10#define SOUND_FIREWIRE_MOTU_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
20#include <sound/control.h>
21#include <sound/core.h>
Takashi Sakamoto4641c932017-03-22 21:30:18 +090022#include <sound/pcm.h>
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +090023#include <sound/info.h>
Takashi Sakamoto6c3cef42017-03-22 21:30:11 +090024
Takashi Sakamoto8865a312017-03-22 21:30:12 +090025#include "../lib.h"
Takashi Sakamoto4641c932017-03-22 21:30:18 +090026#include "../amdtp-stream.h"
Takashi Sakamoto9b2bb4f2017-03-22 21:30:20 +090027#include "../iso-resources.h"
Takashi Sakamoto8865a312017-03-22 21:30:12 +090028
Takashi Sakamoto59f64822017-03-22 21:30:14 +090029struct snd_motu_packet_format {
Takashi Sakamoto59f64822017-03-22 21:30:14 +090030 unsigned char pcm_byte_offset;
31
32 unsigned char msg_chunks;
33 unsigned char fixed_part_pcm_chunks[3];
34 unsigned char differed_part_pcm_chunks[3];
35};
36
Takashi Sakamoto6c3cef42017-03-22 21:30:11 +090037struct snd_motu {
38 struct snd_card *card;
39 struct fw_unit *unit;
40 struct mutex mutex;
Takashi Sakamoto8865a312017-03-22 21:30:12 +090041
42 bool registered;
43 struct delayed_work dwork;
Takashi Sakamoto5e03c332017-03-22 21:30:13 +090044
45 /* Model dependent information. */
46 const struct snd_motu_spec *spec;
Takashi Sakamoto59f64822017-03-22 21:30:14 +090047
48 /* For packet streaming */
49 struct snd_motu_packet_format tx_packet_formats;
50 struct snd_motu_packet_format rx_packet_formats;
Takashi Sakamoto4641c932017-03-22 21:30:18 +090051 struct amdtp_stream tx_stream;
52 struct amdtp_stream rx_stream;
Takashi Sakamoto9b2bb4f2017-03-22 21:30:20 +090053 struct fw_iso_resources tx_resources;
54 struct fw_iso_resources rx_resources;
55 unsigned int capture_substreams;
56 unsigned int playback_substreams;
Takashi Sakamoto2e767012017-03-22 21:30:19 +090057
58 /* For notification. */
59 struct fw_address_handler async_handler;
60 u32 msg;
Takashi Sakamoto5e03c332017-03-22 21:30:13 +090061};
62
63enum snd_motu_spec_flags {
64 SND_MOTU_SPEC_SUPPORT_CLOCK_X2 = 0x0001,
65 SND_MOTU_SPEC_SUPPORT_CLOCK_X4 = 0x0002,
66 SND_MOTU_SPEC_TX_MICINST_CHUNK = 0x0004,
67 SND_MOTU_SPEC_TX_RETURN_CHUNK = 0x0008,
68 SND_MOTU_SPEC_TX_REVERB_CHUNK = 0x0010,
69 SND_MOTU_SPEC_TX_AESEBU_CHUNK = 0x0020,
70 SND_MOTU_SPEC_HAS_OPT_IFACE_A = 0x0040,
71 SND_MOTU_SPEC_HAS_OPT_IFACE_B = 0x0080,
72 SND_MOTU_SPEC_HAS_MIDI = 0x0100,
73};
74
Takashi Sakamoto59f64822017-03-22 21:30:14 +090075#define SND_MOTU_CLOCK_RATE_COUNT 6
76extern const unsigned int snd_motu_clock_rates[SND_MOTU_CLOCK_RATE_COUNT];
77
78enum snd_motu_clock_source {
79 SND_MOTU_CLOCK_SOURCE_INTERNAL,
80 SND_MOTU_CLOCK_SOURCE_ADAT_ON_DSUB,
81 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT,
82 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_A,
83 SND_MOTU_CLOCK_SOURCE_ADAT_ON_OPT_B,
84 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT,
85 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_A,
86 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_OPT_B,
87 SND_MOTU_CLOCK_SOURCE_SPDIF_ON_COAX,
88 SND_MOTU_CLOCK_SOURCE_AESEBU_ON_XLR,
89 SND_MOTU_CLOCK_SOURCE_WORD_ON_BNC,
90 SND_MOTU_CLOCK_SOURCE_UNKNOWN,
91};
92
93struct snd_motu_protocol {
94 int (*get_clock_rate)(struct snd_motu *motu, unsigned int *rate);
95 int (*set_clock_rate)(struct snd_motu *motu, unsigned int rate);
96 int (*get_clock_source)(struct snd_motu *motu,
97 enum snd_motu_clock_source *source);
98 int (*switch_fetching_mode)(struct snd_motu *motu, bool enable);
99 int (*cache_packet_formats)(struct snd_motu *motu);
100};
101
Takashi Sakamoto5e03c332017-03-22 21:30:13 +0900102struct snd_motu_spec {
103 const char *const name;
104 enum snd_motu_spec_flags flags;
105
106 unsigned char analog_in_ports;
107 unsigned char analog_out_ports;
Takashi Sakamoto59f64822017-03-22 21:30:14 +0900108
109 const struct snd_motu_protocol *const protocol;
Takashi Sakamoto6c3cef42017-03-22 21:30:11 +0900110};
111
Takashi Sakamoto4641c932017-03-22 21:30:18 +0900112int amdtp_motu_init(struct amdtp_stream *s, struct fw_unit *unit,
113 enum amdtp_stream_direction dir,
114 const struct snd_motu_protocol *const protocol);
115int amdtp_motu_set_parameters(struct amdtp_stream *s, unsigned int rate,
116 struct snd_motu_packet_format *formats);
117int amdtp_motu_add_pcm_hw_constraints(struct amdtp_stream *s,
118 struct snd_pcm_runtime *runtime);
Takashi Sakamoto2e767012017-03-22 21:30:19 +0900119
120int snd_motu_transaction_read(struct snd_motu *motu, u32 offset, __be32 *reg,
121 size_t size);
122int snd_motu_transaction_write(struct snd_motu *motu, u32 offset, __be32 *reg,
123 size_t size);
124int snd_motu_transaction_register(struct snd_motu *motu);
125int snd_motu_transaction_reregister(struct snd_motu *motu);
126void snd_motu_transaction_unregister(struct snd_motu *motu);
Takashi Sakamoto9b2bb4f2017-03-22 21:30:20 +0900127
128int snd_motu_stream_init_duplex(struct snd_motu *motu);
129void snd_motu_stream_destroy_duplex(struct snd_motu *motu);
130int snd_motu_stream_start_duplex(struct snd_motu *motu, unsigned int rate);
131void snd_motu_stream_stop_duplex(struct snd_motu *motu);
Takashi Sakamoto4638ec6e2017-03-22 21:30:21 +0900132
133void snd_motu_proc_init(struct snd_motu *motu);
Takashi Sakamoto6c3cef42017-03-22 21:30:11 +0900134#endif