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/>.
27 #include "dice_firmware_loader.h"
29 #include "ffadotypes.h"
30 #include "ffadodevice.h"
32 #include "debugmodule/debugmodule.h"
33 #include "libavc/avc_definitions.h"
35 #include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
36 #include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
37 #include "libstreaming/amdtp/AmdtpPort.h"
39 #include "libieee1394/ieee1394service.h"
41 #include "libcontrol/Element.h"
42 #include "libcontrol/MatrixMixer.h"
43 #include "libcontrol/CrossbarRouter.h"
49 class Ieee1394Service
;
61 @brief Devices based on the DICE-platform
63 This class is the basic implementation for devices using the DICE-chip.
65 class Device
: public FFADODevice
{
71 Device( DeviceManager
& d
, std::auto_ptr
<ConfigRom
>( configRom
));
75 static bool probe( Util::Configuration
& c
, ConfigRom
& configRom
, bool generic
= false );
76 static FFADODevice
* createDevice( DeviceManager
& d
, std::auto_ptr
<ConfigRom
>( configRom
));
77 virtual bool discover();
79 static int getConfigurationId( );
81 virtual void showDevice();
82 bool canChangeNickname() { return true; }
84 virtual bool deleteImgFL(const char*, bool v
= true);
85 virtual bool flashDiceFL(const char*, const char* image
= "dice");
86 virtual bool dumpFirmwareFL(const char*);
87 virtual bool showDiceInfoFL();
88 virtual bool showImgInfoFL();
89 virtual bool testDiceFL(int);
90 virtual DICE_FL_INFO_PARAM
* showFlashInfoFL(bool v
= true);
91 virtual bool showAppInfoFL();
93 virtual bool setSamplingFrequency( int samplingFrequency
);
94 virtual int getSamplingFrequency( );
95 virtual std::vector
<int> getSupportedSamplingFrequencies();
97 virtual ClockSourceVector
getSupportedClockSources();
98 virtual bool setActiveClockSource(ClockSource
);
99 virtual ClockSource
getActiveClockSource();
101 virtual int getStreamCount();
102 virtual Streaming::StreamProcessor
*getStreamProcessorByIndex(int i
);
103 virtual enum FFADODevice::eStreamingState
getStreamingState();
105 virtual bool prepare();
108 virtual bool unlock();
110 virtual bool startStreamByIndex(int i
);
111 virtual bool stopStreamByIndex(int i
);
113 virtual bool enableStreaming();
114 virtual bool disableStreaming();
116 virtual std::string
getNickname();
117 virtual bool setNickname(std::string name
);
121 typedef std::vector
< Streaming::StreamProcessor
* > StreamProcessorVector
;
122 typedef std::vector
< Streaming::StreamProcessor
* >::iterator StreamProcessorVectorIterator
;
123 StreamProcessorVector m_receiveProcessors
;
124 StreamProcessorVector m_transmitProcessors
;
126 private: // streaming & port helpers
134 enum EPortTypes portType
;
135 unsigned int streamPosition
;
136 unsigned int streamLocation
;
139 bool addChannelToProcessor( diceChannelInfo
*,
140 Streaming::StreamProcessor
*,
141 Streaming::Port::E_Direction direction
);
143 int allocateIsoChannel(unsigned int packet_size
);
144 bool deallocateIsoChannel(int channel
);
146 private: // active config
154 enum eDiceConfig
getCurrentConfig();
156 private: // helper functions
157 bool enableIsoStreaming();
158 bool disableIsoStreaming();
159 bool isIsoStreamingEnabled();
161 bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset
, fb_quadlet_t mask
);
162 bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset
, fb_quadlet_t mask
);
164 stringlist
splitNameString(std::string in
);
165 stringlist
getTxNameString(unsigned int i
);
166 stringlist
getRxNameString(unsigned int i
);
167 stringlist
getCptrNameString(unsigned int);
168 stringlist
getPbckNameString(unsigned int);
169 stringlist
getClockSourceNameString();
171 enum eClockSourceType
clockIdToType(unsigned int id
);
172 bool isClockSourceIdLocked(unsigned int id
, quadlet_t ext_status_reg
);
173 bool isClockSourceIdSlipping(unsigned int id
, quadlet_t ext_status_reg
);
179 virtual EAP
* createEAP();
181 EAP
* getEAP() {return m_eap
;};
183 private: // register I/O routines
184 bool initIoFunctions();
185 // functions used for RX/TX abstraction
186 bool startstopStreamByIndex(int i
, const bool start
);
187 bool prepareSP (unsigned int, const Streaming::Port::E_Direction direction_requested
);
188 void setRXTXfuncs (const Streaming::Port::E_Direction direction
);
190 // quadlet read/write routines
191 bool readReg(fb_nodeaddr_t
, fb_quadlet_t
*);
192 bool writeReg(fb_nodeaddr_t
, fb_quadlet_t
);
193 bool readRegBlock(fb_nodeaddr_t
, fb_quadlet_t
*, size_t);
194 bool writeRegBlock(fb_nodeaddr_t
, fb_quadlet_t
*, size_t);
196 bool readGlobalReg(fb_nodeaddr_t
, fb_quadlet_t
*);
197 bool writeGlobalReg(fb_nodeaddr_t
, fb_quadlet_t
);
198 bool readGlobalRegBlock(fb_nodeaddr_t
, fb_quadlet_t
*, size_t);
199 bool writeGlobalRegBlock(fb_nodeaddr_t
, fb_quadlet_t
*, size_t);
200 fb_nodeaddr_t
globalOffsetGen(fb_nodeaddr_t
, size_t);
202 bool readTxReg(unsigned int i
, fb_nodeaddr_t
, fb_quadlet_t
*);
203 bool writeTxReg(unsigned int i
, fb_nodeaddr_t
, fb_quadlet_t
);
204 bool readTxRegBlock(unsigned int i
, fb_nodeaddr_t offset
, fb_quadlet_t
*data
, size_t length
);
205 bool writeTxRegBlock(unsigned int i
, fb_nodeaddr_t offset
, fb_quadlet_t
*data
, size_t length
);
206 fb_nodeaddr_t
txOffsetGen(unsigned int, fb_nodeaddr_t
, size_t);
208 bool readRxReg(unsigned int i
, fb_nodeaddr_t
, fb_quadlet_t
*);
209 bool writeRxReg(unsigned int i
, fb_nodeaddr_t
, fb_quadlet_t
);
210 bool readRxRegBlock(unsigned int i
, fb_nodeaddr_t offset
, fb_quadlet_t
*data
, size_t length
);
211 bool writeRxRegBlock(unsigned int i
, fb_nodeaddr_t offset
, fb_quadlet_t
*data
, size_t length
);
212 fb_nodeaddr_t
rxOffsetGen(unsigned int, fb_nodeaddr_t
, size_t);
214 fb_quadlet_t m_global_reg_offset
;
215 fb_quadlet_t m_global_reg_size
;
216 fb_quadlet_t m_tx_reg_offset
;
217 fb_quadlet_t m_tx_reg_size
;
218 fb_quadlet_t m_rx_reg_offset
;
219 fb_quadlet_t m_rx_reg_size
;
220 fb_quadlet_t m_unused1_reg_offset
;
221 fb_quadlet_t m_unused1_reg_size
;
222 fb_quadlet_t m_unused2_reg_offset
;
223 fb_quadlet_t m_unused2_reg_size
;
225 fb_quadlet_t m_nb_tx
;
226 fb_quadlet_t m_tx_size
;
227 fb_quadlet_t m_nb_rx
;
228 fb_quadlet_t m_rx_size
;
230 fb_quadlet_t audio_base_register
;
231 fb_quadlet_t midi_base_register
;
234 // Function pointers to call readTxReg/readRxReg or writeTxReg/writeRxReg respectively
235 bool (Device::*writeFunc
) (unsigned int i
, fb_nodeaddr_t offset
, fb_quadlet_t data
);
236 bool (Device::*readFunc
) (unsigned int i
, fb_nodeaddr_t offset
, fb_quadlet_t
*result
);
241 * this class reacts on the DICE device writing to the
242 * hosts notify address
244 #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
245 #define DICE_NOTIFIER_BLOCK_LENGTH 4
247 class Notifier
: public Ieee1394Service::ARMHandler
250 Notifier(Device
&, nodeaddr_t start
);
258 Notifier
*m_notifier
;