root/trunk/libffado/src/bebob/maudio/normal_avdevice.cpp

Revision 2802, 6.6 kB (checked in by jwoithe, 3 years ago)

Cosmetic: "Firewire" becomes "FireWire?".

Officially both the "F" and "W" were capitalised in the FireWire? name, so
reflect this throughout FFADO's source tree. This mostly affects comments.

This patch originated from pander on the ffado-devel mailing list. To
maintain consistency, the committed version has been expanded to include
files not originally included in the original patch.

Line 
1 /*
2  * Copyright (C) 2013      by Takashi Sakamoto
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 #include "normal_avdevice.h"
26
27 namespace BeBoB {
28 namespace MAudio {
29 namespace Normal {
30
31 Device::Device(DeviceManager& d, ffado_smartptr<ConfigRom>( configRom ),
32                            unsigned int modelId)
33     : BeBoB::Device( d, configRom)
34 {
35     switch ( modelId ) {
36     case 0x00010046: // fw410
37         m_id = FW_410;
38         break;
39     case 0x00010060: // Audiophile
40         m_id = FW_AUDIOPHILE;
41         break;
42     case 0x00010062: // Solo
43         m_id = FW_SOLO;
44         break;
45     case 0x0000000a:
46         m_id = FW_OZONIC;
47         break;
48     }
49     updateClkSrc();
50
51     debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::MAudio::Normal::Device (NodeID %d)\n",
52                  getConfigRom().getNodeId() );
53 }
54
55 Device::~Device()
56 {
57 }
58
59 void
60 Device::showDevice()
61 {
62     debugOutput(DEBUG_LEVEL_NORMAL, "This is a BeBoB::MAudio::Normal::Device\n");
63     BeBoB::Device::showDevice();
64 }
65
66 bool Device::updateClkSrc()
67 {
68     int plugid;
69
70     m_internal_clksrc.type = FFADODevice::eCT_Internal;
71     m_internal_clksrc.active = false;
72     m_internal_clksrc.valid = true;
73     m_internal_clksrc.locked = true;
74     m_internal_clksrc.id = 0x01;
75     m_internal_clksrc.slipping = false;
76     m_internal_clksrc.description = "Internal";
77
78     m_spdif_clksrc.type = FFADODevice::eCT_SPDIF;
79     m_spdif_clksrc.active = false;
80     m_spdif_clksrc.valid = false;
81     m_spdif_clksrc.locked = false;
82     m_spdif_clksrc.id = 0;
83     m_spdif_clksrc.slipping = false;
84     m_spdif_clksrc.description = "S/PDIF (Coaxial)";
85
86     m_adat_clksrc.type = FFADODevice::eCT_ADAT;
87     m_adat_clksrc.active = false;
88     m_adat_clksrc.valid = false;
89     m_adat_clksrc.locked = false;
90     m_adat_clksrc.id = 0;
91     m_adat_clksrc.slipping = false;
92     m_adat_clksrc.description = "ADAT (Optical)";
93
94     switch (m_id) {
95     case FW_410: // fw410
96         m_spdif_clksrc.active = true;
97         m_spdif_clksrc.valid = true;
98         m_spdif_clksrc.id = 0x82;
99         m_adat_clksrc.active = true;
100         m_adat_clksrc.valid = true;
101         m_adat_clksrc.id = 0x83;
102         break;
103     case FW_AUDIOPHILE: // Audiophile
104         m_spdif_clksrc.active = true;
105         m_spdif_clksrc.valid = true;
106         m_spdif_clksrc.id = 0x82;
107         break;
108     case FW_SOLO: // Solo
109         m_spdif_clksrc.active = true;
110         m_spdif_clksrc.valid = true;
111         m_spdif_clksrc.id = 0x81;
112         break;
113     case FW_OZONIC:
114         /* internal only */
115         m_active_clksrc = &m_internal_clksrc;
116         return true;
117     }
118
119     plugid = getClkSrc();
120     if (plugid < 0)
121         return false;
122
123     if (plugid == 0x01) {
124         m_internal_clksrc.active = true;
125         m_active_clksrc = &m_internal_clksrc;
126     } else if (plugid == 0x83) {
127         m_adat_clksrc.active = true;
128         m_active_clksrc = &m_adat_clksrc;
129     } else {
130         m_spdif_clksrc.active = true;
131         m_active_clksrc = &m_spdif_clksrc;
132     }
133
134     return true;
135 }
136
137 int Device::getClkSrc()
138 {
139     AVC::SignalSourceCmd cmd( get1394Service() );
140     cmd.setCommandType( AVC::AVCCommand::eCT_Status );
141     cmd.setNodeId( getNodeId() );
142     cmd.setSubunitType( AVC::eST_Unit  );
143     cmd.setSubunitId( 0xff );
144     cmd.setVerbose( getDebugLevel() );
145
146     AVC::SignalSubunitAddress dst;
147     dst.m_subunitType = AVC::eST_Music;
148     dst.m_subunitId = 0x00;
149     dst.m_plugId = 0x01;
150     cmd.setSignalDestination( dst );
151
152     if ( !cmd.fire() ) {
153         debugError( "Signal source command failed\n" );
154         return -1;
155     }
156     AVC::SignalAddress* pSyncPlugSignalAddress = cmd.getSignalSource();
157
158     AVC::SignalSubunitAddress* pSyncPlugSubunitAddress
159         = dynamic_cast<AVC::SignalSubunitAddress*>( pSyncPlugSignalAddress );
160     if ( pSyncPlugSubunitAddress ) {
161         debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
162                     ( pSyncPlugSubunitAddress->m_subunitType << 3
163                       | pSyncPlugSubunitAddress->m_subunitId ) << 8
164                     | pSyncPlugSubunitAddress->m_plugId );
165         return pSyncPlugSubunitAddress->m_plugId;
166     }
167
168     AVC::SignalUnitAddress* pSyncPlugUnitAddress
169       = dynamic_cast<AVC::SignalUnitAddress*>( pSyncPlugSignalAddress );
170     if ( pSyncPlugUnitAddress ) {
171         debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
172                       0xff << 8 | pSyncPlugUnitAddress->m_plugId );
173         return pSyncPlugUnitAddress->m_plugId;
174     }
175
176     debugError( "Could not retrieve sync mode\n" );
177     return -1;
178 }
179
180 FFADODevice::ClockSourceVector
181 Device::getSupportedClockSources() {
182     FFADODevice::ClockSourceVector r;
183
184     r.push_back(m_internal_clksrc);
185
186     if (m_spdif_clksrc.active)
187         r.push_back(m_spdif_clksrc);
188
189     if (m_adat_clksrc.active)
190         r.push_back(m_adat_clksrc);
191
192     return r;
193 }
194
195 FFADODevice::ClockSource
196 Device::getActiveClockSource()
197 {
198     if (!updateClkSrc()) {
199         ClockSource s;
200         s.type = eCT_Invalid;
201         return s;
202     }
203     return *m_active_clksrc;
204 }
205
206 bool
207 Device::setActiveClockSource(ClockSource s)
208 {
209         AVC::SignalSourceCmd cmd( get1394Service() );
210     cmd.setCommandType( AVC::AVCCommand::eCT_Control );
211     cmd.setNodeId( getNodeId() );
212     cmd.setSubunitType( AVC::eST_Unit  );
213     cmd.setSubunitId( 0xff );
214     cmd.setVerbose( getDebugLevel() );
215
216     AVC::SignalSubunitAddress dst;
217     dst.m_subunitType = AVC::eST_Music;
218     dst.m_subunitId = 0x00;
219     dst.m_plugId = 0x01;
220     cmd.setSignalDestination( dst );
221
222     if (s.id == 0x01) {
223         AVC::SignalSubunitAddress src;
224         src.m_subunitType = AVC::eST_Music;
225         src.m_subunitId = 0x00;
226         src.m_plugId = 0x01;
227         cmd.setSignalSource( src );
228     } else {
229         AVC::SignalUnitAddress src;
230         src.m_plugId = s.id;
231         cmd.setSignalSource( src );
232     }
233
234     if ( !cmd.fire() ) {
235         debugError( "Signal source command failed\n" );
236         return false;
237     }
238
239     return true;
240 }
241
242 } // namespace Normal
243 } // namespace MAudio
244 } // namespace BeBoB
Note: See TracBrowser for help on using the browser.