Ensure or warn about kernel USB autosuspend
authorDan White <dan@whiteaudio.com>
Mon, 29 Oct 2012 19:09:16 +0000 (14:09 -0500)
committerDan White <dan@whiteaudio.com>
Mon, 29 Oct 2012 19:09:16 +0000 (14:09 -0500)
python-lib/devboard.py
python-lib/test-nco.py

index 0d99217f0fe95ae4821f4c38b27874aef9c5ac45..356aa1165f70ce1dd1a3b87a6155de1af01cf9bf 100644 (file)
@@ -1,6 +1,8 @@
 #!/usr/bin/env python
 
 from datetime import datetime as dt
+import glob
+import os
 from time import sleep
 import yaml
 
@@ -187,17 +189,16 @@ arb = None
 amux = None
 
 
-def close_usb():
+def close_usb(delay=0):
     """
     Close the three MPSSE ports from the usb side.  If the serial port is also
     closed, the kernel will suspend the device.  This makes the SUSPEND pin go
     low on the usbio board and allows a circuit to cut power to the devboard.
     """
-    print 'closing usb ports'
+    print 'closing usb ports, waiting for kernel to suspend port'
     for c in (spi0.context, spi1.context, i2c.context):
         usbio.ftdi.usb_close(c)
-    print 'sleeping...'
-    sleep(5)
+    sleep(delay)
 
 
 def init_devboard(name='devboard-defaults.yaml'):
@@ -214,9 +215,28 @@ def init_devboard(name='devboard-defaults.yaml'):
     global chain, mux
     global arb, amux
 
+
+    USB_SUSPEND_DELAY = 0
+
+    # check for appropriate usb autosuspend settings
+    for p in glob.glob('/sys/bus/usb/devices/*'):
+        m = '%s/manufacturer' % p
+        c = '%s/power/control' % p
+        a = '%s/power/autosuspend_delay_ms' % p
+        if os.path.exists(m) and ('White Audio' in open(m).readline()):
+            control = open(c).readline().strip()
+            autosuspend = open(a).readline().strip()
+            ms = int(autosuspend)
+            if 'auto' not in control:
+                print "WARNING: autosuspend is not 'auto', currently: %s" % control
+                print "*******  therefore unable to power-cycle devboard."
+            print 'INFO: kernel autosuspend is %i ms' % ms
+            USB_SUSPEND_DELAY = 1.2 * (ms + 1) / 1e3
+
     #blank the slate
     if is_initialized:
-        close_usb()
+        close_usb(USB_SUSPEND_DELAY)
+
         _config = {}
         spi0 = None
         spi1 = None
index d1f3f28f78dbf7ef99953d7503234a867e5f834c..c386f8bf3f7bee5267ef53546018da32746347ee 100644 (file)
@@ -5,15 +5,8 @@ from time import sleep
 import devboard as dev
 dev.init_devboard(1)
 
+# requires devboard be already initialized
 from calibrate import calibrate
 
 
 
-
-
-sleep(5)
-dev.init_devboard(1)
-
-
-
-