aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/periph_manager/udev.py
blob: 9d64b1b646340d0349ab77514cfbf06571795b83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#
# 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 pyudev
import os
from ..mpmlog import get_logger

def get_eeprom_path(address):
    """
    Return EEPROM device path for a given I2C address
    """
    context = pyudev.Context()
    parent = pyudev.Device.from_name(context, "platform", address)
    paths = [device.device_node if device.device_node is not None else device.sys_path
             for device in context.list_devices(parent=parent, subsystem="nvmem")]
    if len(paths) != 1:
        raise Exception("{0} paths to EEPROM found!".format(len(paths)))
    return paths[0] + "/nvmem"


def get_spidev_nodes(spi_master):
    """
    Return found spidev device paths for a given SPI master
    """
    context = pyudev.Context()
    parent = pyudev.Device.from_name(context, "platform", spi_master)
    paths = [device.device_node.encode('ascii')
             for device in context.list_devices(parent=parent, subsystem="spidev")]
    return paths