BeBoB: add Firebox/Inspire1394 namespace under PreSonus namespace
[ffado.git] / libffado / src / bebob / presonus / firebox_avdevice.cpp
blobe430d72504a53bc0b2db3a86eece32a33c1f6e85
1 /*
2 * Copyright (C) 2013 by Takashi Sakamoto
3 * Copyright (C) 2005-2008 by Pieter Palmers
5 * This file is part of FFADO
6 * FFADO = Free Firewire (pro-)audio drivers for linux
8 * FFADO is based upon FreeBoB.
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.
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.
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/>.
25 #include "firebox_avdevice.h"
27 namespace BeBoB {
28 namespace Presonus {
29 namespace Firebox {
31 Device::Device(DeviceManager& d, std::auto_ptr<ConfigRom>(configRom))
32 : BeBoB::Device( d, configRom)
34 m_intl_clksrc.type = FFADODevice::eCT_Internal;
35 m_intl_clksrc.valid = true;
36 m_intl_clksrc.locked = true;
37 m_intl_clksrc.id = 0x00;
38 m_intl_clksrc.slipping = false;
39 m_intl_clksrc.description = "Internal";
41 m_spdif_clksrc.type = FFADODevice::eCT_SPDIF;
42 m_spdif_clksrc.valid = true;
43 m_spdif_clksrc.locked = true;
44 m_spdif_clksrc.id = 0x01;
45 m_spdif_clksrc.slipping = false;
46 m_spdif_clksrc.description = "S/PDIF (Coaxial)";
48 debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Presonus::Firebox::Device (NodeID %d)\n",
49 getConfigRom().getNodeId() );
52 Device::~Device()
56 void
57 Device::showDevice()
59 debugOutput(DEBUG_LEVEL_NORMAL, "This is a BeBoB::Presonus::Firebox::Device\n");
60 BeBoB::Device::showDevice();
63 FFADODevice::ClockSourceVector
64 Device::getSupportedClockSources()
66 FFADODevice::ClockSourceVector r;
67 r.push_back(m_intl_clksrc);
68 r.push_back(m_spdif_clksrc);
69 return r;
72 enum FFADODevice::eClockSourceType
73 Device::getClkSrc()
75 AVC::SignalSourceCmd cmd(get1394Service());
76 cmd.setCommandType(AVC::AVCCommand::eCT_Status);
77 cmd.setNodeId(getNodeId());
78 cmd.setSubunitType(AVC::eST_Unit);
79 cmd.setSubunitId(0xff);
80 cmd.setVerbose(getDebugLevel());
82 AVC::SignalSubunitAddress dst;
83 dst.m_subunitType = AVC::eST_Music;
84 dst.m_subunitId = 0x00;
85 dst.m_plugId = 0x05;
86 cmd.setSignalDestination(dst);
88 if (!cmd.fire()) {
89 debugError( "Signal source command failed\n" );
90 return eCT_Invalid;
92 AVC::SignalAddress* pSyncPlugSignalAddress = cmd.getSignalSource();
94 AVC::SignalSubunitAddress* pSyncPlugSubunitAddress
95 = dynamic_cast<AVC::SignalSubunitAddress*>( pSyncPlugSignalAddress );
96 if (pSyncPlugSubunitAddress) {
97 debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
98 ( pSyncPlugSubunitAddress->m_subunitType << 3
99 | pSyncPlugSubunitAddress->m_subunitId ) << 8
100 | pSyncPlugSubunitAddress->m_plugId );
101 return eCT_Internal;
104 AVC::SignalUnitAddress* pSyncPlugUnitAddress
105 = dynamic_cast<AVC::SignalUnitAddress*>( pSyncPlugSignalAddress );
106 if (pSyncPlugUnitAddress) {
107 debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
108 0xff << 8 | pSyncPlugUnitAddress->m_plugId );
109 return eCT_SPDIF;
112 debugError( "Could not retrieve sync mode\n" );
113 return eCT_Invalid;
116 FFADODevice::ClockSource
117 Device::getActiveClockSource()
119 switch (getClkSrc()) {
120 case eCT_Internal:
121 m_intl_clksrc.active = true;
122 m_spdif_clksrc.active = false;
123 return m_intl_clksrc;
124 case eCT_SPDIF:
125 m_intl_clksrc.active = false;
126 m_spdif_clksrc.active = true;
127 return m_spdif_clksrc;
128 default:
129 ClockSource s;
130 s.type = eCT_Invalid;
131 return s;
135 bool
136 Device::setActiveClockSource(ClockSource s)
138 AVC::SignalSourceCmd cmd(get1394Service());
139 cmd.setCommandType(AVC::AVCCommand::eCT_Control);
140 cmd.setNodeId(getNodeId());
141 cmd.setSubunitType(AVC::eST_Unit);
142 cmd.setSubunitId(0xff);
143 cmd.setVerbose(getDebugLevel());
145 AVC::SignalSubunitAddress dst;
146 dst.m_subunitType = AVC::eST_Music;
147 dst.m_subunitId = 0x00;
148 dst.m_plugId = 0x05;
149 cmd.setSignalDestination(dst);
151 if (s.id == 0x00) {
152 AVC::SignalSubunitAddress src;
153 src.m_subunitType = AVC::eST_Music;
154 src.m_subunitId = 0x00;
155 src.m_plugId = 0x06;
156 cmd.setSignalSource( src );
157 } else {
158 AVC::SignalUnitAddress src;
159 src.m_plugId = 0x83;
160 cmd.setSignalSource(src);
163 if (!cmd.fire()) {
164 debugError( "Signal source command failed\n" );
165 return false;
168 return true;
171 } // namespace Firebox
172 } // namespace Presonus
173 } // namespace BeBoB