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

Revision 1122, 6.8 kB (checked in by jwoithe, 16 years ago)

* RME: interpret return values of read()/write() from Ieee1394Service correctly.

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 <netinet/in.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 )
71 {
72     unsigned int vendorId = configRom.getNodeVendorId();
73     unsigned int unitVersion = configRom.getUnitVersion();
74
75     for ( unsigned int i = 0;
76           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
77           ++i )
78     {
79         if ( ( supportedDeviceList[i].vendor_id == vendorId )
80              && ( supportedDeviceList[i].unit_version == unitVersion )
81            )
82         {
83             return true;
84         }
85     }
86
87     return false;
88 }
89
90 FFADODevice *
91 RmeDevice::createDevice(DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ))
92 {
93     return new RmeDevice(d, configRom );
94 }
95
96 bool
97 RmeDevice::discover()
98 {
99     unsigned int vendorId = getConfigRom().getNodeVendorId();
100     unsigned int unitVersion = getConfigRom().getUnitVersion();
101
102     for ( unsigned int i = 0;
103           i < ( sizeof( supportedDeviceList )/sizeof( VendorModelEntry ) );
104           ++i )
105     {
106         if ( ( supportedDeviceList[i].vendor_id == vendorId )
107              && ( supportedDeviceList[i].unit_version == unitVersion )
108            )
109         {
110             m_model = &(supportedDeviceList[i]);
111             m_rme_model = supportedDeviceList[i].model;
112         }
113     }
114
115     if (m_model != NULL) {
116         debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
117                 m_model->vendor_name, m_model->model_name);
118         return true;
119     }
120
121     return false;
122 }
123
124 int
125 RmeDevice::getSamplingFrequency( ) {
126 /*
127  * Retrieve the current sample rate from the RME device.  At this stage it
128  * seems that the "current rate" can't be retrieved from the device.  Other
129  * drivers don't read the DDS control register and there isn't anywhere else
130  * where the frequency is sent back to the PC.  Unless we test the DDS
131  * control register for readabilty and find it can be read we'll assume it
132  * can't and instead cache the DDS frequency.
133  *
134  * If the device frequency has not been set this function will return -1
135  * (the default value of m_ddsFreq).
136  */
137     return m_ddsFreq;
138 }
139
140 int
141 RmeDevice::getConfigurationId()
142 {
143     return 0;
144 }
145
146 bool
147 RmeDevice::setSamplingFrequency( int samplingFrequency )
148 {
149 /*
150  * Set the RME device's samplerate.  The RME can do sampling frequencies of
151  * 32k, 44.1k and 48k along with the corresponding 2x and 4x rates.
152  * However, it can also do +/- 4% from any of these "base" frequencies.
153  * This makes it a little long-winded to work out whether a given frequency
154  * is supported or not.
155  */
156
157     /* Work out whether the requested rate is supported */
158     if (!((samplingFrequency >= 32000*0.96 && samplingFrequency <= 32000*1.04) ||
159         (samplingFrequency >= 44100*0.96 && samplingFrequency <= 44100*1.04) ||
160         (samplingFrequency >= 48000*0.96 && samplingFrequency <= 48000*1.04) ||
161         (samplingFrequency >= 64000*0.96 && samplingFrequency <= 64000*1.04) ||
162         (samplingFrequency >= 88200*0.96 && samplingFrequency <= 88200*1.04) ||
163         (samplingFrequency >= 96000*0.96 && samplingFrequency <= 96000*1.04) ||
164         (samplingFrequency >= 128000*0.96 && samplingFrequency <= 128000*1.04) ||
165         (samplingFrequency >= 176000*0.96 && samplingFrequency <= 176000*1.04) ||
166         (samplingFrequency >= 192000*0.96 && samplingFrequency <= 192000*1.04))) {
167         return false;
168     }
169    
170     /* Send the desired frequency to the RME */
171     if (writeRegister(RME_REG_DDS_CONTROL, samplingFrequency) != 0)
172       return false;
173
174     m_ddsFreq = samplingFrequency;
175     return true;
176 }
177
178 FFADODevice::ClockSourceVector
179 RmeDevice::getSupportedClockSources() {
180     FFADODevice::ClockSourceVector r;
181     return r;
182 }
183
184 bool
185 RmeDevice::setActiveClockSource(ClockSource s) {
186     return false;
187 }
188
189 FFADODevice::ClockSource
190 RmeDevice::getActiveClockSource() {
191     ClockSource s;
192     return s;
193 }
194
195 bool
196 RmeDevice::lock() {
197
198     return true;
199 }
200
201
202 bool
203 RmeDevice::unlock() {
204
205     return true;
206 }
207
208 void
209 RmeDevice::showDevice()
210 {
211         debugOutput(DEBUG_LEVEL_VERBOSE,
212                 "%s %s at node %d\n", m_model->vendor_name, m_model->model_name,
213                 getNodeId());
214 }
215
216 bool
217 RmeDevice::prepare() {
218
219         debugOutput(DEBUG_LEVEL_NORMAL, "Preparing RmeDevice...\n" );
220
221         return true;
222 }
223
224 int
225 RmeDevice::getStreamCount() {
226         return 0; // one receive, one transmit
227 }
228
229 Streaming::StreamProcessor *
230 RmeDevice::getStreamProcessorByIndex(int i) {
231     return NULL;
232 }
233
234 bool
235 RmeDevice::startStreamByIndex(int i) {
236     return false;
237 }
238
239 bool
240 RmeDevice::stopStreamByIndex(int i) {
241     return false;
242
243 }
244
245 unsigned int
246 RmeDevice::readRegister(unsigned int reg) {
247
248     quadlet_t quadlet;
249    
250     quadlet = 0;
251     if (get1394Service().read(0xffc0 | getNodeId(), reg, 1, &quadlet) <= 0) {
252         debugError("Error doing RME read from register 0x%06x\n",reg);
253     }
254     return ntohl(quadlet);
255 }
256
257 signed int
258 RmeDevice::writeRegister(unsigned int reg, quadlet_t data) {
259
260     unsigned int err = 0;
261     data = htonl(data);
262     if (get1394Service().write(0xffc0 | getNodeId(), reg, 1, &data) <= 0) {
263         err = 1;
264         debugError("Error doing RME write to register 0x%06x\n",reg);
265     }
266 //    SleepRelativeUsec(100);
267     return (err==0)?0:-1;
268 }
269                  
270 }
Note: See TracBrowser for help on using the browser.