aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/sys_utils/udev.py
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-12-12 09:59:50 -0800
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:05:58 -0800
commitd3e6dd11406893bfbc5537dfbe74d8151bbc1280 (patch)
tree8663263b3c5a4ff7202e01a5f9c5c6bb23969829 /mpm/python/usrp_mpm/sys_utils/udev.py
parentea7cc7f8250cd9bdb41c1f22703d38be91fb6a84 (diff)
downloaduhd-d3e6dd11406893bfbc5537dfbe74d8151bbc1280.tar.gz
uhd-d3e6dd11406893bfbc5537dfbe74d8151bbc1280.tar.bz2
uhd-d3e6dd11406893bfbc5537dfbe74d8151bbc1280.zip
mpm: Harmonize imports, tidy + sort modules
- Moved nijesdcore to cores/ - Moved udev, net, dtoverlay, uio to sys_utils/ - Made all imports non-relative (except in __init__.py files) - Removed some unnecessary imports - Reordered some imports for Python conventions
Diffstat (limited to 'mpm/python/usrp_mpm/sys_utils/udev.py')
-rw-r--r--mpm/python/usrp_mpm/sys_utils/udev.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/mpm/python/usrp_mpm/sys_utils/udev.py b/mpm/python/usrp_mpm/sys_utils/udev.py
new file mode 100644
index 000000000..87d264d2d
--- /dev/null
+++ b/mpm/python/usrp_mpm/sys_utils/udev.py
@@ -0,0 +1,51 @@
+#
+# Copyright 2017 Ettus Research (National Instruments)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import os
+import pyudev
+
+def get_eeprom_paths(address):
+ """
+ Return list of EEPROM device paths for a given I2C address.
+ If no device paths are found, an empty list is returned.
+ """
+ context = pyudev.Context()
+ parent = pyudev.Device.from_name(context, "platform", address)
+ paths = [d.device_node if d.device_node is not None else d.sys_path
+ for d in context.list_devices(parent=parent, subsystem="nvmem")]
+ if len(paths) == 0:
+ return []
+ # We need to sort this so 9-0050 comes before 10-0050 (etc.)
+ maxlen = max((len(os.path.split(p)[1]) for p in paths))
+ paths = sorted(
+ paths,
+ key=lambda x: "{:>0{maxlen}}".format(os.path.split(x)[1], maxlen=maxlen)
+ )
+ return [os.path.join(x, 'nvmem') for x in paths]
+
+def get_spidev_nodes(spi_master):
+ """
+ Return list of spidev device paths for a given SPI master. If no valid paths
+ can be found, an empty list is returned.
+ """
+ context = pyudev.Context()
+ parent = pyudev.Device.from_name(context, "platform", spi_master)
+ return [
+ device.device_node
+ for device in context.list_devices(parent=parent, subsystem="spidev")
+ ]
+