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

Revision 1300, 7.6 kB (checked in by jwoithe, 13 years ago)

MOTU: merge recent trunk mixer changes to 2.0 branch from revisions 1257, 1265 and 1274 ("svn merge -r REV" for REV = 1256:1257, 1264:1265, 1273:1274). Not yet tested.

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 #define MOTU_RATE_BASE_44100         (0<<3)
41 #define MOTU_RATE_BASE_48000         (1<<3)
42 #define MOTU_RATE_MULTIPLIER_1X      (0<<4)
43 #define MOTU_RATE_MULTIPLIER_2X      (1<<4)
44 #define MOTU_RATE_MULTIPLIER_4X      (2<<4)
45 #define MOTU_RATE_BASE_MASK          (0x00000008)
46 #define MOTU_RATE_MULTIPLIER_MASK    (0x00000030)
47
48 #define MOTU_OPTICAL_MODE_OFF        0x00
49 #define MOTU_OPTICAL_MODE_ADAT       0x01
50 #define MOTU_OPTICAL_MODE_TOSLINK    0x02
51 #define MOTU_OPTICAL_IN_MODE_MASK    (0x00000300)
52 #define MOTU_OPTICAL_OUT_MODE_MASK   (0x00000c00)
53 #define MOTU_OPTICAL_MODE_MASK       (MOTU_OPTICAL_IN_MODE_MASK|MOTU_OPTICAL_MODE_MASK)
54
55 #define MOTU_CLKSRC_MASK             0x00000007
56 #define MOTU_CLKSRC_INTERNAL         0
57 #define MOTU_CLKSRC_ADAT_OPTICAL     1
58 #define MOTU_CLKSRC_SPDIF_TOSLINK    2
59 #define MOTU_CLKSRC_SMPTE            3
60 #define MOTU_CLKSRC_WORDCLOCK        4
61 #define MOTU_CLKSRC_ADAT_9PIN        5
62 #define MOTU_CLKSRC_AES_EBU          7
63 #define MOTU_CLKSRC_NONE             0xffff
64 #define MOTU_CLKSRC_UNCHANGED        MOTU_CLKSRC_NONE
65
66 #define MOTU_DIR_IN          1
67 #define MOTU_DIR_OUT         2
68 #define MOTU_DIR_INOUT       (MOTU_DIR_IN | MOTU_DIR_OUT)
69
70 /* Device registers */
71 #define MOTU_REG_ISOCTRL           0x0b00
72 #define MOTU_REG_OPTICAL_CTRL      0x0b10
73 #define MOTU_REG_CLK_CTRL          0x0b14
74 #define MOTU_REG_ROUTE_PORT_CONF   0x0c04
75 #define MOTU_REG_INPUT_LEVEL       0x0c08
76 #define MOTU_REG_INPUT_BOOST       0x0c14
77 #define MOTU_REG_INPUT_GAIN_PAD_0  0x0c1c
78 #define MOTU_REG_CLKSRC_NAME0      0x0c60
79
80 /* Port Active Flags (ports declaration) */
81 #define MOTU_PA_RATE_1x          0x0001    /* 44k1 or 48k */
82 #define MOTU_PA_RATE_2x          0x0002    /* 88k2 or 96k */
83 #define MOTU_PA_RATE_4x          0x0004    /* 176k4 or 192k */
84 #define MOTU_PA_RATE_1x2x        (MOTU_PA_RATE_1x|MOTU_PA_RATE_2x)
85 #define MOTU_PA_RATE_ANY         (MOTU_PA_RATE_1x|MOTU_PA_RATE_2x|MOTU_PA_RATE_4x)
86 #define MOTU_PA_RATE_MASK        MOTU_PA_RATE_ANY
87 #define MOTU_PA_OPTICAL_OFF      0x0010    /* Optical port off */
88 #define MOTU_PA_OPTICAL_ADAT     0x0020    /* Optical port in ADAT mode */
89 #define MOTU_PA_OPTICAL_TOSLINK  0x0040    /* Optical port in SPDIF/Toslink mode */
90 #define MOTU_PA_OPTICAL_ON       (MOTU_PA_OPTICAL_ADAT|MOTU_PA_OPTICAL_TOSLINK)
91 #define MOTU_PA_OPTICAL_ANY      (MOTU_PA_OPTICAL_OFF|MOTU_PA_OPTICAL_ON)
92 #define MOTU_PA_OPTICAL_MASK     MOTU_PA_OPTICAL_ANY
93
94 class ConfigRom;
95 class Ieee1394Service;
96
97 namespace Util {
98     class Configuration;
99 }
100
101 namespace Motu {
102
103 enum EMotuModel {
104     MOTU_MODEL_NONE     = 0x0000,
105     MOTU_MODEL_828mkII  = 0x0001,
106     MOTU_MODEL_TRAVELER = 0x0002,
107     MOTU_MODEL_ULTRALITE= 0x0003,
108     MOTU_MODEL_8PRE     = 0x0004,
109     MOTU_MODEL_828MkI   = 0x0005,
110     MOTU_MODEL_896HD    = 0x0006,
111 };
112
113 struct VendorModelEntry {
114     unsigned int vendor_id;
115     unsigned int model_id;
116     unsigned int unit_version;
117     unsigned int unit_specifier_id;
118     enum EMotuModel model;
119     const char *vendor_name;
120     const char *model_name;
121 };
122
123 struct PortEntry {
124     const char *port_name;
125     unsigned int port_dir;
126     unsigned int port_flags;
127     unsigned int port_offset;
128 };
129
130 struct MixerCtrl {
131     const char *name, *label, *desc;
132     unsigned int type;
133     unsigned int dev_register;
134 };
135
136 struct MatrixMixBus {
137     const char *name;
138     unsigned int address;
139 };
140
141 struct MatrixMixChannel {
142     const char *name;
143     unsigned int flags;
144     unsigned int addr_ofs;
145 };
146
147 struct MotuMixer {
148     const MixerCtrl *mixer_ctrl;
149     unsigned int n_mixer_ctrls;
150     const MatrixMixBus *mixer_buses;
151     unsigned int n_mixer_buses;
152     const MatrixMixChannel *mixer_channels;
153     unsigned int n_mixer_channels;
154 };
155
156 struct DevicePropertyEntry {
157     const PortEntry* port_entry;
158     unsigned int n_port_entries;
159     signed int MaxSampleRate;
160     const struct MotuMixer *mixer;
161     // Others features can be added here like MIDI port presence.
162 };
163
164 /* Macro to calculate the size of an array */
165 #define N_ELEMENTS(_array) (sizeof(_array) / sizeof((_array)[0]))
166
167 /* Macro to define a MotuMixer structure succintly */
168 #define MOTUMIXER(_ctrls, _buses, _channels) \
169     { _ctrls, N_ELEMENTS(_ctrls), _buses, N_ELEMENTS(_buses), _channels, N_ELEMENTS(_channels), }
170
171 class MotuDevice : public FFADODevice {
172 public:
173
174     MotuDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ) );
175     virtual ~MotuDevice();
176
177     virtual bool buildMixer();
178     virtual bool destroyMixer();
179
180     static bool probe( Util::Configuration&, ConfigRom& configRom, bool generic = false );
181     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
182     static int getConfigurationId( );
183     virtual bool discover();
184
185     virtual void showDevice();
186
187     bool setClockCtrlRegister(signed int samplingFrequency, unsigned int clock_source);
188     virtual bool setSamplingFrequency( int samplingFrequency );
189     virtual int getSamplingFrequency( );
190     virtual std::vector<int> getSupportedSamplingFrequencies();
191
192     FFADODevice::ClockSource clockIdToClockSource(unsigned int id);
193     virtual ClockSourceVector getSupportedClockSources();
194     virtual bool setActiveClockSource(ClockSource);
195     virtual ClockSource getActiveClockSource();
196
197     virtual int getStreamCount();
198     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
199
200     virtual bool prepare();
201     virtual bool lock();
202     virtual bool unlock();
203
204     virtual bool startStreamByIndex(int i);
205     virtual bool stopStreamByIndex(int i);
206
207     signed int getIsoRecvChannel(void);
208     signed int getIsoSendChannel(void);
209     unsigned int getOpticalMode(unsigned int dir);
210     signed int setOpticalMode(unsigned int dir, unsigned int mode);
211
212     signed int getEventSize(unsigned int dir);
213
214     signed int       m_motu_model;
215 protected:
216     struct VendorModelEntry * m_model;
217     signed int m_iso_recv_channel, m_iso_send_channel;
218     signed int m_rx_bandwidth, m_tx_bandwidth;
219
220     Streaming::MotuReceiveStreamProcessor *m_receiveProcessor;
221     Streaming::MotuTransmitStreamProcessor *m_transmitProcessor;
222
223 private:
224     bool addPort(Streaming::StreamProcessor *s_processor,
225         char *name,
226         enum Streaming::Port::E_Direction direction,
227         int position, int size);
228     bool addDirPorts(
229         enum Streaming::Port::E_Direction direction,
230         unsigned int sample_rate, unsigned int optical_mode);
231
232 public:
233     unsigned int ReadRegister(unsigned int reg);
234     signed int WriteRegister(unsigned int reg, quadlet_t data);
235
236 private:
237     Control::Container *m_MixerContainer;
238     Control::Container *m_ControlContainer;
239 };
240
241 }
242
243 #endif
Note: See TracBrowser for help on using the browser.