summaryrefslogtreecommitdiffstats
path: root/woferclock/list_i2c_busses
blob: fa1dbffc0c4dfa97a08338b5767dbd0b5eb37716 (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
45
46
47
#!/usr/bin/python
#
# Copyright (c) 2018 Raptor Engineering, LLC
# Released under the terms of the AGPL v3

import sys
import os
import glob

i2cdir = "/sys/class/i2c-dev/"
eeprom_address = 0x50

mod_ret = os.system("modprobe i2c_dev")
exit_code = os.WEXITSTATUS(mod_ret)
if exit_code != 0:
    print "[ERROR] I2C driver load failed!"
    sys.exit(1)

i2cbusses = glob.glob(i2cdir + "i2c-*")
busnumlist = []
for b in i2cbusses:
    bus = b.replace(i2cdir + "i2c-", "")
    busnumlist.append(int(bus))

busnumlist.sort()

mod_ret = os.system("modprobe at24")
exit_code = os.WEXITSTATUS(mod_ret)
if exit_code != 0:
    print "[ERROR] at24 driver load failed!"
    sys.exit(1)

print "The following I2C busses are available on this system:"
for b in busnumlist:
    sys.stdout.write("\tBus " + str(b))
    mvpd_found = False
    try:
        with open("/sys/class/i2c-dev/i2c-" + str(b) + "/device/" + str(b) + "-" + format(eeprom_address, '04x') + "/eeprom", 'rb') as f:
            f.seek(0, os.SEEK_END)
            if f.tell() == 65536:
                mvpd_found = True
                print " (MVPD candidate found on bus)"
    except:
        pass

    if not mvpd_found:
        print ""
OpenPOWER on IntegriCloud