root/trunk/libffado/src/rme/rme_avdevice.cpp

Revision 1239, 6.9 kB (checked in by ppalmers, 16 years ago)
Line 
1 /*
2  * Copyright (C) 2005-2008 by Jonathan Woithe
3  * Copyright (C) 2005-2008 by Pieter Palmers
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 #warning RME support is currently useless (detection only)
26
27 #include "rme/rme_avdevice.h"
28
29 #include "libieee1394/configrom.h"
30 #include "libieee1394/ieee1394service.h"
31
32 #include "debugmodule/debugmodule.h"
33
34 #include <string>
35 #include <stdint.h>
36 #include <assert.h>
37 #include "libutil/ByteSwap.h"
38
39 #include <iostream>
40 #include <sstream>
41
42 #include <libraw1394/csr.h>
43
44 namespace Rme {
45
46 // to define the supported devices
47 static VendorModelEntry supportedDeviceList[] =
48 {
49     {FW_VENDORID_RME, 0x0001, RME_MODEL_FIREFACE800, "RME", "Fireface-800"},
50     {FW_VENDORID_RME, 0x0002, RME_MODEL_FIREFACE400, "RME", "Fireface-400"},
51 };
52
53 RmeDevice::RmeDevice( DeviceManager& d,
54                       std::auto_ptr<ConfigRom>( configRom ))
55     : FFADODevice( d, configRom )
56     , m_model( NULL )
57     , m_rme_model( RME_MODEL_NONE )
58     , m_ddsFreq( -1 )
59 {
60     debugOutput( DEBUG_LEVEL_VERBOSE, "Created Rme::RmeDevice (NodeID %d)\n",
61                  getConfigRom().getNodeId() );
62 }
63
64 RmeDevice::~RmeDevice()
65 {
66
67 }
68
69 bool
70 RmeDevice::probe( ConfigRom& configRom, bool generic )
71 {
72     if (generic) return false;
73     unsigned int vendorId = configRom.getNodeVendorId();
74     unsigned int unitVersion = configRom.getUnitVersion();
75
76     for ( unsigned int i = 0;
77           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
78           ++i )
79     {
80         if ( ( supportedDeviceList[i].vendor_id == vendorId )
81              && ( supportedDeviceList[i].unit_version == unitVersion )
82            )
83         {
84             return true;
85         }
86     }
87
88     return false;
89 }
90
91 FFADODevice *
92 RmeDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ))
93 {
94     return new RmeDevice(d, configRom );
95 }
96
97 bool
98 RmeDevice::discover()
99 {
100     unsigned int vendorId = getConfigRom().getNodeVendorId();
101     unsigned int unitVersion = getConfigRom().getUnitVersion();
102
103     for ( unsigned int i = 0;
104           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
105           ++i )
106     {
107         if ( ( supportedDeviceList[i].vendor_id == vendorId )
108              && ( supportedDeviceList[i].unit_version == unitVersion )
109            )
110         {
111             m_model = &(supportedDeviceList[i]);
112             m_rme_model = supportedDeviceList[i].model;
113         }
114     }
115
116     if (m_model != NULL) {
117         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
118                 m_model->vendor_name, m_model->model_name);
119         return true;
120     }
121
122     return false;
123 }
124
125 int
126 RmeDevice::getSamplingFrequency( ) {
127 /*
128  * Retrieve the current sample rate from the RME device.  At this stage it
129  * seems that the "current rate" can't be retrieved from the device.  Other
130  * drivers don't read the DDS control register and there isn't anywhere else
131  * where the frequency is sent back to the PC.  Unless we test the DDS
132  * control register for readabilty and find it can be read we'll assume it
133  * can't and instead cache the DDS frequency.
134  *
135  * If the device frequency has not been set this function will return -1
136  * (the default value of m_ddsFreq).
137  */
138     return m_ddsFreq;
139 }
140
141 int
142 RmeDevice::getConfigurationId()
143 {
144     return 0;
145 }
146
147 bool
148 RmeDevice::setSamplingFrequency( int samplingFrequency )
149 {
150 /*
151  * Set the RME device's samplerate.  The RME can do sampling frequencies of
152  * 32k, 44.1k and 48k along with the corresponding 2x and 4x rates.
153  * However, it can also do +/- 4% from any of these "base" frequencies.
154  * This makes it a little long-winded to work out whether a given frequency
155  * is supported or not.
156  */
157
158     /* Work out whether the requested rate is supported */
159     if (!((samplingFrequency >= 32000*0.96 && samplingFrequency <= 32000*1.04) ||
160         (samplingFrequency >= 44100*0.96 && samplingFrequency <= 44100*1.04) ||
161         (samplingFrequency >= 48000*0.96 && samplingFrequency <= 48000*1.04) ||
162         (samplingFrequency >= 64000*0.96 && samplingFrequency <= 64000*1.04) ||
163         (samplingFrequency >= 88200*0.96 && samplingFrequency <= 88200*1.04) ||
164         (samplingFrequency >= 96000*0.96 && samplingFrequency <= 96000*1.04) ||
165         (samplingFrequency >= 128000*0.96 && samplingFrequency <= 128000*1.04) ||
166         (samplingFrequency >= 176000*0.96 && samplingFrequency <= 176000*1.04) ||
167         (samplingFrequency >= 192000*0.96 && samplingFrequency <= 192000*1.04))) {
168         return false;
169     }
170    
171     /* Send the desired frequency to the RME */
172     if (writeRegister(RME_REG_DDS_CONTROL, samplingFrequency) != 0)
173       return false;
174
175     m_ddsFreq = samplingFrequency;
176     return true;
177 }
178
179 FFADODevice::ClockSourceVector
180 RmeDevice::getSupportedClockSources() {
181     FFADODevice::ClockSourceVector r;
182     return r;
183 }
184
185 bool
186 RmeDevice::setActiveClockSource(ClockSource s) {
187     return false;
188 }
189
190 FFADODevice::ClockSource
191 RmeDevice::getActiveClockSource() {
192     ClockSource s;
193     return s;
194 }
195
196 bool
197 RmeDevice::lock() {
198
199     return true;
200 }
201
202
203 bool
204 RmeDevice::unlock() {
205
206     return true;
207 }
208
209 void
210 RmeDevice::showDevice()
211 {
212         debugOutput(DEBUG_LEVEL_VERBOSE,
213                 "%s %s at node %d\n", m_model->vendor_name, m_model->model_name,
214                 getNodeId());
215 }
216
217 bool
218 RmeDevice::prepare() {
219
220         debugOutput(DEBUG_LEVEL_NORMAL, "Preparing RmeDevice...\n" );
221
222         return true;
223 }
224
225 int
226 RmeDevice::getStreamCount() {
227         return 0; // one receive, one transmit
228 }
229
230 Streaming::StreamProcessor *
231 RmeDevice::getStreamProcessorByIndex(int i) {
232     return NULL;
233 }
234
235 bool
236 RmeDevice::startStreamByIndex(int i) {
237     return false;
238 }
239
240 bool
241 RmeDevice::stopStreamByIndex(int i) {
242     return false;
243
244 }
245
246 unsigned int
247 RmeDevice::readRegister(unsigned int reg) {
248
249     quadlet_t quadlet;
250    
251     quadlet = 0;
252     if (get1394Service().read(0xffc0 | getNodeId(), reg, 1, &quadlet) <= 0) {
253         debugError("Error doing RME read from register 0x%06x\n",reg);
254     }
255     return CondSwapFromBus32(quadlet);
256 }
257
258 signed int
259 RmeDevice::writeRegister(unsigned int reg, quadlet_t data) {
260
261     unsigned int err = 0;
262     data = CondSwapToBus32(data);
263     if (get1394Service().write(0xffc0 | getNodeId(), reg, 1, &data) <= 0) {
264         err = 1;
265         debugError("Error doing RME write to register 0x%06x\n",reg);
266     }
267 //    SleepRelativeUsec(100);
268     return (err==0)?0:-1;
269 }
270                  
271 }
Note: See TracBrowser for help on using the browser.