motu: the 4pre channel layout within packets is now believed to be correct. Thanks...
[ffado.git] / libffado / src / fireworks / efc / efc_cmds_hardware_ctrl.cpp
blob1914c5a9d603089ccb981ae9023bd0bccf947039
1 /*
2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) version 3 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "efc_cmd.h"
25 #include "efc_cmds_hardware_ctrl.h"
27 #include "libutil/ByteSwap.h"
28 #include <iostream>
29 #include <unistd.h>
31 using namespace std;
33 namespace FireWorks {
35 EfcGetClockCmd::EfcGetClockCmd()
36 : EfcCmd(EFC_CAT_HARDWARE_CONTROL, EFC_CMD_HWCTRL_GET_CLOCK)
37 , m_clock ( EFC_CMD_HW_CLOCK_UNSPECIFIED )
38 , m_samplerate ( EFC_CMD_HW_CLOCK_UNSPECIFIED )
39 , m_index ( 0 )
43 bool
44 EfcGetClockCmd::serialize( Util::Cmd::IOSSerialize& se )
46 bool result=true;
48 // the length should be specified before
49 // the header is serialized
50 m_length=EFC_HEADER_LENGTH_QUADLETS;
52 result &= EfcCmd::serialize ( se );
54 return result;
57 bool
58 EfcGetClockCmd::deserialize( Util::Cmd::IISDeserialize& de )
60 bool result=true;
62 result &= EfcCmd::deserialize ( de );
64 EFC_DESERIALIZE_AND_SWAP(de, &m_clock, result);
65 EFC_DESERIALIZE_AND_SWAP(de, &m_samplerate, result);
66 EFC_DESERIALIZE_AND_SWAP(de, &m_index, result);
68 return result;
71 void
72 EfcGetClockCmd::showEfcCmd()
74 EfcCmd::showEfcCmd();
75 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Get Clock:\n");
76 debugOutput(DEBUG_LEVEL_NORMAL, " Clock : %u\n", m_clock);
77 debugOutput(DEBUG_LEVEL_NORMAL, " Samplerate : %u\n", m_samplerate);
78 debugOutput(DEBUG_LEVEL_NORMAL, " Index : %u\n", m_index);
81 // ----
82 EfcSetClockCmd::EfcSetClockCmd()
83 : EfcCmd(EFC_CAT_HARDWARE_CONTROL, EFC_CMD_HWCTRL_SET_CLOCK)
84 , m_clock ( EFC_CMD_HW_CLOCK_UNSPECIFIED )
85 , m_samplerate ( EFC_CMD_HW_CLOCK_UNSPECIFIED )
86 , m_index ( 0 )
90 bool
91 EfcSetClockCmd::serialize( Util::Cmd::IOSSerialize& se )
93 bool result=true;
95 // the length should be specified before
96 // the header is serialized
97 m_length=EFC_HEADER_LENGTH_QUADLETS+3;
99 result &= EfcCmd::serialize ( se );
101 result &= se.write(CondSwapToBus32(m_clock), "Clock" );
102 result &= se.write(CondSwapToBus32(m_samplerate), "Samplerate" );
103 result &= se.write(CondSwapToBus32(m_index), "Index" );
105 return result;
108 bool
109 EfcSetClockCmd::deserialize( Util::Cmd::IISDeserialize& de )
111 bool result=true;
113 result &= EfcCmd::deserialize ( de );
115 EFC_DESERIALIZE_AND_SWAP(de, &m_clock, result);
116 EFC_DESERIALIZE_AND_SWAP(de, &m_samplerate, result);
117 EFC_DESERIALIZE_AND_SWAP(de, &m_index, result);
120 * With firmware version 5.8, after setting, approximately 100ms needs to
121 * get it effective. If getting command is executed during this period,
122 * previous value is returned. This is a simple hack for this issue.
124 usleep(150000);
126 return result;
129 void
130 EfcSetClockCmd::showEfcCmd()
132 EfcCmd::showEfcCmd();
133 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Set Clock:\n");
134 debugOutput(DEBUG_LEVEL_NORMAL, " Clock : %u\n", m_clock);
135 debugOutput(DEBUG_LEVEL_NORMAL, " Samplerate : %u\n", m_samplerate);
136 debugOutput(DEBUG_LEVEL_NORMAL, " Index : %u\n", m_index);
139 // ----
140 EfcPhyReconnectCmd::EfcPhyReconnectCmd()
141 : EfcCmd(EFC_CAT_HARDWARE_CONTROL, EFC_CMD_HWCTRL_RECONNECT_PHY)
145 bool
146 EfcPhyReconnectCmd::serialize( Util::Cmd::IOSSerialize& se )
148 bool result=true;
150 // the length should be specified before
151 // the header is serialized
152 m_length=EFC_HEADER_LENGTH_QUADLETS;
154 result &= EfcCmd::serialize ( se );
156 return result;
159 bool
160 EfcPhyReconnectCmd::deserialize( Util::Cmd::IISDeserialize& de )
162 bool result=true;
164 result &= EfcCmd::deserialize ( de );
166 return result;
169 void
170 EfcPhyReconnectCmd::showEfcCmd()
172 EfcCmd::showEfcCmd();
173 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Phy Reconnect\n");
176 // -- get flags
177 EfcGetFlagsCmd::EfcGetFlagsCmd()
178 : EfcCmd(EFC_CAT_HARDWARE_CONTROL, EFC_CMD_HWCTRL_GET_FLAGS)
179 , m_flags ( 0 )
183 bool
184 EfcGetFlagsCmd::serialize( Util::Cmd::IOSSerialize& se )
186 bool result=true;
188 // the length should be specified before
189 // the header is serialized
190 m_length=EFC_HEADER_LENGTH_QUADLETS;
192 result &= EfcCmd::serialize ( se );
194 return result;
197 bool
198 EfcGetFlagsCmd::deserialize( Util::Cmd::IISDeserialize& de )
200 bool result=true;
202 result &= EfcCmd::deserialize ( de );
204 EFC_DESERIALIZE_AND_SWAP(de, &m_flags, result);
206 return result;
209 void
210 EfcGetFlagsCmd::showEfcCmd()
212 EfcCmd::showEfcCmd();
213 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Get Flags:\n");
214 debugOutput(DEBUG_LEVEL_NORMAL, " Flags : %08X\n", m_flags);
217 // ----
218 EfcChangeFlagsCmd::EfcChangeFlagsCmd()
219 : EfcCmd(EFC_CAT_HARDWARE_CONTROL, EFC_CMD_HWCTRL_CHANGE_FLAGS)
220 , m_setmask ( 0 )
221 , m_clearmask ( 0 )
225 bool
226 EfcChangeFlagsCmd::serialize( Util::Cmd::IOSSerialize& se )
228 bool result=true;
230 // the length should be specified before
231 // the header is serialized
232 m_length=EFC_HEADER_LENGTH_QUADLETS+2;
234 result &= EfcCmd::serialize ( se );
236 result &= se.write(CondSwapToBus32(m_setmask), "SetMask" );
237 result &= se.write(CondSwapToBus32(m_clearmask), "ClearMask" );
239 return result;
242 bool
243 EfcChangeFlagsCmd::deserialize( Util::Cmd::IISDeserialize& de )
245 bool result=true;
246 result &= EfcCmd::deserialize ( de );
247 return result;
250 void
251 EfcChangeFlagsCmd::showEfcCmd()
253 EfcCmd::showEfcCmd();
254 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Change flags:\n");
255 debugOutput(DEBUG_LEVEL_NORMAL, " Set mask : %08X\n", m_setmask);
256 debugOutput(DEBUG_LEVEL_NORMAL, " Clear mask : %08X\n", m_clearmask);
260 // ----
261 EfcIdentifyCmd::EfcIdentifyCmd()
262 : EfcCmd(EFC_CAT_HARDWARE_CONTROL, EFC_CMD_HWCTRL_IDENTIFY)
266 bool
267 EfcIdentifyCmd::serialize( Util::Cmd::IOSSerialize& se )
269 bool result=true;
271 // the length should be specified before
272 // the header is serialized
273 m_length=EFC_HEADER_LENGTH_QUADLETS;
275 result &= EfcCmd::serialize ( se );
277 return result;
280 bool
281 EfcIdentifyCmd::deserialize( Util::Cmd::IISDeserialize& de )
283 bool result=true;
285 result &= EfcCmd::deserialize ( de );
287 return result;
290 void
291 EfcIdentifyCmd::showEfcCmd()
293 EfcCmd::showEfcCmd();
294 debugOutput(DEBUG_LEVEL_NORMAL, "EFC Identify\n");
297 } // namespace FireWorks