root/trunk/libffado/src/dice/dice_avdevice.h

Revision 1550, 10.3 kB (checked in by ppalmers, 15 years ago)

- Implement basic HSS1394 support for the Stanton SCS devices
- Start of the implementation of a generic TCAT DICE EAP control
- Reworked part of the busreset / ARM handler code

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  */
23
24 #ifndef DICEDEVICE_H
25 #define DICEDEVICE_H
26
27 #include "ffadodevice.h"
28
29 #include "debugmodule/debugmodule.h"
30 #include "libavc/avc_definitions.h"
31
32 #include "libstreaming/amdtp/AmdtpReceiveStreamProcessor.h"
33 #include "libstreaming/amdtp/AmdtpTransmitStreamProcessor.h"
34 #include "libstreaming/amdtp/AmdtpPort.h"
35
36 #include "libieee1394/ieee1394service.h"
37
38 #include <string>
39 #include <vector>
40
41 class ConfigRom;
42 class Ieee1394Service;
43
44 namespace Util {
45     class Configuration;
46 }
47
48 namespace Dice {
49
50 class Notifier;
51
52 class Device : public FFADODevice {
53 // private:
54 public:
55     class Notifier;
56     class EAP;
57
58 public:
59     Device( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
60     ~Device();
61
62     static bool probe( Util::Configuration& c, ConfigRom& configRom, bool generic = false );
63     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
64     virtual bool discover();
65
66     static int getConfigurationId( );
67
68     virtual void showDevice();
69
70     virtual bool setSamplingFrequency( int samplingFrequency );
71     virtual int getSamplingFrequency( );
72     virtual std::vector<int> getSupportedSamplingFrequencies();
73
74     virtual ClockSourceVector getSupportedClockSources();
75     virtual bool setActiveClockSource(ClockSource);
76     virtual ClockSource getActiveClockSource();
77
78     virtual int getStreamCount();
79     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
80
81     virtual bool prepare();
82
83     virtual bool lock();
84     virtual bool unlock();
85
86     virtual bool startStreamByIndex(int i);
87     virtual bool stopStreamByIndex(int i);
88
89     virtual bool enableStreaming();
90     virtual bool disableStreaming();
91
92     virtual std::string getNickname();
93     virtual bool setNickname(std::string name);
94
95 protected:
96
97     // streaming stuff
98     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
99     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
100     StreamProcessorVector m_receiveProcessors;
101     StreamProcessorVector m_transmitProcessors;
102
103 private: // streaming & port helpers
104     enum EPortTypes {
105         ePT_Analog,
106         ePT_MIDI,
107     };
108
109     typedef struct {
110         std::string name;
111         enum EPortTypes portType;
112         unsigned int streamPosition;
113         unsigned int streamLocation;
114     } diceChannelInfo;
115
116     bool addChannelToProcessor( diceChannelInfo *,
117                               Streaming::StreamProcessor *,
118                               Streaming::Port::E_Direction direction);
119
120     int allocateIsoChannel(unsigned int packet_size);
121     bool deallocateIsoChannel(int channel);
122
123 private: // helper functions
124     bool enableIsoStreaming();
125     bool disableIsoStreaming();
126     bool isIsoStreamingEnabled();
127
128     bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
129     bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
130
131     typedef std::vector< std::string > diceNameVector;
132     typedef std::vector< std::string >::iterator diceNameVectorIterator;
133     diceNameVector splitNameString(std::string in);
134     diceNameVector getTxNameString(unsigned int i);
135     diceNameVector getRxNameString(unsigned int i);
136     diceNameVector getClockSourceNameString();
137     std::string getDeviceNickName();
138     bool setDeviceNickName(std::string name);
139
140     enum eClockSourceType  clockIdToType(unsigned int id);
141     bool isClockSourceIdLocked(unsigned int id, quadlet_t ext_status_reg);
142     bool isClockSourceIdSlipping(unsigned int id, quadlet_t ext_status_reg);
143
144 private: // register I/O routines
145     bool initIoFunctions();
146     // quadlet read/write routines
147     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
148     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
149     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
150     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
151
152     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
153     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
154     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
155     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
156     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
157
158     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
159     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
160     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
161     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
162     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
163
164     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
165     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
166     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
167     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
168     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
169
170     fb_quadlet_t m_global_reg_offset;
171     fb_quadlet_t m_global_reg_size;
172     fb_quadlet_t m_tx_reg_offset;
173     fb_quadlet_t m_tx_reg_size;
174     fb_quadlet_t m_rx_reg_offset;
175     fb_quadlet_t m_rx_reg_size;
176     fb_quadlet_t m_unused1_reg_offset;
177     fb_quadlet_t m_unused1_reg_size;
178     fb_quadlet_t m_unused2_reg_offset;
179     fb_quadlet_t m_unused2_reg_size;
180
181     fb_quadlet_t m_nb_tx;
182     fb_quadlet_t m_tx_size;
183     fb_quadlet_t m_nb_rx;
184     fb_quadlet_t m_rx_size;
185
186 // private:
187 public:
188     // notification
189     Notifier *m_notifier;
190
191     /**
192      * this class reacts on the DICE device writing to the
193      * hosts notify address
194      */
195     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
196     #define DICE_NOTIFIER_BLOCK_LENGTH 4
197     class Notifier : public Ieee1394Service::ARMHandler
198     {
199     public:
200         Notifier(Device &, nodeaddr_t start);
201         virtual ~Notifier();
202
203     private:
204         Device &m_device;
205     };
206
207     /**
208      * this class represents the EAP interface
209      * available on some devices
210      */
211     class EAP
212     {
213     public:
214         class Router;
215         class Mixer;
216
217     private:
218         enum eWaitReturn {
219             eWR_Error,
220             eWR_Timeout,
221             eWR_Busy,
222             eWR_Done,
223         };
224         enum eRegBase {
225             eRT_Base,
226             eRT_Capability,
227             eRT_Command,
228             eRT_Mixer,
229             eRT_Peak,
230             eRT_NewRouting,
231             eRT_NewStreamCfg,
232             eRT_CurrentCfg,
233             eRT_Standalone,
234             eRT_Application,
235         };
236
237     public:
238         EAP(Device &);
239         virtual ~EAP();
240
241         static bool supportsEAP(Device &);
242         bool init();
243
244         void show();
245         enum eWaitReturn operationBusy();
246         enum eWaitReturn waitForOperationEnd(int max_wait_time_ms = 100);
247         bool loadRouterConfig(bool low, bool mid, bool high);
248         bool loadStreamConfig(bool low, bool mid, bool high);
249         bool loadRouterAndStreamConfig(bool low, bool mid, bool high);
250         bool loadFlashConfig();
251         bool storeFlashConfig();
252        
253     private:
254         bool     m_router_exposed;
255         bool     m_router_readonly;
256         bool     m_router_flashstored;
257         uint16_t m_router_nb_entries;
258
259         bool     m_mixer_exposed;
260         bool     m_mixer_readonly;
261         bool     m_mixer_flashstored;
262         uint8_t  m_mixer_input_id;
263         uint8_t  m_mixer_output_id;
264         uint8_t  m_mixer_nb_inputs;
265         uint8_t  m_mixer_nb_outputs;
266
267         bool     m_general_support_dynstream;
268         bool     m_general_support_flash;
269         bool     m_general_peak_enabled;
270         uint8_t  m_general_max_tx;
271         uint8_t  m_general_max_rx;
272         bool     m_general_stream_cfg_stored;
273         uint16_t m_general_chip;
274
275         bool commandHelper(fb_quadlet_t cmd);
276
277         bool readReg(enum eRegBase, unsigned offset, quadlet_t *);
278         bool writeReg(enum eRegBase, unsigned offset, quadlet_t);
279         bool readRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
280         bool writeRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
281         bool readRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
282         bool writeRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
283         fb_nodeaddr_t offsetGen(enum eRegBase, unsigned, size_t);
284
285         Device &m_device;
286         DECLARE_DEBUG_MODULE_REFERENCE;
287
288         fb_quadlet_t m_capability_offset;
289         fb_quadlet_t m_capability_size;
290         fb_quadlet_t m_cmd_offset;
291         fb_quadlet_t m_cmd_size;
292         fb_quadlet_t m_mixer_offset;
293         fb_quadlet_t m_mixer_size;
294         fb_quadlet_t m_peak_offset;
295         fb_quadlet_t m_peak_size;
296         fb_quadlet_t m_new_routing_offset;
297         fb_quadlet_t m_new_routing_size;
298         fb_quadlet_t m_new_stream_cfg_offset;
299         fb_quadlet_t m_new_stream_cfg_size;
300         fb_quadlet_t m_curr_cfg_offset;
301         fb_quadlet_t m_curr_cfg_size;
302         fb_quadlet_t m_standalone_offset;
303         fb_quadlet_t m_standalone_size;
304         fb_quadlet_t m_app_offset;
305         fb_quadlet_t m_app_size;
306
307     public: // mixer subclass
308         class Mixer {
309         public:
310             Mixer(EAP &);
311             ~Mixer();
312
313             bool init();
314             void show();
315             bool updateCoefficients();
316
317         private:
318             EAP &m_parent;
319             fb_quadlet_t *m_coeff;
320
321             DECLARE_DEBUG_MODULE_REFERENCE;
322         };
323
324         class Router {
325         public:
326             Router(EAP &);
327             ~Router();
328
329             bool init();
330             void show();
331
332         private:
333             EAP &m_parent;
334
335             DECLARE_DEBUG_MODULE_REFERENCE;
336         };
337
338     };
339
340 };
341
342 }
343 #endif
Note: See TracBrowser for help on using the browser.