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

Revision 2134, 20.0 kB (checked in by jwoithe, 11 years ago)

dice: default router setup patch 1/10 from Philippe Carriere: This function forces the creation of a destination whatever is the present existing status. This will be useful (in view of a 'hardware default setting' function) since the same destination is sometimes effectively duplicated in the router space for some devices (Focusrite Saffire Pro 24 and Pro 40, for instance).

Line 
1 /*
2  * Copyright (C) 2005-2009 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 #ifndef __DICE_EAP_H
24 #define __DICE_EAP_H
25
26 #include "dice_avdevice.h"
27
28 #define DICE_EAP_BASE                  0x0000000000200000ULL
29 #define DICE_EAP_MAX_SIZE              0x0000000000F00000ULL
30
31 #define DICE_EAP_CAPABILITY_SPACE_OFF      0x0000
32 #define DICE_EAP_CAPABILITY_SPACE_SZ       0x0004
33 #define DICE_EAP_CMD_SPACE_OFF             0x0008
34 #define DICE_EAP_CMD_SPACE_SZ              0x000C
35 #define DICE_EAP_MIXER_SPACE_OFF           0x0010
36 #define DICE_EAP_MIXER_SPACE_SZ            0x0014
37 #define DICE_EAP_PEAK_SPACE_OFF            0x0018
38 #define DICE_EAP_PEAK_SPACE_SZ             0x001C
39 #define DICE_EAP_NEW_ROUTING_SPACE_OFF     0x0020
40 #define DICE_EAP_NEW_ROUTING_SPACE_SZ      0x0024
41 #define DICE_EAP_NEW_STREAM_CFG_SPACE_OFF  0x0028
42 #define DICE_EAP_NEW_STREAM_CFG_SPACE_SZ   0x002C
43 #define DICE_EAP_CURR_CFG_SPACE_OFF        0x0030
44 #define DICE_EAP_CURR_CFG_SPACE_SZ         0x0034
45 #define DICE_EAP_STAND_ALONE_CFG_SPACE_OFF 0x0038
46 #define DICE_EAP_STAND_ALONE_CFG_SPACE_SZ  0x003C
47 #define DICE_EAP_APP_SPACE_OFF             0x0040
48 #define DICE_EAP_APP_SPACE_SZ              0x0044
49 #define DICE_EAP_ZERO_MARKER_1             0x0048
50
51 // CAPABILITY registers
52 #define DICE_EAP_CAPABILITY_ROUTER         0x0000
53 #define DICE_EAP_CAPABILITY_MIXER          0x0004
54 #define DICE_EAP_CAPABILITY_GENERAL        0x0008
55 #define DICE_EAP_CAPABILITY_RESERVED       0x000C
56
57 // CAPABILITY bit definitions
58 #define DICE_EAP_CAP_ROUTER_EXPOSED         0
59 #define DICE_EAP_CAP_ROUTER_READONLY        1
60 #define DICE_EAP_CAP_ROUTER_FLASHSTORED     2
61 #define DICE_EAP_CAP_ROUTER_MAXROUTES      16
62
63 #define DICE_EAP_CAP_MIXER_EXPOSED          0
64 #define DICE_EAP_CAP_MIXER_READONLY         1
65 #define DICE_EAP_CAP_MIXER_FLASHSTORED      2
66 #define DICE_EAP_CAP_MIXER_IN_DEV           4
67 #define DICE_EAP_CAP_MIXER_OUT_DEV          8
68 #define DICE_EAP_CAP_MIXER_INPUTS          16
69 #define DICE_EAP_CAP_MIXER_OUTPUTS         24
70
71 #define DICE_EAP_CAP_GENERAL_STRM_CFG_EN    0
72 #define DICE_EAP_CAP_GENERAL_FLASH_EN       1
73 #define DICE_EAP_CAP_GENERAL_PEAK_EN        2
74 #define DICE_EAP_CAP_GENERAL_MAX_TX_STREAM  4
75 #define DICE_EAP_CAP_GENERAL_MAX_RX_STREAM  8
76 #define DICE_EAP_CAP_GENERAL_STRM_CFG_FLS  12
77 #define DICE_EAP_CAP_GENERAL_CHIP          16
78
79 #define DICE_EAP_CAP_GENERAL_CHIP_DICEII    0
80 #define DICE_EAP_CAP_GENERAL_CHIP_DICEMINI  1
81 #define DICE_EAP_CAP_GENERAL_CHIP_DICEJR    2
82
83 // COMMAND registers
84 #define DICE_EAP_COMMAND_OPCODE         0x0000
85 #define DICE_EAP_COMMAND_RETVAL         0x0004
86
87 // opcodes
88 #define DICE_EAP_CMD_OPCODE_NO_OP            0x0000
89 #define DICE_EAP_CMD_OPCODE_LD_ROUTER        0x0001
90 #define DICE_EAP_CMD_OPCODE_LD_STRM_CFG      0x0002
91 #define DICE_EAP_CMD_OPCODE_LD_RTR_STRM_CFG  0x0003
92 #define DICE_EAP_CMD_OPCODE_LD_FLASH_CFG     0x0004
93 #define DICE_EAP_CMD_OPCODE_ST_FLASH_CFG     0x0005
94
95 #define DICE_EAP_CMD_OPCODE_FLAG_LD_LOW      (1U<<16)
96 #define DICE_EAP_CMD_OPCODE_FLAG_LD_MID      (1U<<17)
97 #define DICE_EAP_CMD_OPCODE_FLAG_LD_HIGH     (1U<<18)
98 #define DICE_EAP_CMD_OPCODE_FLAG_LD_EXECUTE  (1U<<31)
99
100
101 // MIXER registers
102 // TODO
103
104 // PEAK registers
105 // TODO
106
107 // NEW ROUTER registers
108 // TODO
109
110 // NEW STREAM CFG registers
111 // TODO
112
113 // CURRENT CFG registers
114 #define DICE_EAP_CURRCFG_LOW_ROUTER         0x0000
115 #define DICE_EAP_CURRCFG_LOW_STREAM         0x1000
116 #define DICE_EAP_CURRCFG_MID_ROUTER         0x2000
117 #define DICE_EAP_CURRCFG_MID_STREAM         0x3000
118 #define DICE_EAP_CURRCFG_HIGH_ROUTER        0x4000
119 #define DICE_EAP_CURRCFG_HIGH_STREAM        0x5000
120
121 #define DICE_EAP_CHANNEL_CONFIG_NAMESTR_LEN_QUADS  (64)
122 #define DICE_EAP_CHANNEL_CONFIG_NAMESTR_LEN_BYTES  (4*DICE_EAP_CHANNEL_CONFIG_NAMESTR_LEN_QUADS)
123
124 namespace Dice {
125
126 /**
127   @brief Sources for audio hitting the router
128   */
129 enum eRouteSource {
130     eRS_AES = 0,
131     eRS_ADAT = 1,
132     eRS_Mixer = 2,
133     eRS_InS0 = 4,
134     eRS_InS1 = 5,
135     eRS_ARM = 10,
136     eRS_ARX0 = 11,
137     eRS_ARX1 = 12,
138     eRS_Muted = 15,
139     eRS_Invalid = 16,
140 };
141 /**
142   @brief Destinations for audio exiting the router
143   */
144 enum eRouteDestination {
145     eRD_AES = 0,
146     eRD_ADAT = 1,
147     eRD_Mixer0 = 2,
148     eRD_Mixer1 = 3,
149     eRD_InS0 = 4,
150     eRD_InS1 = 5,
151     eRD_ARM = 10,
152     eRD_ATX0 = 11,
153     eRD_ATX1 = 12,
154     eRD_Muted = 15,
155     eRD_Invalid = 16,
156 };
157
158 /**
159   @brief represents the EAP interface available on some devices
160
161   When available, the mixer and router are visible. This class is also the base for custom
162   implementations of EAP extensions.
163   */
164 class EAP : public Control::Container
165 {
166 public:
167     /**
168       @brief Command status
169       */
170     enum eWaitReturn {
171         eWR_Error,
172         eWR_Timeout,
173         eWR_Busy,
174         eWR_Done,
175     };
176     /**
177       @brief Constants for the EAP spaces
178
179       @see offsetGen for the calculation of the real offsets.
180       */
181     enum eRegBase {
182         eRT_Base,
183         eRT_Capability,
184         eRT_Command,
185         eRT_Mixer,
186         eRT_Peak,
187         eRT_NewRouting,
188         eRT_NewStreamCfg,
189         eRT_CurrentCfg,
190         eRT_Standalone,
191         eRT_Application,
192         eRT_None,
193     };
194
195 private:
196
197     /**
198       @brief Description of the routing in the hardware
199       */
200     class RouterConfig {
201     private:
202         friend class Dice::EAP;
203         RouterConfig(EAP &);
204         RouterConfig(EAP &, enum eRegBase, unsigned int offset);
205         ~RouterConfig();
206
207     public:
208
209         bool read() {return read(m_base, m_offset);};
210         bool write() {return write(m_base, m_offset);};
211         bool read(enum eRegBase b, unsigned offset);
212         bool write(enum eRegBase b, unsigned offset);
213         void show();
214
215         /**
216           @brief Create a route between src and dest
217
218           This will effectively create a new destination.
219           If destination exists or its status unknown,
220           rather use the next setupRoute function
221           */
222         bool createRoute(unsigned char src, unsigned char dest);
223
224         /**
225           @brief Set up a route between src and dest
226
227           If a route with that destination exists, it will be replaced. If no route to that
228           destination exists, a new route will be established.
229           */
230         bool setupRoute(unsigned char src, unsigned char dest);
231
232         /**
233           @brief Mute a route for dest
234
235           All EAP devices will support muting.
236           Not all of them support (at least full support) removing a dest (see comment below)
237           */
238         bool muteRoute(unsigned char dest);
239
240         /**
241           @brief Remove a route
242
243           @todo is this really necessary?
244           */
245         bool removeRoute(unsigned char src, unsigned char dest);
246         /**
247           @brief Remove the destinations route
248           */
249         bool removeRoute(unsigned char dest);
250
251         /**
252           @brief Return the source for the given destination
253
254           Returns -1 if the destination is not connected.
255           */
256         unsigned char getSourceForDestination(unsigned char dest);
257         /**
258           @brief Return a list of destinations for a given source
259
260           Returns an empty list if no destination is connected to this source.
261           */
262         std::vector<unsigned char> getDestinationsForSource(unsigned char src);
263
264         unsigned int getNbRoutes() {return m_routes2.size();};
265
266     private:
267         EAP &m_eap;
268         enum eRegBase m_base;
269         unsigned int m_offset;
270
271         /**
272           @brief map for the routes
273
274           The key is the destination as each destination can only have audio from one source.
275           Sources can be routed to several destinations though.
276           */
277 //        typedef std::map<unsigned char,unsigned char> RouteVectorV2;
278         typedef std::vector< std::pair<unsigned char,unsigned char> > RouteVectorV2;
279         RouteVectorV2 m_routes2;
280     private:
281         DECLARE_DEBUG_MODULE_REFERENCE;
282     };
283
284     /**
285       @brief Description of the peak space in hardware
286       */
287     class PeakSpace {
288     private:
289         friend class Dice::EAP;
290         PeakSpace(EAP &p) : m_eap(p), m_base(eRT_Peak), m_offset(0), m_debugModule(p.m_debugModule) {};
291         ~PeakSpace() {};
292
293     public:
294         bool read() {return read(m_base, m_offset);};
295         bool read(enum eRegBase b, unsigned offset);
296         void show();
297
298         std::map<unsigned char, int> getPeaks();
299         int getPeak(unsigned char dest);
300
301     private:
302         EAP &m_eap;
303         enum eRegBase m_base;
304         unsigned int m_offset;
305
306         /**
307           @brief maps peaks to destinations
308           */
309         std::map<unsigned char, int> m_peaks;
310
311         DECLARE_DEBUG_MODULE_REFERENCE;
312     };
313
314     /**
315       @brief Description of the streams in the hardware
316       */
317     class StreamConfig {
318     private:
319         friend class Dice::EAP;
320         StreamConfig(EAP &, enum eRegBase, unsigned int offset);
321         ~StreamConfig();
322
323     public:
324         struct ConfigBlock { // FIXME: somewhere in the DICE avdevice this is present too
325             uint32_t nb_audio;
326             uint32_t nb_midi;
327             uint32_t names[DICE_EAP_CHANNEL_CONFIG_NAMESTR_LEN_QUADS];
328             uint32_t ac3_map;
329         };
330         void showConfigBlock(struct ConfigBlock &);
331         stringlist getNamesForBlock(struct ConfigBlock &b);
332         stringlist getTxNamesString(unsigned int);
333         stringlist getRxNamesString(unsigned int);
334
335         bool read() {return read(m_base, m_offset);};
336         bool write() {return write(m_base, m_offset);};
337         bool read(enum eRegBase b, unsigned offset);
338         bool write(enum eRegBase b, unsigned offset);
339
340         void show();
341
342     private:
343         EAP &m_eap;
344         enum eRegBase m_base;
345         unsigned int m_offset;
346
347         uint32_t m_nb_tx;
348         uint32_t m_nb_rx;
349
350         struct ConfigBlock *m_tx_configs;
351         struct ConfigBlock *m_rx_configs;
352
353         DECLARE_DEBUG_MODULE_REFERENCE;
354     };
355
356 public:
357
358     /**
359       @brief The matrixmixer exposed
360       */
361     class Mixer : public Control::MatrixMixer {
362     public:
363         Mixer(EAP &);
364         ~Mixer();
365
366         bool init();
367         void show();
368
369         void updateNameCache();
370         /**
371          * load the coefficients from the device into the local cache
372          * @return
373          */
374         bool loadCoefficients();
375         /**
376          * Stores the coefficients from the cache to the device
377          * @return
378          */
379         bool storeCoefficients();
380
381         virtual int getRowCount( );
382         virtual int getColCount( );
383
384         virtual int canWrite( const int, const int );
385         virtual double setValue( const int, const int, const double );
386         virtual double getValue( const int, const int );
387
388         //
389         bool hasNames() const { return false; }
390         std::string getRowName( const int );
391         std::string getColName( const int );
392
393         // TODO: implement connections.
394         bool canConnect() const { return false; }
395
396         // full map updates are unsupported
397         virtual bool getCoefficientMap(int &);
398         virtual bool storeCoefficientMap(int &);
399
400     private:
401         EAP &         m_eap;
402         fb_quadlet_t *m_coeff;
403
404         //std::map<int, RouterConfig::Route> m_input_route_map;
405         //std::map<int, RouterConfig::RouteVector> m_output_route_map;
406
407         DECLARE_DEBUG_MODULE_REFERENCE;
408     };
409
410     /**
411       @brief The router exposed
412       */
413     class Router : public Control::CrossbarRouter {
414     public:
415         Router(EAP &);
416         ~Router();
417
418         void update();
419         void show();
420
421         void addDestination(const std::string& name, enum eRouteDestination dstid,
422                             unsigned int base, unsigned int cnt, unsigned int offset=0);
423         void addSource(const std::string& name, enum eRouteSource srcid,
424                        unsigned int base, unsigned int cnt, unsigned int offset=0);
425
426         // per-coefficient access
427         virtual std::string getSourceName(const int);
428         virtual std::string getDestinationName(const int);
429         virtual int getSourceIndex(std::string);
430         virtual int getDestinationIndex(std::string);
431         virtual stringlist getSourceNames();
432         virtual stringlist getDestinationNames();
433
434         std::string getSourceForDestination(const std::string& dstname);
435         stringlist getDestinationsForSource(const std::string& srcname);
436
437         virtual bool canConnect(const int srcidx, const int dstidx);
438         virtual bool setConnectionState(const int srcidx, const int dstidx, const bool enable);
439         virtual bool getConnectionState(const int srcidx, const int dstidx);
440
441         virtual bool canConnect(const std::string& srcname, const std::string& dstname);
442         virtual bool setConnectionState(const std::string& srcname, const std::string& dstname, const bool enable);
443         virtual bool getConnectionState(const std::string& srcname, const std::string& dstname);
444
445         virtual bool clearAllConnections();
446
447         // peak metering support
448         virtual bool hasPeakMetering();
449         virtual double getPeakValue(const std::string& dest);
450         virtual std::map<std::string, double> getPeakValues();
451
452     private:
453         EAP &m_eap;
454         /**
455           @{
456           @brief Name-Index pairs for the sources and destinations
457
458           The index is 'artificial' and is the block/channel combination used in the dice.
459           */
460         std::map<std::string, int> m_sources;
461         std::map<std::string, int> m_destinations;
462         // @}
463
464         PeakSpace &m_peak;
465
466         DECLARE_DEBUG_MODULE_REFERENCE;
467     };
468
469 public:
470     /** constructor */
471     EAP(Device &);
472     /** destructor */
473     virtual ~EAP();
474
475     /**
476       @brief Does this device support the EAP?
477
478       When subclassing EAP, return true only on devices that actually have an EAP.
479
480       @todo Shouldn't this be inside Dice::Device?
481       */
482     static bool supportsEAP(Device &);
483
484     /**
485       @brief Initialize the EAP
486       */
487     bool init();
488
489     /// update EAP
490     void update();
491
492     /// Show information about the EAP
493     void show();
494     /// Dump the first parts of the application space
495     void showApplication();
496     /// Show the full router content
497     void showFullRouter();
498     /// Show the full peak space content
499     void showFullPeakSpace();
500
501     /// Restore from flash
502     bool loadFlashConfig();
503     /// Store to flash
504     bool storeFlashConfig();
505
506     /// Is the current operation still busy?
507     enum eWaitReturn operationBusy();
508     /// Block until the current operation is done
509     enum eWaitReturn waitForOperationEnd(int max_wait_time_ms = 100);
510
511     /// Update all configurations from the device
512     bool updateConfigurationCache();
513
514     /**
515       @{
516       @brief Read and write registers on the device
517       */
518     bool readReg(enum eRegBase, unsigned offset, quadlet_t *);
519     bool writeReg(enum eRegBase, unsigned offset, quadlet_t);
520     bool readRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
521     bool writeRegBlock(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
522     bool readRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
523     bool writeRegBlockSwapped(enum eRegBase, unsigned, fb_quadlet_t *, size_t);
524     //@}
525
526     /** @brief Get access to the mixer */
527     Mixer*  getMixer() {return m_mixer;};
528     /** @brief Get access to the router */
529     Router* getRouter() {return m_router;};
530
531     /** @brief Get capture and playback names */
532     stringlist getCptrNameString(unsigned int);
533     stringlist getPbckNameString(unsigned int);
534
535 protected:
536     /**
537       @brief Setup all the available sources
538
539       This adds the needed entries for sources to the router. The default implementation decides on
540       the chip which sources to add, subclasses should only add the sources actually usable for the
541       device.
542
543       To ease custom device support, this function is not in EAP::Router but here.
544       */
545     void setupSources();
546     virtual void setupSources_low();
547     virtual void setupSources_mid();
548     virtual void setupSources_high();
549     virtual unsigned int getSMuteId();
550     /**
551       @brief Setup all the available destinations
552
553       This adds the needed entries for destinations to the router. The default implementation
554       decides on the chip which destinations to add, subclasses should only add the destinations
555       actually usable for the device.
556
557       To ease custom device support, this function is not in EAP::Router but here.
558       */
559     void setupDestinations();
560     virtual void setupDestinations_low();
561     virtual void setupDestinations_mid();
562     virtual void setupDestinations_high();
563
564     /**
565       @brief Actually add the source
566       */
567     void addSource(const std::string name, unsigned int base, unsigned int count,
568                    enum eRouteSource srcid, unsigned int offset=0);
569     /**
570       @brief Actually add the destination
571       */
572     void addDestination(const std::string name, unsigned int base, unsigned int count,
573                         enum eRouteDestination destid, unsigned int offset=0);
574
575     uint16_t getMaxNbRouterEntries() {return m_router_nb_entries;};
576
577 private:
578     /// Return the router configuration for the current rate
579     RouterConfig * getActiveRouterConfig();
580     /// Return the stream configuration for the current rate
581     StreamConfig * getActiveStreamConfig();
582
583     /// Write a new router configuration to the device
584     bool updateRouterConfig(RouterConfig&, bool low, bool mid, bool high);
585     /// Write a new router configuration to the device
586     bool updateCurrentRouterConfig(RouterConfig&);
587     /// Write a new stream configuration to the device
588     bool updateStreamConfig(StreamConfig&, bool low, bool mid, bool high);
589     /// Write a new stream configuration to the device
590     bool updateStreamConfig(RouterConfig&, StreamConfig&, bool low, bool mid, bool high);
591
592     bool loadRouterConfig(bool low, bool mid, bool high);
593     bool loadStreamConfig(bool low, bool mid, bool high);
594     bool loadRouterAndStreamConfig(bool low, bool mid, bool high);
595
596 private:
597     bool     m_router_exposed;
598     bool     m_router_readonly;
599     bool     m_router_flashstored;
600     uint16_t m_router_nb_entries;
601
602     bool     m_mixer_exposed;
603     bool     m_mixer_readonly;
604     bool     m_mixer_flashstored;
605     uint8_t  m_mixer_tx_id;
606     uint8_t  m_mixer_rx_id;
607     uint8_t  m_mixer_nb_tx;
608     uint8_t  m_mixer_nb_rx;
609
610     bool     m_general_support_dynstream;
611     bool     m_general_support_flash;
612     bool     m_general_peak_enabled;
613     uint8_t  m_general_max_tx;
614     uint8_t  m_general_max_rx;
615     bool     m_general_stream_cfg_stored;
616     uint16_t m_general_chip;
617
618     bool commandHelper(fb_quadlet_t cmd);
619
620     /// Calculate the real offset for the different spaces
621     fb_nodeaddr_t offsetGen(enum eRegBase, unsigned, size_t);
622
623 private:
624     Device & m_device;
625     Mixer*   m_mixer;
626     Router*  m_router;
627     RouterConfig m_current_cfg_routing_low;
628     RouterConfig m_current_cfg_routing_mid;
629     RouterConfig m_current_cfg_routing_high;
630     StreamConfig m_current_cfg_stream_low;
631     StreamConfig m_current_cfg_stream_mid;
632     StreamConfig m_current_cfg_stream_high;
633
634     fb_quadlet_t m_capability_offset;
635     fb_quadlet_t m_capability_size;
636     fb_quadlet_t m_cmd_offset;
637     fb_quadlet_t m_cmd_size;
638     fb_quadlet_t m_mixer_offset;
639     fb_quadlet_t m_mixer_size;
640     fb_quadlet_t m_peak_offset;
641     fb_quadlet_t m_peak_size;
642     fb_quadlet_t m_new_routing_offset;
643     fb_quadlet_t m_new_routing_size;
644     fb_quadlet_t m_new_stream_cfg_offset;
645     fb_quadlet_t m_new_stream_cfg_size;
646     fb_quadlet_t m_curr_cfg_offset;
647     fb_quadlet_t m_curr_cfg_size;
648     fb_quadlet_t m_standalone_offset;
649     fb_quadlet_t m_standalone_size;
650     fb_quadlet_t m_app_offset;
651     fb_quadlet_t m_app_size;
652
653 protected:
654     DECLARE_DEBUG_MODULE;
655 };
656
657 };
658
659 #endif // __DICE_EAP_H
Note: See TracBrowser for help on using the browser.