root/branches/libffado-2.0/src/motu/motu_avdevice.h

Revision 1579, 8.9 kB (checked in by jwoithe, 15 years ago)

MOTU: add skeletal support for the mixer protocol used in Mark3 devices.
MOTU: split mixer management code and definitions into dedicated files to aid in maintenance.

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  * Copyright (C) 2005-2008 by Jonathan Woithe
4  *
5  * This file is part of FFADO
6  * FFADO = Free Firewire (pro-)audio drivers for linux
7  *
8  * FFADO is based upon FreeBoB.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 2 of the License, or
13  * (at your option) version 3 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef MOTUDEVICE_H
26 #define MOTUDEVICE_H
27
28 #include "ffadodevice.h"
29
30 #include "debugmodule/debugmodule.h"
31 #include "libavc/avc_definitions.h"
32
33 #include "libstreaming/motu/MotuReceiveStreamProcessor.h"
34 #include "libstreaming/motu/MotuTransmitStreamProcessor.h"
35
36 #include "motu_controls.h"
37
38 #define MOTU_BASE_ADDR               0xfffff0000000ULL
39
40 /* Bitmasks and values used when setting MOTU device registers */
41 #define MOTU_RATE_BASE_44100         (0<<3)
42 #define MOTU_RATE_BASE_48000         (1<<3)
43 #define MOTU_RATE_MULTIPLIER_1X      (0<<4)
44 #define MOTU_RATE_MULTIPLIER_2X      (1<<4)
45 #define MOTU_RATE_MULTIPLIER_4X      (2<<4)
46 #define MOTU_RATE_BASE_MASK          (0x00000008)
47 #define MOTU_RATE_MULTIPLIER_MASK    (0x00000030)
48
49 #define MOTU_OPTICAL_MODE_OFF        0x00
50 #define MOTU_OPTICAL_MODE_ADAT       0x01
51 #define MOTU_OPTICAL_MODE_TOSLINK    0x02
52 #define MOTU_OPTICAL_IN_MODE_MASK    (0x00000300)
53 #define MOTU_OPTICAL_OUT_MODE_MASK   (0x00000c00)
54 #define MOTU_OPTICAL_MODE_MASK       (MOTU_OPTICAL_IN_MODE_MASK|MOTU_OPTICAL_MODE_MASK)
55
56 #define MOTU_CLKSRC_MASK             0x00000007
57 #define MOTU_CLKSRC_INTERNAL         0
58 #define MOTU_CLKSRC_ADAT_OPTICAL     1
59 #define MOTU_CLKSRC_SPDIF_TOSLINK    2
60 #define MOTU_CLKSRC_SMPTE            3
61 #define MOTU_CLKSRC_WORDCLOCK        4
62 #define MOTU_CLKSRC_ADAT_9PIN        5
63 #define MOTU_CLKSRC_AES_EBU          7
64 #define MOTU_CLKSRC_NONE             0xffff
65 #define MOTU_CLKSRC_UNCHANGED        MOTU_CLKSRC_NONE
66
67 #define MOTU_METER_PEAKHOLD_MASK     0x3800
68 #define MOTU_METER_PEAKHOLD_SHIFT    11
69 #define MOTU_METER_CLIPHOLD_MASK     0x0700
70 #define MOTU_METER_CLIPHOLD_SHIFT    8
71 #define MOTU_METER_AESEBU_SRC_MASK   0x0004
72 #define MOTU_METER_AESEBU_SRC_SHIFT  2
73 #define MOTU_METER_PROG_SRC_MASK     0x0003
74 #define MOTU_METER_PROG_SRC_SHIFT    0
75
76 /* Device registers */
77 #define MOTU_REG_ISOCTRL           0x0b00
78 #define MOTU_REG_OPTICAL_CTRL      0x0b10
79 #define MOTU_REG_CLK_CTRL          0x0b14
80 #define MOTU_REG_896HD_METER_REG   0x0b1c
81 #define MOTU_REG_896HD_METER_CONF  0x0b24
82 #define MOTU_REG_ROUTE_PORT_CONF   0x0c04
83 #define MOTU_REG_INPUT_LEVEL       0x0c08
84 #define MOTU_REG_INPUT_BOOST       0x0c14
85 #define MOTU_REG_INPUT_GAIN_PAD_0  0x0c1c
86 #define MOTU_REG_CLKSRC_NAME0      0x0c60
87 #define MOTU_REG_INPUT_GAIN_PHINV0 0x0c70
88 #define MOTU_REG_INPUT_GAIN_PHINV1 0x0c74
89 #define MOTU_REG_INPUT_GAIN_PHINV2 0x0c78
90
91 /* Port Active Flags (ports declaration) */
92 #define MOTU_PA_RATE_1x          0x0001    /* 44k1 or 48k */
93 #define MOTU_PA_RATE_2x          0x0002    /* 88k2 or 96k */
94 #define MOTU_PA_RATE_4x          0x0004    /* 176k4 or 192k */
95 #define MOTU_PA_RATE_1x2x        (MOTU_PA_RATE_1x|MOTU_PA_RATE_2x)
96 #define MOTU_PA_RATE_ANY         (MOTU_PA_RATE_1x|MOTU_PA_RATE_2x|MOTU_PA_RATE_4x)
97 #define MOTU_PA_RATE_MASK        MOTU_PA_RATE_ANY
98 #define MOTU_PA_OPTICAL_OFF      0x0010    /* Optical port off */
99 #define MOTU_PA_OPTICAL_ADAT     0x0020    /* Optical port in ADAT mode */
100 #define MOTU_PA_OPTICAL_TOSLINK  0x0040    /* Optical port in SPDIF/Toslink mode */
101 #define MOTU_PA_OPTICAL_ON       (MOTU_PA_OPTICAL_ADAT|MOTU_PA_OPTICAL_TOSLINK)
102 #define MOTU_PA_OPTICAL_ANY      (MOTU_PA_OPTICAL_OFF|MOTU_PA_OPTICAL_ON)
103 #define MOTU_PA_OPTICAL_MASK     MOTU_PA_OPTICAL_ANY
104 #define MOTU_PA_PADDING          0x0100
105 #define MOTU_PA_IN               0x0200
106 #define MOTU_PA_OUT              0x0400
107 #define MOTU_PA_INOUT            (MOTU_PA_IN | MOTU_PA_OUT)
108
109 /* Generic "direction" flags */
110 #define MOTU_DIR_IN          1
111 #define MOTU_DIR_OUT         2
112 #define MOTU_DIR_INOUT       (MOTU_DIR_IN | MOTU_DIR_OUT)
113
114 class ConfigRom;
115 class Ieee1394Service;
116
117 namespace Util {
118     class Configuration;
119 }
120
121 namespace Motu {
122
123 enum EMotuModel {
124     MOTU_MODEL_NONE     = 0x0000,
125     MOTU_MODEL_828mkII  = 0x0001,
126     MOTU_MODEL_TRAVELER = 0x0002,
127     MOTU_MODEL_ULTRALITE= 0x0003,
128     MOTU_MODEL_8PRE     = 0x0004,
129     MOTU_MODEL_828MkI   = 0x0005,
130     MOTU_MODEL_896HD    = 0x0006,
131     MOTU_MODEL_828mk3   = 0x0007,
132 };
133
134 struct VendorModelEntry {
135     unsigned int vendor_id;
136     unsigned int model_id;
137     unsigned int unit_version;
138     unsigned int unit_specifier_id;
139     enum EMotuModel model;
140     const char *vendor_name;
141     const char *model_name;
142 };
143
144 struct PortEntry {
145     const char *port_name;
146     unsigned int port_flags;
147     unsigned int port_offset;
148 };
149
150 // Structures used for pre-Mark3 device mixer definitions
151 struct MixerCtrl {
152     const char *name, *label, *desc;
153     unsigned int type;
154     unsigned int dev_register;
155 };
156 struct MatrixMixBus {
157     const char *name;
158     unsigned int address;
159 };
160 struct MatrixMixChannel {
161     const char *name;
162     unsigned int flags;
163     unsigned int addr_ofs;
164 };
165 struct MotuMixer {
166     const MixerCtrl *mixer_ctrl;
167     unsigned int n_mixer_ctrls;
168     const MatrixMixBus *mixer_buses;
169     unsigned int n_mixer_buses;
170     const MatrixMixChannel *mixer_channels;
171     unsigned int n_mixer_channels;
172 };
173
174 // Structures used for devices which use the "Mark3" mixer protocol
175 struct MotuMark3Mixer {
176 };
177
178 struct DevicePropertyEntry {
179     const PortEntry* port_entry;
180     unsigned int n_port_entries;
181     signed int MaxSampleRate;
182     // A device will set at most one of the *mixer fields
183     const struct MotuMixer *mixer;
184     const struct MotuMark3Mixer *m3mixer;
185     // Others features can be added here like MIDI port presence.
186 };
187
188 extern const DevicePropertyEntry DevicesProperty[];
189
190 /* Macro to calculate the size of an array */
191 #define N_ELEMENTS(_array) (sizeof(_array) / sizeof((_array)[0]))
192
193 /* Macro to define a MotuMixer structure succintly */
194 #define MOTUMIXER(_ctrls, _buses, _channels) \
195     { _ctrls, N_ELEMENTS(_ctrls), _buses, N_ELEMENTS(_buses), _channels, N_ELEMENTS(_channels), }
196
197 class MotuDevice : public FFADODevice {
198 public:
199
200     MotuDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) );
201     virtual ~MotuDevice();
202
203     virtual bool buildMixer();
204     virtual bool destroyMixer();
205
206     static bool probe( Util::Configuration&, ConfigRom& configRom, bool generic = false );
207     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
208     static int getConfigurationId( );
209     virtual bool discover();
210
211     virtual void showDevice();
212
213     bool setClockCtrlRegister(signed int samplingFrequency, unsigned int clock_source);
214     virtual bool setSamplingFrequency( int samplingFrequency );
215     virtual int getSamplingFrequency( );
216     virtual std::vector<int> getSupportedSamplingFrequencies();
217
218     FFADODevice::ClockSource clockIdToClockSource(unsigned int id);
219     virtual ClockSourceVector getSupportedClockSources();
220     virtual bool setActiveClockSource(ClockSource);
221     virtual ClockSource getActiveClockSource();
222
223     virtual int getStreamCount();
224     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
225     enum FFADODevice::eStreamingState getStreamingState();
226
227     virtual bool prepare();
228     virtual bool lock();
229     virtual bool unlock();
230
231     virtual bool startStreamByIndex(int i);
232     virtual bool stopStreamByIndex(int i);
233
234     signed int getIsoRecvChannel(void);
235     signed int getIsoSendChannel(void);
236     unsigned int getOpticalMode(unsigned int dir);
237     signed int setOpticalMode(unsigned int dir, unsigned int mode);
238
239     signed int getEventSize(unsigned int dir);
240
241     signed int       m_motu_model;
242 protected:
243     struct VendorModelEntry * m_model;
244     signed int m_iso_recv_channel, m_iso_send_channel;
245     signed int m_rx_bandwidth, m_tx_bandwidth;
246
247     Streaming::MotuReceiveStreamProcessor *m_receiveProcessor;
248     Streaming::MotuTransmitStreamProcessor *m_transmitProcessor;
249
250 private:
251     bool buildMixerAudioControls(void);
252     bool buildMark3MixerAudioControls(void);
253     bool addPort(Streaming::StreamProcessor *s_processor,
254         char *name,
255         enum Streaming::Port::E_Direction direction,
256         int position, int size);
257     bool addDirPorts(
258         enum Streaming::Port::E_Direction direction,
259         unsigned int sample_rate, unsigned int optical_mode);
260
261 public:
262     unsigned int ReadRegister(unsigned int reg);
263     signed int WriteRegister(unsigned int reg, quadlet_t data);
264
265 private:
266     Control::Container *m_MixerContainer;
267     Control::Container *m_ControlContainer;
268 };
269
270 }
271
272 #endif
Note: See TracBrowser for help on using the browser.