root/trunk/libffado/src/motu/motu_avdevice.h

Revision 1763, 11.1 kB (checked in by ppalmers, 13 years ago)

Merged revisions 1536,1541,1544-1546,1549,1554-1562,1571,1579-1581,1618,1632,1634-1635,1661,1677-1679,1703-1704,1715,1720-1723,1743-1745,1755 via svnmerge from
svn+ssh://ffadosvn@ffado.org/ffado/branches/libffado-2.0

Also fix remaining format string warnings.

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 #include "motu_mark3_controls.h"
38
39 #define MOTU_BASE_ADDR               0xfffff0000000ULL
40
41 /* Bitmasks and values used when setting MOTU device registers */
42 #define MOTU_RATE_BASE_44100         (0<<3)
43 #define MOTU_RATE_BASE_48000         (1<<3)
44 #define MOTU_RATE_MULTIPLIER_1X      (0<<4)
45 #define MOTU_RATE_MULTIPLIER_2X      (1<<4)
46 #define MOTU_RATE_MULTIPLIER_4X      (2<<4)
47 #define MOTU_RATE_BASE_MASK          (0x00000008)
48 #define MOTU_RATE_MULTIPLIER_MASK    (0x00000030)
49
50 #define MOTU_OPTICAL_MODE_OFF        0x00
51 #define MOTU_OPTICAL_MODE_ADAT       0x01
52 #define MOTU_OPTICAL_MODE_TOSLINK    0x02
53 #define MOTU_OPTICAL_IN_MODE_MASK    (0x00000300)
54 #define MOTU_OPTICAL_OUT_MODE_MASK   (0x00000c00)
55 #define MOTU_OPTICAL_MODE_MASK       (MOTU_OPTICAL_IN_MODE_MASK|MOTU_OPTICAL_MODE_MASK)
56
57 #define MOTU_CLKSRC_MASK             0x00000007
58 #define MOTU_CLKSRC_INTERNAL         0
59 #define MOTU_CLKSRC_ADAT_OPTICAL     1
60 #define MOTU_CLKSRC_SPDIF_TOSLINK    2
61 #define MOTU_CLKSRC_SMPTE            3
62 #define MOTU_CLKSRC_WORDCLOCK        4
63 #define MOTU_CLKSRC_ADAT_9PIN        5
64 #define MOTU_CLKSRC_AES_EBU          7
65 #define MOTU_CLKSRC_NONE             0xffff
66 #define MOTU_CLKSRC_UNCHANGED        MOTU_CLKSRC_NONE
67
68 #define MOTU_METER_PEAKHOLD_MASK     0x3800
69 #define MOTU_METER_PEAKHOLD_SHIFT    11
70 #define MOTU_METER_CLIPHOLD_MASK     0x0700
71 #define MOTU_METER_CLIPHOLD_SHIFT    8
72 #define MOTU_METER_AESEBU_SRC_MASK   0x0004
73 #define MOTU_METER_AESEBU_SRC_SHIFT  2
74 #define MOTU_METER_PROG_SRC_MASK     0x0003
75 #define MOTU_METER_PROG_SRC_SHIFT    0
76
77 /* Device registers */
78 #define MOTU_REG_ISOCTRL           0x0b00
79 #define MOTU_REG_OPTICAL_CTRL      0x0b10
80 #define MOTU_REG_CLK_CTRL          0x0b14
81 #define MOTU_REG_896HD_METER_REG   0x0b1c
82 #define MOTU_REG_896HD_METER_CONF  0x0b24
83 #define MOTU_REG_ROUTE_PORT_CONF   0x0c04
84 #define MOTU_REG_INPUT_LEVEL       0x0c08
85 #define MOTU_REG_INPUT_BOOST       0x0c14
86 #define MOTU_REG_INPUT_GAIN_PAD_0  0x0c1c
87 #define MOTU_REG_CLKSRC_NAME0      0x0c60
88 #define MOTU_REG_INPUT_GAIN_PHINV0 0x0c70
89 #define MOTU_REG_INPUT_GAIN_PHINV1 0x0c74
90 #define MOTU_REG_INPUT_GAIN_PHINV2 0x0c78
91
92 /* Device register definitions for the earliest generation devices */
93 #define MOTU_G1_REG_CONFIG         0x0b00
94 #define MOTU_G1_REG_ISOCTRL        0x0b10
95
96 /* There's an unknown subtlety regarding the optical mode of the "generation
97  * 1" devices such as the 828Mk1.  It seems that the same configuration
98  * register setting is used for "off" and "adat" modes.  There must be more
99  * to this though because the number of audio channels sent presumedly
100  * changes when adat mode is selected; there must be some way that the
101  * device deduces the mode.
102  */
103 #define MOTU_G1_OPT_IN_MODE_MASK   0x8000
104 #define MOTU_G1_OPT_IN_MODE_BIT0       15
105 #define MOTU_G1_OPT_OUT_MODE_MASK  0x4000
106 #define MOTU_G1_OPT_OUT_MODE_BIT0      14
107 #define MOTU_G1_OPTICAL_OFF        0x0000
108 #define MOTU_G1_OPTICAL_TOSLINK    0x0001
109 #define MOTU_G1_OPTICAL_ADAT       0x0000
110
111 #define MOTU_G1_RATE_MASK          0x0004
112 #define MOTU_G1_RATE_44100         0x0000
113 #define MOTU_G1_RATE_48000         0x0004
114
115 #define MOTU_G1_CLKSRC_MASK        0x0003
116 #define MOTU_G1_CLKSRC_INTERNAL    0x0000
117 #define MOTU_G1_CLKSRC_ADAT_9PIN   0x0001
118 #define MOTU_G1_CLKSRC_SPDIF       0x0002
119 #define MOTU_G1_CLKSRC_UNCHANGED   MOTU_CLKSRC_UNCHANGED
120
121 #define MOTU_G1_MONIN_MASK         0x3f00
122 #define MOTU_G1_MONIN_L_SRC_MASK   0x0600
123 #define MOTU_G1_MONIN_R_SRC_MASK   0x3000
124 #define MOTU_G1_MONIN_L_MUTE_MASK  0x0100  // Yes, the sense of these 2 bits
125 #define MOTU_G1_MONIN_R_EN_MASK    0x0800  //   really are reversed
126 #define MOTU_G1_MONIN_L_MUTE       0x0100
127 #define MOTU_G1_MONIN_L_ENABLE     0x0000
128 #define MOTU_G1_MONIN_R_MUTE       0x0000
129 #define MOTU_G1_MONIN_R_ENABLE     0x0800
130 #define MOTU_G1_MONIN_L_CH1        0x0000
131 #define MOTU_G1_MONIN_L_CH3        0x0020
132 #define MOTU_G1_MONIN_L_CH5        0x0040
133 #define MOTU_G1_MONIN_L_CH7        0x0060
134 #define MOTU_G1_MONIN_R_CH2        0x0000
135 #define MOTU_G1_MONIN_R_CH4        0x1000
136 #define MOTU_G1_MONIN_R_CH6        0x2000
137 #define MOTU_G1_MONIN_R_CH8        0x3000
138
139 /* Mark3 device registers - these don't have MOTU_BASE_ADDR as the base
140  * address so for now we'll define them as absolute addresses.
141  */
142 #define MOTU_MARK3_REG_MIXER     0xffff00010000LL
143
144 /* Port Active Flags (ports declaration) */
145 #define MOTU_PA_RATE_1x          0x0001    /* 44k1 or 48k */
146 #define MOTU_PA_RATE_2x          0x0002    /* 88k2 or 96k */
147 #define MOTU_PA_RATE_4x          0x0004    /* 176k4 or 192k */
148 #define MOTU_PA_RATE_1x2x        (MOTU_PA_RATE_1x|MOTU_PA_RATE_2x)
149 #define MOTU_PA_RATE_ANY         (MOTU_PA_RATE_1x|MOTU_PA_RATE_2x|MOTU_PA_RATE_4x)
150 #define MOTU_PA_RATE_MASK        MOTU_PA_RATE_ANY
151 #define MOTU_PA_OPTICAL_OFF      0x0010    /* Optical port off */
152 #define MOTU_PA_OPTICAL_ADAT     0x0020    /* Optical port in ADAT mode */
153 #define MOTU_PA_OPTICAL_TOSLINK  0x0040    /* Optical port in SPDIF/Toslink mode */
154 #define MOTU_PA_OPTICAL_ON       (MOTU_PA_OPTICAL_ADAT|MOTU_PA_OPTICAL_TOSLINK)
155 #define MOTU_PA_OPTICAL_ANY      (MOTU_PA_OPTICAL_OFF|MOTU_PA_OPTICAL_ON)
156 #define MOTU_PA_OPTICAL_MASK     MOTU_PA_OPTICAL_ANY
157 #define MOTU_PA_PADDING          0x0100
158 #define MOTU_PA_IN               0x0200
159 #define MOTU_PA_OUT              0x0400
160 #define MOTU_PA_INOUT            (MOTU_PA_IN | MOTU_PA_OUT)
161
162 /* Generic "direction" flags */
163 #define MOTU_DIR_IN          1
164 #define MOTU_DIR_OUT         2
165 #define MOTU_DIR_INOUT       (MOTU_DIR_IN | MOTU_DIR_OUT)
166
167 class ConfigRom;
168 class Ieee1394Service;
169
170 namespace Util {
171     class Configuration;
172 }
173
174 namespace Motu {
175
176 enum EMotuModel {
177     MOTU_MODEL_NONE         = 0x0000,
178     MOTU_MODEL_828mkII      = 0x0001,
179     MOTU_MODEL_TRAVELER     = 0x0002,
180     MOTU_MODEL_ULTRALITE    = 0x0003,
181     MOTU_MODEL_8PRE         = 0x0004,
182     MOTU_MODEL_828MkI       = 0x0005,
183     MOTU_MODEL_896HD        = 0x0006,
184     MOTU_MODEL_828mk3       = 0x0007,
185     MOTU_MODEL_ULTRALITEmk3 = 0x0008,
186 };
187
188 struct VendorModelEntry {
189     unsigned int vendor_id;
190     unsigned int model_id;
191     unsigned int unit_version;
192     unsigned int unit_specifier_id;
193     enum EMotuModel model;
194     const char *vendor_name;
195     const char *model_name;
196 };
197
198 struct PortEntry {
199     const char *port_name;
200     unsigned int port_flags;
201     unsigned int port_offset;
202 };
203
204 // Structures used for pre-Mark3 device mixer definitions
205 struct MixerCtrl {
206     const char *name, *label, *desc;
207     unsigned int type;
208     unsigned int dev_register;
209 };
210 struct MatrixMixBus {
211     const char *name;
212     unsigned int address;
213 };
214 struct MatrixMixChannel {
215     const char *name;
216     unsigned int flags;
217     unsigned int addr_ofs;
218 };
219 struct MotuMixer {
220     const MixerCtrl *mixer_ctrl;
221     unsigned int n_mixer_ctrls;
222     const MatrixMixBus *mixer_buses;
223     unsigned int n_mixer_buses;
224     const MatrixMixChannel *mixer_channels;
225     unsigned int n_mixer_channels;
226 };
227
228 // Structures used for devices which use the "Mark3" mixer protocol
229 struct MotuMark3Mixer {
230 };
231
232 struct DevicePropertyEntry {
233     const PortEntry* port_entry;
234     unsigned int n_port_entries;
235     signed int MaxSampleRate;
236     // A device will set at most one of the *mixer fields
237     const struct MotuMixer *mixer;
238     const struct MotuMark3Mixer *m3mixer;
239     // Others features can be added here like MIDI port presence.
240 };
241
242 extern const DevicePropertyEntry DevicesProperty[];
243
244 /* Macro to calculate the size of an array */
245 #define N_ELEMENTS(_array) (sizeof(_array) / sizeof((_array)[0]))
246
247 /* Macro to define a MotuMixer structure succintly */
248 #define MOTUMIXER(_ctrls, _buses, _channels) \
249     { _ctrls, N_ELEMENTS(_ctrls), _buses, N_ELEMENTS(_buses), _channels, N_ELEMENTS(_channels), }
250
251 class MotuDevice : public FFADODevice {
252 public:
253
254     MotuDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) );
255     virtual ~MotuDevice();
256
257     virtual bool buildMixer();
258     virtual bool destroyMixer();
259
260     static bool probe( Util::Configuration&, ConfigRom& configRom, bool generic = false );
261     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
262     static int getConfigurationId( );
263     virtual bool discover();
264
265     virtual void showDevice();
266
267     bool setClockCtrlRegister(signed int samplingFrequency, unsigned int clock_source);
268     virtual bool setSamplingFrequency( int samplingFrequency );
269     virtual int getSamplingFrequency( );
270     virtual std::vector<int> getSupportedSamplingFrequencies();
271
272     FFADODevice::ClockSource clockIdToClockSource(unsigned int id);
273     virtual ClockSourceVector getSupportedClockSources();
274     virtual bool setActiveClockSource(ClockSource);
275     virtual ClockSource getActiveClockSource();
276
277     virtual int getStreamCount();
278     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
279     enum FFADODevice::eStreamingState getStreamingState();
280
281     virtual bool prepare();
282     virtual bool lock();
283     virtual bool unlock();
284
285     virtual bool startStreamByIndex(int i);
286     virtual bool stopStreamByIndex(int i);
287
288     signed int getIsoRecvChannel(void);
289     signed int getIsoSendChannel(void);
290     unsigned int getOpticalMode(unsigned int dir);
291     signed int setOpticalMode(unsigned int dir, unsigned int mode);
292
293     signed int getEventSize(unsigned int dir);
294
295     signed int       m_motu_model;
296 protected:
297     struct VendorModelEntry * m_model;
298     signed int m_iso_recv_channel, m_iso_send_channel;
299     signed int m_rx_bandwidth, m_tx_bandwidth;
300
301     Streaming::MotuReceiveStreamProcessor *m_receiveProcessor;
302     Streaming::MotuTransmitStreamProcessor *m_transmitProcessor;
303
304 private:
305     bool buildMixerAudioControls(void);
306     bool buildMark3MixerAudioControls(void);
307     bool addPort(Streaming::StreamProcessor *s_processor,
308         char *name,
309         enum Streaming::Port::E_Direction direction,
310         int position, int size);
311     bool addDirPorts(
312         enum Streaming::Port::E_Direction direction,
313         unsigned int sample_rate, unsigned int optical_mode);
314
315 public:
316     unsigned int ReadRegister(unsigned int reg);
317     signed int WriteRegister(unsigned int reg, quadlet_t data);
318
319 private:
320     Control::Container *m_MixerContainer;
321     Control::Container *m_ControlContainer;
322 };
323
324 }
325
326 #endif
Note: See TracBrowser for help on using the browser.