From: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Forwarded: not-needed
Bug-FFADO: http://subversion.ffado.org/ticket/242
Description: Downgrade vom SVN r2171 to r2166
 Upstream has introduced major changes to the timing code that will
 break FFADO if used with libraw1394-2.1.0. r2166 still contains
 the old code that's known to work, so we stick to this one until
 the WIP is over and things work relibably with libraw1394-2.1.0.
--- a/src/bebob/bebob_dl_mgr.cpp
+++ b/src/bebob/bebob_dl_mgr.cpp
@@ -574,7 +574,7 @@
 {
     struct timespec timeout;
     int retcode;
-    Util::SystemTimeSource::clockGettime(&timeout);
+    clock_gettime(CLOCK_REALTIME, &timeout);
     do {
         printf(".");
         fflush(stdout);
--- a/src/debugmodule/debugmodule.cpp
+++ b/src/debugmodule/debugmodule.cpp
@@ -26,7 +26,6 @@
 
 #include <stdarg.h>
 #include "libutil/ByteSwap.h"
-#include "libutil/Time.h"
 
 #include <iostream>
 
@@ -180,7 +179,7 @@
 
     // add a timing timestamp
     struct timespec ts;
-    Util::SystemTimeSource::clockGettime(&ts);
+    clock_gettime(CLOCK_MONOTONIC, &ts);
     uint64_t ts_usec=(uint64_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL);
 
     // format the message such that it remains together
--- a/src/libieee1394/ieee1394service.cpp
+++ b/src/libieee1394/ieee1394service.cpp
@@ -1,7 +1,6 @@
 /*
  * Copyright (C) 2005-2008 by Daniel Wagner
  * Copyright (C) 2005-2008 by Pieter Palmers
- * Copyright (C) 2012 by Jonathan Woithe
  *
  * This file is part of FFADO
  * FFADO = Free Firewire (pro-)audio drivers for linux
@@ -48,19 +47,6 @@
 #include <iostream>
 #include <iomanip>
 
-// Permit linking against older libraw1394 which didn't include this
-// function.
-#ifdef __GNUC__
-  #ifdef __APPLE__
-  #define WEAK_ATTRIBUTE weak_import
-  #else
-  #define WEAK_ATTRIBUTE __weak__
-  #endif
-  int raw1394_read_cycle_timer_and_clock(raw1394handle_t handle,
-      u_int32_t *cycle_timer, u_int64_t *local_time, clockid_t clk_id)
-      __attribute__((WEAK_ATTRIBUTE));
-#endif
-
 using namespace std;
 
 IMPL_DEBUG_MODULE( Ieee1394Service, Ieee1394Service, DEBUG_LEVEL_NORMAL );
@@ -331,7 +317,6 @@
     int err;
     uint32_t cycle_timer;
     uint64_t local_time;
-    m_have_read_ctr_and_clock = false;
     err = raw1394_read_cycle_timer(m_util_handle, &cycle_timer, &local_time);
     if(err) {
         debugOutput(DEBUG_LEVEL_VERBOSE, "raw1394_read_cycle_timer failed.\n");
@@ -344,29 +329,8 @@
         debugWarning("==================================================================\n");
         m_have_new_ctr_read = false;
     } else {
+        debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n");
         m_have_new_ctr_read = true;
-
-        // Only if raw1394_read_cycle_timer() is present is it worth even
-        // considering the option that raw1394_read_cycle_timer_and_clock()
-        // might be available.
-        if (raw1394_read_cycle_timer_and_clock != NULL) {
-            err = raw1394_read_cycle_timer_and_clock(m_util_handle, &cycle_timer, &local_time, CLOCK_MONOTONIC_RAW);
-            if (!err && Util::SystemTimeSource::setSource(CLOCK_MONOTONIC_RAW)==true)
-                m_have_read_ctr_and_clock = true;
-        }
-
-        if (m_have_read_ctr_and_clock) {
-            debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer_and_clock call and the\n");
-            debugOutput(DEBUG_LEVEL_VERBOSE, "CLOCK_MONOTONIC_RAW clock source; using them.\n");
-        } else {
-            debugOutput(DEBUG_LEVEL_VERBOSE, "This system supports the raw1394_read_cycle_timer call, using it.\n");
-            debugOutput(DEBUG_LEVEL_NORMAL, "The raw1394_read_cycle_timer_and_clock call and/or the CLOCK_MONOTONIC_RAW\n");
-            debugOutput(DEBUG_LEVEL_NORMAL, "clock source is not available.\n");
-            debugOutput(DEBUG_LEVEL_NORMAL, "Fallback to raw1394_read_cycle_timer.\n");
-            debugOutput(DEBUG_LEVEL_NORMAL, "FFADO may be susceptible to NTP-induced clock discontinuities.\n");
-            debugOutput(DEBUG_LEVEL_NORMAL, "If this is an issue, upgrade libraw1394 to version 2.1.0 or later and/or\n");
-            debugOutput(DEBUG_LEVEL_NORMAL, "kernel 2.6.28 or later.\n");
-        }
     }
 
     // obtain port name
@@ -539,16 +503,6 @@
 bool
 Ieee1394Service::readCycleTimerReg(uint32_t *cycle_timer, uint64_t *local_time)
 {
-    if (m_have_read_ctr_and_clock) {
-        int err;
-        err = raw1394_read_cycle_timer_and_clock(m_util_handle, cycle_timer, local_time, 
-                  Util::SystemTimeSource::getSource());
-        if(err) {
-            debugWarning("raw1394_read_cycle_timer_and_clock: %s\n", strerror(err));
-            return false;
-        }
-        return true;
-    } else
     if(m_have_new_ctr_read) {
         int err;
         err = raw1394_read_cycle_timer(m_util_handle, cycle_timer, local_time);
--- a/src/libieee1394/ieee1394service.h
+++ b/src/libieee1394/ieee1394service.h
@@ -460,7 +460,6 @@
     IsoHandlerManager*      m_pIsoManager;
     CycleTimerHelper*       m_pCTRHelper;
     bool                    m_have_new_ctr_read;
-    bool                    m_have_read_ctr_and_clock;
 
     bool            m_filterFCPResponse;
 
--- a/src/libieee1394/IsoHandlerManager.cpp
+++ b/src/libieee1394/IsoHandlerManager.cpp
@@ -397,7 +397,7 @@
     struct timespec ts;
     int result;
 
-    if (Util::SystemTimeSource::clockGettime(&ts) == -1) {
+    if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
         debugError("clock_gettime failed\n");
         return eAR_Error;
     }
--- a/src/libstreaming/StreamProcessorManager.cpp
+++ b/src/libstreaming/StreamProcessorManager.cpp
@@ -163,7 +163,7 @@
 
     if (m_activity_wait_timeout_nsec >= 0) {
 
-        if (Util::SystemTimeSource::clockGettime(&ts) == -1) {
+        if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
             debugError("clock_gettime failed\n");
             return eAR_Error;
         }
--- a/src/libutil/PosixMessageQueue.cpp
+++ b/src/libutil/PosixMessageQueue.cpp
@@ -25,7 +25,6 @@
 
 #include "Functors.h"
 #include "PosixMutex.h"
-#include "Time.h"
 
 #include <errno.h>
 #include <string.h>
@@ -197,7 +196,7 @@
     MutexLockHelper lock(m_notifyHandlerLock);
     while(countMessages()) {
         struct timespec timeout;
-        Util::SystemTimeSource::clockGettime(&timeout);
+        clock_gettime(CLOCK_REALTIME, &timeout);
         timeout.tv_sec += m_timeout.tv_sec;
         timeout.tv_nsec += m_timeout.tv_nsec;
         if(timeout.tv_nsec >= 1000000000LL) {
@@ -247,7 +246,7 @@
     }
 
     struct timespec timeout;
-    Util::SystemTimeSource::clockGettime(&timeout);
+    clock_gettime(CLOCK_REALTIME, &timeout);
     timeout.tv_sec += m_timeout.tv_sec;
     timeout.tv_nsec += m_timeout.tv_nsec;
     if(timeout.tv_nsec >= 1000000000LL) {
@@ -293,7 +292,7 @@
     }
 
     struct timespec timeout;
-    Util::SystemTimeSource::clockGettime(&timeout);
+    clock_gettime(CLOCK_REALTIME, &timeout);
     timeout.tv_sec += m_timeout.tv_sec;
     timeout.tv_nsec += m_timeout.tv_nsec;
     if(timeout.tv_nsec >= 1000000000LL) {
--- a/src/libutil/SystemTimeSource.cpp
+++ b/src/libutil/SystemTimeSource.cpp
@@ -1,6 +1,5 @@
 /*
  * Copyright (C) 2005-2008 by Pieter Palmers
- * Copytight (C) 2012 by Jonathan Woithe
  *
  * This file is part of FFADO
  * FFADO = Free Firewire (pro-)audio drivers for linux
@@ -37,33 +36,6 @@
 
 namespace Util {
 
-static clockid_t clock_id = CLOCK_REALTIME;
-
-bool
-SystemTimeSource::setSource(clockid_t id)
-{
-    struct timespec tp;
-    // Determine at runtime whether the kernel has support for the
-    // requested clock source.
-    if (clock_gettime(id, &tp) == 0) {
-        clock_id = id;
-        return true;
-    }
-    return false;
-}
-
-clockid_t
-SystemTimeSource::getSource(void)
-{
-    return clock_id;
-}
-
-int
-SystemTimeSource::clockGettime(struct timespec *tp)
-{
-    return clock_gettime(clock_id, tp);
-}
-
 void
 SystemTimeSource::SleepUsecRelative(ffado_microsecs_t usecs)
 {
@@ -71,7 +43,7 @@
     struct timespec ts;
     ts.tv_sec = usecs / (1000000LL);
     ts.tv_nsec = (usecs % (1000000LL)) * 1000LL;
-    clock_nanosleep(clock_id, 0, &ts, NULL);
+    clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
 }
 
 void
@@ -84,7 +56,7 @@
     debugOutputExtreme(DEBUG_LEVEL_VERBOSE,
                        "clock_nanosleep until %"PRId64" sec, %"PRId64" nanosec\n",
                        (int64_t)ts.tv_sec, (int64_t)ts.tv_nsec);
-    int err = clock_nanosleep(clock_id, TIMER_ABSTIME, &ts, NULL);
+    int err = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL);
     if(err) {
         // maybe signal occurred, but we're going to ignore that
     }
@@ -122,7 +94,7 @@
 SystemTimeSource::getCurrentTimeAsUsecs()
 {
     struct timespec ts;
-    clock_gettime(clock_id, &ts);
+    clock_gettime(CLOCK_REALTIME, &ts);
     return (ffado_microsecs_t)(ts.tv_sec * 1000000LL + ts.tv_nsec / 1000LL);
 }
 
--- a/src/libutil/SystemTimeSource.h
+++ b/src/libutil/SystemTimeSource.h
@@ -1,6 +1,5 @@
 /*
  * Copyright (C) 2005-2008 by Pieter Palmers
- * Copyright (C) 2012 by Jonathan Woithe
  *
  * This file is part of FFADO
  * FFADO = Free Firewire (pro-)audio drivers for linux
@@ -31,12 +30,6 @@
 
 typedef uint64_t ffado_microsecs_t;
 
-// Ensure this is defined even for kernels/glib versions which don't include
-// it.  This allows compile-time testing for the feature.
-#ifndef CLOCK_MONOTONIC_RAW
-#define CLOCK_MONOTONIC_RAW 4
-#endif
-
 namespace Util {
 
 class SystemTimeSource
@@ -46,10 +39,6 @@
     virtual ~SystemTimeSource() {};
 
 public:
-    static bool setSource(clockid_t id);
-    static clockid_t getSource(void);
-    static int clockGettime(struct timespec *tp);
-
     static ffado_microsecs_t getCurrentTime();
     static ffado_microsecs_t getCurrentTimeAsUsecs();
 
--- a/src/motu/motu_avdevice.cpp
+++ b/src/motu/motu_avdevice.cpp
@@ -65,13 +65,7 @@
 
 namespace Motu {
 
-// Define the supported devices.  Device ordering is arbitary here.  To include a MOTU
-// device which cannot yet be used (for identification purposes only), set the model
-// field to MOTU_MODEL_NONE.
-//
-// The V4HD device includes 4 sub-devices.  Include all in the definition as a way
-// of documenting it.  It's likely that only one of these is of interest for audio
-// but that's still to be determined.
+// Define the supported devices.  Device ordering is arbitary here.
 static VendorModelEntry supportedDeviceList[] =
 {
 //  {vendor_id, model_id, unit_version, unit_specifier_id, model, vendor_name,model_name}
@@ -85,10 +79,6 @@
     {FW_VENDORID_MOTU, 0, 0x00000017, 0x000001f2, MOTU_MODEL_896mk3, "MOTU", "896Mk3"},
     {FW_VENDORID_MOTU, 0, 0x00000019, 0x000001f2, MOTU_MODEL_ULTRALITEmk3, "MOTU", "UltraLiteMk3"},
     {FW_VENDORID_MOTU, 0, 0x0000001b, 0x000001f2, MOTU_MODEL_TRAVELERmk3, "MOTU", "TravelerMk3"},
-    {FW_VENDORID_MOTU, 0, 0x00000021, 0x000001f2, MOTU_MODEL_NONE, "MOTU", "V4HD subdevice 0"},
-    {FW_VENDORID_MOTU, 0, 0x00000022, 0x000001f2, MOTU_MODEL_NONE, "MOTU", "V4HD subdevice 1"},
-    {FW_VENDORID_MOTU, 0, 0x00000023, 0x000001f2, MOTU_MODEL_NONE, "MOTU", "V4HD subdevice 2"},
-    {FW_VENDORID_MOTU, 0, 0x00000024, 0x000001f2, MOTU_MODEL_NONE, "MOTU", "V4HD subdevice 3"},
     {FW_VENDORID_MOTU, 0, 0x00000030, 0x000001f2, MOTU_MODEL_ULTRALITEmk3_HYB, "MOTU", "UltraLiteMk3-hybrid"},
 };
 
@@ -809,13 +799,6 @@
              && ( supportedDeviceList[i].unit_specifier_id == unitSpecifierId )
            )
         {
-            if (supportedDeviceList[i].model == MOTU_MODEL_NONE) {
-                debugOutput( DEBUG_LEVEL_VERBOSE, "%s %s found but is not currently supported by FFADO\n",
-                    supportedDeviceList[i].vendor_name, supportedDeviceList[i].model_name);
-                debugOutput( DEBUG_LEVEL_VERBOSE, "  unitVersion=0x%08x\n", unitVersion);
-                return false;
-            }
-
             return true;
         }
     }
@@ -857,11 +840,6 @@
     debugOutput( DEBUG_LEVEL_VERBOSE, "found %s %s\n",
         m_model->vendor_name, m_model->model_name);
 
-    if (m_motu_model == MOTU_MODEL_NONE) {
-        debugOutput( DEBUG_LEVEL_VERBOSE, "This MOTU device is not currently supported by FFADO\n");
-        return false;
-    }
-
     if (!buildMixer()) {
         debugWarning("Could not build mixer\n");
     }
--- a/src/rme/fireface_hw.cpp
+++ b/src/rme/fireface_hw.cpp
@@ -886,11 +886,7 @@
                  ram_addr += ram_output_block_size;
             break;
         case RME_FF_MM_OUTPUT:
-            if (m_rme_model == RME_MODEL_FIREFACE400)
-                ram_addr += 0x0f80;
-            else
-                ram_addr += 0x1f80;
-            ram_addr += 4*src_channel;
+            ram_addr += 0x0f80 + 4*src_channel;
             break;
     }
 
--- a/src/rme/rme_avdevice.cpp
+++ b/src/rme/rme_avdevice.cpp
@@ -61,21 +61,27 @@
 // opposed to bus order, which is big endian).  Therefore define our own
 // 32-bit byteswap function to do this.
 #if __BYTE_ORDER == __BIG_ENDIAN
-#define RME_BYTESWAP32(x)	ByteSwap32(x)
+static inline uint32_t
+ByteSwapToDevice32(uint32_t d)
+{
+    return byteswap_32(d);
+}
+ByteSwapFromDevice32(uint32_t d)
+{
+    return byteswap_32(d);
+}
 #else
-#define RME_BYTESWAP32(x)	(x)
-#endif
-
 static inline uint32_t
 ByteSwapToDevice32(uint32_t d)
 {
-    return RME_BYTESWAP32(d);
+    return d;
 }
 static inline uint32_t
 ByteSwapFromDevice32(uint32_t d)
 {
-    return RME_BYTESWAP32(d);
+    return d;
 }
+#endif
 
 Device::Device( DeviceManager& d,
                       std::auto_ptr<ConfigRom>( configRom ))
