[BeBoB/MAudio] Add PreSonus::FireboxDevice class to support functionality to switch...
[ffado.git] / libffado / src / bebob / presonus / presonus_avdevice.cpp
blob79d20aa8be1c1341e2e82343b01e72fa5febe637
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 "presonus_avdevice.h"
27 namespace BeBoB {
28 namespace Presonus {
30 FireboxDevice::FireboxDevice(DeviceManager& d, std::auto_ptr<ConfigRom>(configRom))
31 : BeBoB::Device( d, configRom)
33 m_intl_clksrc.type = FFADODevice::eCT_Internal;
34 m_intl_clksrc.valid = true;
35 m_intl_clksrc.locked = true;
36 m_intl_clksrc.id = 0x00;
37 m_intl_clksrc.slipping = false;
38 m_intl_clksrc.description = "Internal";
40 m_spdif_clksrc.type = FFADODevice::eCT_SPDIF;
41 m_spdif_clksrc.valid = true;
42 m_spdif_clksrc.locked = true;
43 m_spdif_clksrc.id = 0x01;
44 m_spdif_clksrc.slipping = false;
45 m_spdif_clksrc.description = "S/PDIF (Coaxial)";
47 debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Presonus::FireboxDevice (NodeID %d)\n",
48 getConfigRom().getNodeId() );
51 FireboxDevice::~FireboxDevice()
55 void
56 FireboxDevice::showDevice()
58 debugOutput(DEBUG_LEVEL_NORMAL, "This is a BeBoB::Presonus::FireboxDevice\n");
59 BeBoB::Device::showDevice();
62 FFADODevice::ClockSourceVector
63 FireboxDevice::getSupportedClockSources()
65 FFADODevice::ClockSourceVector r;
66 r.push_back(m_intl_clksrc);
67 r.push_back(m_spdif_clksrc);
68 return r;
71 enum FFADODevice::eClockSourceType
72 FireboxDevice::getClkSrc()
74 AVC::SignalSourceCmd cmd(get1394Service());
75 cmd.setCommandType(AVC::AVCCommand::eCT_Status);
76 cmd.setNodeId(getNodeId());
77 cmd.setSubunitType(AVC::eST_Unit);
78 cmd.setSubunitId(0xff);
79 cmd.setVerbose(getDebugLevel());
81 AVC::SignalSubunitAddress dst;
82 dst.m_subunitType = AVC::eST_Music;
83 dst.m_subunitId = 0x00;
84 dst.m_plugId = 0x05;
85 cmd.setSignalDestination(dst);
87 if (!cmd.fire()) {
88 debugError( "Signal source command failed\n" );
89 return eCT_Invalid;
91 AVC::SignalAddress* pSyncPlugSignalAddress = cmd.getSignalSource();
93 AVC::SignalSubunitAddress* pSyncPlugSubunitAddress
94 = dynamic_cast<AVC::SignalSubunitAddress*>( pSyncPlugSignalAddress );
95 if (pSyncPlugSubunitAddress) {
96 debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
97 ( pSyncPlugSubunitAddress->m_subunitType << 3
98 | pSyncPlugSubunitAddress->m_subunitId ) << 8
99 | pSyncPlugSubunitAddress->m_plugId );
100 return eCT_Internal;
103 AVC::SignalUnitAddress* pSyncPlugUnitAddress
104 = dynamic_cast<AVC::SignalUnitAddress*>( pSyncPlugSignalAddress );
105 if (pSyncPlugUnitAddress) {
106 debugOutput(DEBUG_LEVEL_VERBOSE, "Sync mode 0x%02x\n",
107 0xff << 8 | pSyncPlugUnitAddress->m_plugId );
108 return eCT_SPDIF;
111 debugError( "Could not retrieve sync mode\n" );
112 return eCT_Invalid;
115 FFADODevice::ClockSource
116 FireboxDevice::getActiveClockSource()
118 switch (getClkSrc()) {
119 case eCT_Internal:
120 m_intl_clksrc.active = true;
121 m_spdif_clksrc.active = false;
122 return m_intl_clksrc;
123 case eCT_SPDIF:
124 m_intl_clksrc.active = false;
125 m_spdif_clksrc.active = true;
126 return m_spdif_clksrc;
127 default:
128 ClockSource s;
129 s.type = eCT_Invalid;
130 return s;
134 bool
135 FireboxDevice::setActiveClockSource(ClockSource s)
137 AVC::SignalSourceCmd cmd(get1394Service());
138 cmd.setCommandType(AVC::AVCCommand::eCT_Control);
139 cmd.setNodeId(getNodeId());
140 cmd.setSubunitType(AVC::eST_Unit);
141 cmd.setSubunitId(0xff);
142 cmd.setVerbose(getDebugLevel());
144 AVC::SignalSubunitAddress dst;
145 dst.m_subunitType = AVC::eST_Music;
146 dst.m_subunitId = 0x00;
147 dst.m_plugId = 0x05;
148 cmd.setSignalDestination(dst);
150 if (s.id == 0x00) {
151 AVC::SignalSubunitAddress src;
152 src.m_subunitType = AVC::eST_Music;
153 src.m_subunitId = 0x00;
154 src.m_plugId = 0x06;
155 cmd.setSignalSource( src );
156 } else {
157 AVC::SignalUnitAddress src;
158 src.m_plugId = 0x83;
159 cmd.setSignalSource(src);
162 if (!cmd.fire()) {
163 debugError( "Signal source command failed\n" );
164 return false;
167 return true;
170 } // namespace Presonus
171 } // namespace BeBoB