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

Revision 1742, 20.3 kB (checked in by arnonym, 11 years ago)

Extend the interface of the MatrixMixer?:

  • Have booleans indicating if names and/or connections are supported. These functions are pure virtual.
  • Allow names and connections to be read and written, the default implementations of these (not anymore pure) virtual functions do nothing and return false or nothing.
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 "libcontrol/Element.h"
39 #include "libcontrol/MatrixMixer.h"
40 #include "libcontrol/CrossbarRouter.h"
41
42 #include "dice_eap.h"
43
44 #include <string>
45 #include <vector>
46
47 class ConfigRom;
48 class Ieee1394Service;
49
50 namespace Util {
51     class Configuration;
52 }
53
54 namespace Dice {
55
56 class Notifier;
57
58 class Device : public FFADODevice {
59 // private:
60     typedef std::vector< std::string > diceNameVector;
61     typedef std::vector< std::string >::iterator diceNameVectorIterator;
62
63 public:
64     class Notifier;
65     class EAP;
66
67     /**
68      * this class represents the EAP interface
69      * available on some devices
70      */
71     class EAP : public Control::Container
72     {
73     public:
74         enum eWaitReturn {
75             eWR_Error,
76             eWR_Timeout,
77             eWR_Busy,
78             eWR_Done,
79         };
80         enum eRegBase {
81             eRT_Base,
82             eRT_Capability,
83             eRT_Command,
84             eRT_Mixer,
85             eRT_Peak,
86             eRT_NewRouting,
87             eRT_NewStreamCfg,
88             eRT_CurrentCfg,
89             eRT_Standalone,
90             eRT_Application,
91             eRT_None,
92         };
93         enum eRouteSource {
94             eRS_AES = 0,
95             eRS_ADAT = 1,
96             eRS_Mixer = 2,
97             eRS_InS0 = 4,
98             eRS_InS1 = 5,
99             eRS_ARM = 10,
100             eRS_ARX0 = 11,
101             eRS_ARX1 = 12,
102             eRS_Muted = 15,
103             eRS_Invalid = 16,
104         };
105         enum eRouteDestination {
106             eRD_AES = 0,
107             eRD_ADAT = 1,
108             eRD_Mixer0 = 2,
109             eRD_Mixer1 = 3,
110             eRD_InS0 = 4,
111             eRD_InS1 = 5,
112             eRD_ARM = 10,
113             eRD_ATX0 = 11,
114             eRD_ATX1 = 12,
115             eRD_Muted = 15,
116             eRD_Invalid = 16,
117         };
118
119     public:
120
121         // ----------
122         class RouterConfig {
123         public:
124             struct Route
125             {
126                 enum eRouteSource src;
127                 int srcChannel;
128                 enum eRouteDestination dst;
129                 int dstChannel;
130                 int peak;
131             };
132             typedef std::vector<RouterConfig::Route> RouteVector;
133             typedef std::vector<RouterConfig::Route>::iterator RouteVectorIterator;
134             RouterConfig(EAP &);
135             RouterConfig(EAP &, enum eRegBase, unsigned int offset);
136             virtual ~RouterConfig();
137
138             virtual bool read() {return read(m_base, m_offset);};
139             virtual bool write() {return write(m_base, m_offset);};
140             virtual bool read(enum eRegBase b, unsigned offset);
141             virtual bool write(enum eRegBase b, unsigned offset);
142             virtual void show();
143
144
145             bool insertRoute(struct Route r)
146                 {return insertRoute(r, m_routes.size());};
147             bool insertRoute(struct Route r, unsigned int index);
148             bool replaceRoute(unsigned int old_index, struct Route new_route);
149             bool replaceRoute(struct Route old_route, struct Route new_route);
150             bool removeRoute(struct Route r);
151             bool removeRoute(unsigned int index);
152             int getRouteIndex(struct Route r);
153             struct Route getRoute(unsigned int index);
154
155             unsigned int getNbRoutes() {return m_routes.size();};
156
157             struct Route getRouteForDestination(enum eRouteDestination dst, int channel);
158             RouteVector getRoutesForSource(enum eRouteSource src, int channel);
159
160             struct Route decodeRoute(uint32_t val);
161             uint32_t encodeRoute(struct Route r);
162         public:
163             static enum eRouteDestination intToRouteDestination(int);
164             static enum eRouteSource intToRouteSource(int);
165         protected:
166             EAP &m_eap;
167             enum eRegBase m_base;
168             unsigned int m_offset;
169             RouteVector m_routes;
170         protected:
171             DECLARE_DEBUG_MODULE_REFERENCE;
172         };
173
174         // ----------
175         // the peak space is a special version of a router config
176         class PeakSpace : public RouterConfig {
177         public:
178             PeakSpace(EAP &p) : RouterConfig(p, eRT_Peak, 0) {};
179             virtual ~PeakSpace() {};
180
181             virtual bool read() {return read(m_base, m_offset);};
182             virtual bool write() {return write(m_base, m_offset);};
183             virtual bool read(enum eRegBase b, unsigned offset);
184             virtual bool write(enum eRegBase b, unsigned offset);
185             virtual void show();
186         };
187
188         // ----------
189         class StreamConfig {
190         public:
191             struct ConfigBlock { // FIXME: somewhere in the DICE avdevice this is present too
192                 uint32_t nb_audio;
193                 uint32_t nb_midi;
194                 uint32_t names[DICE_EAP_CHANNEL_CONFIG_NAMESTR_LEN_QUADS];
195                 uint32_t ac3_map;
196             };
197             void showConfigBlock(struct ConfigBlock &);
198             diceNameVector getNamesForBlock(struct ConfigBlock &b);
199         public:
200             StreamConfig(EAP &, enum eRegBase, unsigned int offset);
201             ~StreamConfig();
202
203             bool read() {return read(m_base, m_offset);};
204             bool write() {return write(m_base, m_offset);};
205             bool read(enum eRegBase b, unsigned offset);
206             bool write(enum eRegBase b, unsigned offset);
207
208             void show();
209
210         private:
211             EAP &m_eap;
212             enum eRegBase m_base;
213             unsigned int m_offset;
214
215             uint32_t m_nb_tx;
216             uint32_t m_nb_rx;
217
218             struct ConfigBlock *m_tx_configs;
219             struct ConfigBlock *m_rx_configs;
220
221             DECLARE_DEBUG_MODULE_REFERENCE;
222         };
223
224     public: // mixer control subclass
225         class Mixer : public Control::MatrixMixer {
226         public:
227             Mixer(EAP &);
228             ~Mixer();
229
230             bool init();
231             void show();
232
233             void updateNameCache();
234             /**
235              * load the coefficients from the device into the local cache
236              * @return
237              */
238             bool loadCoefficients();
239             /**
240              * Stores the coefficients from the cache to the device
241              * @return
242              */
243             bool storeCoefficients();
244
245             virtual int getRowCount( );
246             virtual int getColCount( );
247
248             virtual int canWrite( const int, const int );
249             virtual double setValue( const int, const int, const double );
250             virtual double getValue( const int, const int );
251
252             bool hasNames() const { return false; }
253
254             // TODO: implement connections.
255             bool canConnect() const { return false; }
256
257             // full map updates are unsupported
258             virtual bool getCoefficientMap(int &);
259             virtual bool storeCoefficientMap(int &);
260
261         private:
262             EAP &         m_eap;
263             fb_quadlet_t *m_coeff;
264
265             std::map<int, RouterConfig::Route> m_input_route_map;
266             std::map<int, RouterConfig::RouteVector> m_output_route_map;
267
268             DECLARE_DEBUG_MODULE_REFERENCE;
269         };
270
271         // ----------
272         class Router : public Control::CrossbarRouter {
273         private:
274             struct Source {
275                 std::string name;
276                 enum eRouteSource src;
277                 int srcChannel;
278             };
279             typedef std::vector<Source> SourceVector;
280             typedef std::vector<Source>::iterator SourceVectorIterator;
281
282             struct Destination {
283                 std::string name;
284                 enum eRouteDestination dst;
285                 int dstChannel;
286             };
287             typedef std::vector<Destination> DestinationVector;
288             typedef std::vector<Destination>::iterator DestinationVectorIterator;
289
290         public:
291             Router(EAP &);
292             ~Router();
293
294             void show();
295
296             // to be subclassed by the implementing
297             // devices
298             virtual void setupSources();
299             virtual void setupDestinations();
300
301             void setupDestinationsAddDestination(const char *name, enum eRouteDestination dstid,
302                                                  unsigned int base, unsigned int cnt);
303             void setupSourcesAddSource(const char *name, enum eRouteSource srcid,
304                                        unsigned int base, unsigned int cnt);
305
306             int getDestinationIndex(enum eRouteDestination dstid, int channel);
307             int getSourceIndex(enum eRouteSource srcid, int channel);
308
309             // per-coefficient access
310             virtual std::string getSourceName(const int);
311             virtual std::string getDestinationName(const int);
312             virtual int getSourceIndex(std::string);
313             virtual int getDestinationIndex(std::string);
314             virtual NameVector getSourceNames();
315             virtual NameVector getDestinationNames();
316
317             virtual Control::CrossbarRouter::Groups getSources();
318             virtual Control::CrossbarRouter::Groups getDestinations();
319
320             virtual IntVector getDestinationsForSource(const int);
321             virtual int getSourceForDestination(const int);
322
323             virtual bool canConnect( const int source, const int dest);
324             virtual bool setConnectionState( const int source, const int dest, const bool enable);
325             virtual bool getConnectionState( const int source, const int dest );
326
327             virtual bool canConnect(std::string, std::string);
328             virtual bool setConnectionState(std::string, std::string, const bool enable);
329             virtual bool getConnectionState(std::string, std::string);
330
331             virtual bool clearAllConnections();
332
333             virtual int getNbSources();
334             virtual int getNbDestinations();
335
336             // functions to access the entire routing map at once
337             // idea is that the row/col nodes that are 1 get a routing entry
338             virtual bool getConnectionMap(int *);
339             virtual bool setConnectionMap(int *);
340
341             // peak metering support
342             virtual bool hasPeakMetering();
343             virtual bool getPeakValues(double &) {return false;};
344             virtual double getPeakValue(const int source, const int dest);
345             virtual Control::CrossbarRouter::PeakValues getPeakValues();
346
347         private:
348             EAP &m_eap;
349             // these contain the sources and destinations available for this
350             // router
351             SourceVector      m_sources;
352             DestinationVector m_destinations;
353
354             PeakSpace &m_peak;
355
356             DECLARE_DEBUG_MODULE_REFERENCE;
357         };
358
359     public:
360         EAP(Device &);
361         virtual ~EAP();
362
363         static bool supportsEAP(Device &);
364         bool init();
365
366         void show();
367         void showApplication();
368         enum eWaitReturn operationBusy();
369         enum eWaitReturn waitForOperationEnd(int max_wait_time_ms = 100);
370
371         bool updateConfigurationCache();
372         RouterConfig * getActiveRouterConfig();
373         StreamConfig * getActiveStreamConfig();
374
375         bool updateRouterConfig(RouterConfig&, bool low, bool mid, bool high);
376         bool updateCurrentRouterConfig(RouterConfig&);
377         bool updateStreamConfig(StreamConfig&, bool low, bool mid, bool high);
378         bool updateStreamConfig(RouterConfig&, StreamConfig&, bool low, bool mid, bool high);
379
380         bool loadFlashConfig();
381         bool storeFlashConfig();
382
383     private:
384         bool loadRouterConfig(bool low, bool mid, bool high);
385         bool loadStreamConfig(bool low, bool mid, bool high);
386         bool loadRouterAndStreamConfig(bool low, bool mid, bool high);
387     private:
388         bool     m_router_exposed;
389         bool     m_router_readonly;
390         bool     m_router_flashstored;
391         uint16_t m_router_nb_entries;
392
393         bool     m_mixer_exposed;
394         bool     m_mixer_readonly;
395         bool     m_mixer_flashstored;
396         uint8_t  m_mixer_tx_id;
397         uint8_t  m_mixer_rx_id;
398         uint8_t  m_mixer_nb_tx;
399         uint8_t  m_mixer_nb_rx;
400
401         bool     m_general_support_dynstream;
402         bool     m_general_support_flash;
403         bool     m_general_peak_enabled;
404         uint8_t  m_general_max_tx;
405         uint8_t  m_general_max_rx;
406         bool     m_general_stream_cfg_stored;
407         uint16_t m_general_chip;
408
409         bool commandHelper(fb_quadlet_t cmd);
410
411     public:
412         bool readReg(enum eRegBase, unsigned offset, quadlet_t *);
413         bool writeReg(enum eRegBase, unsigned offset, quadlet_t);
414         bool readRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
415         bool writeRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
416         bool readRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
417         bool writeRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
418         fb_nodeaddr_t offsetGen(enum eRegBase, unsigned, size_t);
419
420     protected:
421         DECLARE_DEBUG_MODULE_REFERENCE;
422
423     private:
424         Device & m_device;
425         Mixer*   m_mixer;
426         Router*  m_router;
427         RouterConfig m_current_cfg_routing_low;
428         RouterConfig m_current_cfg_routing_mid;
429         RouterConfig m_current_cfg_routing_high;
430         StreamConfig m_current_cfg_stream_low;
431         StreamConfig m_current_cfg_stream_mid;
432         StreamConfig m_current_cfg_stream_high;
433     public:
434         Mixer*  getMixer() {return m_mixer;};
435         Router* getRouter() {return m_router;};
436
437     private:
438
439         fb_quadlet_t m_capability_offset;
440         fb_quadlet_t m_capability_size;
441         fb_quadlet_t m_cmd_offset;
442         fb_quadlet_t m_cmd_size;
443         fb_quadlet_t m_mixer_offset;
444         fb_quadlet_t m_mixer_size;
445         fb_quadlet_t m_peak_offset;
446         fb_quadlet_t m_peak_size;
447         fb_quadlet_t m_new_routing_offset;
448         fb_quadlet_t m_new_routing_size;
449         fb_quadlet_t m_new_stream_cfg_offset;
450         fb_quadlet_t m_new_stream_cfg_size;
451         fb_quadlet_t m_curr_cfg_offset;
452         fb_quadlet_t m_curr_cfg_size;
453         fb_quadlet_t m_standalone_offset;
454         fb_quadlet_t m_standalone_size;
455         fb_quadlet_t m_app_offset;
456         fb_quadlet_t m_app_size;
457     };
458
459 public:
460     Device( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
461     ~Device();
462
463     static bool probe( Util::Configuration& c, ConfigRom& configRom, bool generic = false );
464     static FFADODevice * createDevice( DeviceManager& d, std::auto_ptr<ConfigRom>( configRom ));
465     virtual bool discover();
466
467     static int getConfigurationId( );
468
469     virtual void showDevice();
470
471     virtual bool setSamplingFrequency( int samplingFrequency );
472     virtual int getSamplingFrequency( );
473     virtual std::vector<int> getSupportedSamplingFrequencies();
474
475     virtual ClockSourceVector getSupportedClockSources();
476     virtual bool setActiveClockSource(ClockSource);
477     virtual ClockSource getActiveClockSource();
478
479     virtual int getStreamCount();
480     virtual Streaming::StreamProcessor *getStreamProcessorByIndex(int i);
481
482     virtual bool prepare();
483
484     virtual bool lock();
485     virtual bool unlock();
486
487     virtual bool startStreamByIndex(int i);
488     virtual bool stopStreamByIndex(int i);
489
490     virtual bool enableStreaming();
491     virtual bool disableStreaming();
492
493     virtual std::string getNickname();
494     virtual bool setNickname(std::string name);
495
496 protected:
497     // streaming stuff
498     typedef std::vector< Streaming::StreamProcessor * > StreamProcessorVector;
499     typedef std::vector< Streaming::StreamProcessor * >::iterator StreamProcessorVectorIterator;
500     StreamProcessorVector m_receiveProcessors;
501     StreamProcessorVector m_transmitProcessors;
502
503 private: // streaming & port helpers
504     enum EPortTypes {
505         ePT_Analog,
506         ePT_MIDI,
507     };
508
509     typedef struct {
510         std::string name;
511         enum EPortTypes portType;
512         unsigned int streamPosition;
513         unsigned int streamLocation;
514     } diceChannelInfo;
515
516     bool addChannelToProcessor( diceChannelInfo *,
517                               Streaming::StreamProcessor *,
518                               Streaming::Port::E_Direction direction);
519
520     int allocateIsoChannel(unsigned int packet_size);
521     bool deallocateIsoChannel(int channel);
522
523 private: // active config
524     enum eDiceConfig {
525         eDC_Unknown,
526         eDC_Low,
527         eDC_Mid,
528         eDC_High,
529     };
530
531     enum eDiceConfig getCurrentConfig();
532
533 private: // helper functions
534     bool enableIsoStreaming();
535     bool disableIsoStreaming();
536     bool isIsoStreamingEnabled();
537
538     bool maskedCheckZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
539     bool maskedCheckNotZeroGlobalReg(fb_nodeaddr_t offset, fb_quadlet_t mask);
540
541     diceNameVector splitNameString(std::string in);
542     diceNameVector getTxNameString(unsigned int i);
543     diceNameVector getRxNameString(unsigned int i);
544     diceNameVector getClockSourceNameString();
545     std::string getDeviceNickName();
546     bool setDeviceNickName(std::string name);
547
548     enum eClockSourceType  clockIdToType(unsigned int id);
549     bool isClockSourceIdLocked(unsigned int id, quadlet_t ext_status_reg);
550     bool isClockSourceIdSlipping(unsigned int id, quadlet_t ext_status_reg);
551
552 // EAP stuff
553 private:
554     EAP*         m_eap;
555 protected:
556     virtual EAP* createEAP();
557 public:
558     EAP* getEAP() {return m_eap;};
559
560 private: // register I/O routines
561     bool initIoFunctions();
562     // quadlet read/write routines
563     bool readReg(fb_nodeaddr_t, fb_quadlet_t *);
564     bool writeReg(fb_nodeaddr_t, fb_quadlet_t);
565     bool readRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
566     bool writeRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
567
568     bool readGlobalReg(fb_nodeaddr_t, fb_quadlet_t *);
569     bool writeGlobalReg(fb_nodeaddr_t, fb_quadlet_t);
570     bool readGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
571     bool writeGlobalRegBlock(fb_nodeaddr_t, fb_quadlet_t *, size_t);
572     fb_nodeaddr_t globalOffsetGen(fb_nodeaddr_t, size_t);
573
574     bool readTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
575     bool writeTxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
576     bool readTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
577     bool writeTxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
578     fb_nodeaddr_t txOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
579
580     bool readRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t *);
581     bool writeRxReg(unsigned int i, fb_nodeaddr_t, fb_quadlet_t);
582     bool readRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
583     bool writeRxRegBlock(unsigned int i, fb_nodeaddr_t offset, fb_quadlet_t *data, size_t length);
584     fb_nodeaddr_t rxOffsetGen(unsigned int, fb_nodeaddr_t, size_t);
585
586     fb_quadlet_t m_global_reg_offset;
587     fb_quadlet_t m_global_reg_size;
588     fb_quadlet_t m_tx_reg_offset;
589     fb_quadlet_t m_tx_reg_size;
590     fb_quadlet_t m_rx_reg_offset;
591     fb_quadlet_t m_rx_reg_size;
592     fb_quadlet_t m_unused1_reg_offset;
593     fb_quadlet_t m_unused1_reg_size;
594     fb_quadlet_t m_unused2_reg_offset;
595     fb_quadlet_t m_unused2_reg_size;
596
597     fb_quadlet_t m_nb_tx;
598     fb_quadlet_t m_tx_size;
599     fb_quadlet_t m_nb_rx;
600     fb_quadlet_t m_rx_size;
601
602 // private:
603 public:
604     // notification
605     Notifier *m_notifier;
606
607     /**
608      * this class reacts on the DICE device writing to the
609      * hosts notify address
610      */
611     #define DICE_NOTIFIER_BASE_ADDRESS 0x0000FFFFE0000000ULL
612     #define DICE_NOTIFIER_BLOCK_LENGTH 4
613     class Notifier : public Ieee1394Service::ARMHandler
614     {
615     public:
616         Notifier(Device &, nodeaddr_t start);
617         virtual ~Notifier();
618
619     private:
620         Device &m_device;
621     };
622
623
624
625 };
626
627 }
628 #endif
Note: See TracBrowser for help on using the browser.