blob: a1d29b3be020adfe5ebe0b773971dc2613772809 [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
Ed Tanousdb504502019-02-25 10:49:32 -080014import re
James Feist57444232018-03-08 13:36:32 -080015
16CONFIGURATION_FILE = '/var/configuration/system.json'
James Feist57444232018-03-08 13:36:32 -080017
18if not os.path.isfile(CONFIGURATION_FILE):
19 print('No Configuration')
20 exit(0)
21
22configuration = json.load(open(CONFIGURATION_FILE))
23
24for _, entity in configuration.iteritems():
James Feist1e3e6982018-08-03 16:09:28 -070025 for exposed in entity.get('Exposes', []):
Ed Tanousdb504502019-02-25 10:49:32 -080026 if re.match("PCA954\\dMux", exposed.get('Type', None)):
James Feist1e3e6982018-08-03 16:09:28 -070027 bus = exposed.get('Bus', False)
28 address = exposed.get('Address', False)
James Feist57444232018-03-08 13:36:32 -080029 if bus and address:
30 subprocess.call('i2cset -y -f {} {} 0'.format(bus, address),
31 shell=True)