blob: 49bf0b04f5f1e1aac438f1bb8c748718fd72e3f1 [file] [log] [blame]
Xo Wang9baac6f2016-12-15 15:24:22 -08001#!/bin/sh -e
2# Read and control VCS rails by sending the UCD power sequencer I2C commands.
3# This script assumes that the UCD is controlling VCS rails as GPIOs 5 and 6.
4# Also assumes that those GPIOs are already enabled.
5
6ucd_bus="0"
7ucd_addr="0x64"
8ucd_path="/sys/bus/i2c/drivers/ucd9000"
9ucd_driver="${ucd_bus}-00${ucd_addr#0x}"
Xo Wang4e689672017-01-27 15:00:25 -080010ucd_retries="5"
11
12retry()
13{
14 local i=0
15 until [ $i -ge $ucd_retries ]; do
16 i=$((i+1))
17 retry_output=`$@` && break
18 done
19 local ret=$?
20 if [ $i -eq $ucd_retries ]; then exit $ret; fi
21}
Xo Wang9baac6f2016-12-15 15:24:22 -080022
23# Usage: ucd_get address
24# Result stored in $ucd_reg
25ucd_get()
26{
Robert Lippert6c77e482017-05-26 12:45:46 -070027 retry i2cget -f -y $ucd_bus $ucd_addr $1 b
Xo Wang4e689672017-01-27 15:00:25 -080028 ucd_reg=$retry_output
Xo Wang9baac6f2016-12-15 15:24:22 -080029}
30
31# Usage: ucd_get address value
32ucd_set()
33{
Robert Lippert6c77e482017-05-26 12:45:46 -070034 retry i2cset -f -y $ucd_bus $ucd_addr $1 $2 b
Xo Wang9baac6f2016-12-15 15:24:22 -080035}
36
37vcs_set_gpios()
38{
Xo Wang9baac6f2016-12-15 15:24:22 -080039 echo -e "\tSetting UCD GPIO 5 to $1"
40 ucd_set 0xFA 5
41 ucd_set 0xFB $1
42 ucd_set 0xFB $1
43 echo -e "\tSetting UCD GPIO 6 to $1"
44 ucd_set 0xFA 6
45 ucd_set 0xFB $1
46 ucd_set 0xFB $1
Xo Wang9baac6f2016-12-15 15:24:22 -080047}
48
49vcs_get()
50{
51 echo Reading VCS settings
Xo Wang9baac6f2016-12-15 15:24:22 -080052 ucd_set 0xFA 5
53 ucd_get 0xFB
54 local val=`echo $ucd_reg | grep -i -c 0x0f`
55 echo -e "\tUCD GPIO 5 state=$val"
56 ucd_set 0xFA 6
57 ucd_get 0xFB
58 local val=`echo $ucd_reg | grep -i -c 0x0f`
59 echo -e "\tUCD GPIO 6 state=$val"
Xo Wang9baac6f2016-12-15 15:24:22 -080060}
61
62
Xo Wang4e689672017-01-27 15:00:25 -080063if [ "$1" == "on" ]; then
Xo Wang9baac6f2016-12-15 15:24:22 -080064 echo Turning on VCS
65 vcs_set_gpios 0x7
Xo Wang4e689672017-01-27 15:00:25 -080066elif [ "$1" == "off" ]; then
Xo Wang9baac6f2016-12-15 15:24:22 -080067 echo Turning off VCS
68 vcs_set_gpios 0x3
69else
70 vcs_get
71 echo "$0 <on|off>" to set state
72fi