blob: 52d8403e336ea2d95b519626fc8cc0d897eff1c2 [file] [log] [blame]
James Feist57444232018-03-08 13:36:32 -08001#!/usr/bin/python
2"""
3This script sets muxes back to default values so that
4during device parsing we are not left with an invisible
5mux before the mux has been added to device tree.
6
7If we find a better way to take care of this, we should
8remove this file.
9"""
10
11import os
12import json
13import subprocess
14
15
16CONFIGURATION_FILE = '/var/configuration/system.json'
17MUX_TYPES = ['PCA9543Mux', 'PCA9545Mux']
18
19if not os.path.isfile(CONFIGURATION_FILE):
20 print('No Configuration')
21 exit(0)
22
23configuration = json.load(open(CONFIGURATION_FILE))
24
25for _, entity in configuration.iteritems():
26 for exposed in entity.get('exposes', []):
27 if exposed.get('type', None) in MUX_TYPES:
28 bus = exposed.get('bus', False)
29 address = exposed.get('address', False)
30 if bus and address:
31 subprocess.call('i2cset -y -f {} {} 0'.format(bus, address),
32 shell=True)