blob: 64198f1c72057028b7e0cf207a59cb5953fe741a [file] [log] [blame]
# Lint as: python2, python3
# Copyriht (c) 2014 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import logging
import six
# Following Beaglebone GPIO pins are used to control the 8 port multiplexer.
MUX_EN = '20'
MUX_S0 = '115'
MUX_S1 = '117'
MUX_S2 = '49'
# Various commands used to control the GPIO pins at the kernel level.
LS_GPIO_DIRECTORY = 'ls /sys/class/gpio'
EXPORT_GPIO_PIN = 'echo %s > /sys/class/gpio/export'
SET_GPIO_DIRECTION = 'echo high > /sys/class/gpio/gpio%s/direction'
SET_GPIO_VALUE = 'echo %s > /sys/class/gpio/gpio%s/value'
UNEXPORT_GPIO_PIN = 'echo %s > /sys/class/gpio/unexport'
# Values passed to each GPIO pin to enable a specific port.
# Bit sequence: MUX_S2, MUX_S1, MUX_S0
# Example: To enable port 5, MUX_S2 will be set to 1, MUX_S1 will be set to 0
# and MUX_S0 will be set to 1
ports = {0:'000', 1:'001', 2:'010', 3:'011', 4:'100', 5:'101', 6:'110', 7:'111'}
class USBMuxController(object):
"""Class to control individual ports on a 8 port USB switch/hub.
This class is responsible for enabling all the GPIO pins on the beaglebone
needed to control the 8 port USB switch/hub. In order to use this USB mux
controller you need custom hardware setup which connects to the beaglebone
and drives the 8 port relay switch to turn the individual ports on the USB
hub 'on'/'off'.
TODO(harpreet) Write a USB mux hardware design document and provide a link
version = 1
def __init__(self, host):
"""Initializes this USB Mux Controller instance.
@param host: Host where the test will be run.
""" = host
def __del__(self):
"""Destructor of USBMuxController.
Disables all GPIO pins used that control the multiplexer.
def mux_setup(self):
Enable GPIO pins that control the multiplexer.
"""'Enable GPIO pins that control the multiplexer.')
def mux_teardown(self):
Disable the multiplexer and unexport all GPIO pins.
"""'Start USB multiplexer teardown.')
# unexport gpio pins'Unexport all GPIO pins.') % MUX_S0) % MUX_S1) % MUX_S2) % MUX_EN)'Completed USB multiplexer teardown. All USB ports should'
'now be turned off.')
def enable_gpio_pins(self, pin):
Enables the given GPIO pin by exporting the pin and setting the
@param pin: GPIO pin to be enabled.
if 'gpio' + pin not in % pin) % pin)
def enable_port(self, usb_port):
Enables the given port on the USB hub.
@param usb_port: USB port to be enabled.
port = ports[usb_port]'Enable port %s.', port)
self.disable_all_ports()'Set GPIO pins to correct logic levels.') % (port[0], MUX_S2)) % (port[1], MUX_S1)) % (port[2], MUX_S0))'Enable USB multiplexer. Appropriate port should now be'
'enabled') % (ENABLE_MUX, MUX_EN))
def disable_all_ports(self):
Disables all USB ports that are currently enabled.
if 'gpio20' in'Disable USB ports.') % (DISABLE_MUX, MUX_EN))