Xo Wang | 9baac6f | 2016-12-15 15:24:22 -0800 | [diff] [blame] | 1 | #!/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 | |
| 6 | ucd_bus="0" |
| 7 | ucd_addr="0x64" |
| 8 | ucd_path="/sys/bus/i2c/drivers/ucd9000" |
| 9 | ucd_driver="${ucd_bus}-00${ucd_addr#0x}" |
| 10 | |
| 11 | # Usage: ucd_get address |
| 12 | # Result stored in $ucd_reg |
| 13 | ucd_get() |
| 14 | { |
| 15 | ucd_reg=`i2cget -y $ucd_bus $ucd_addr $1 b` |
| 16 | } |
| 17 | |
| 18 | # Usage: ucd_get address value |
| 19 | ucd_set() |
| 20 | { |
| 21 | i2cset -y $ucd_bus $ucd_addr $1 $2 b |
| 22 | } |
| 23 | |
| 24 | unbind_ucd() |
| 25 | { |
| 26 | if [ -e $ucd_path/$ucd_driver ] |
| 27 | then |
| 28 | echo -e "\tUnbinding UCD driver $ucd_driver" |
| 29 | echo $ucd_driver > $ucd_path/unbind |
| 30 | else |
| 31 | echo -e "\tWarning: $ucd_path/$ucd_driver doesn't exist" |
| 32 | fi |
| 33 | } |
| 34 | |
| 35 | rebind_ucd() |
| 36 | { |
| 37 | if [ -e $ucd_path ] |
| 38 | then |
| 39 | echo -e "\tBinding UCD driver $ucd_driver" |
| 40 | echo $ucd_driver > $ucd_path/bind |
| 41 | fi |
| 42 | } |
| 43 | |
| 44 | vcs_set_gpios() |
| 45 | { |
| 46 | unbind_ucd |
| 47 | echo -e "\tSetting UCD GPIO 5 to $1" |
| 48 | ucd_set 0xFA 5 |
| 49 | ucd_set 0xFB $1 |
| 50 | ucd_set 0xFB $1 |
| 51 | echo -e "\tSetting UCD GPIO 6 to $1" |
| 52 | ucd_set 0xFA 6 |
| 53 | ucd_set 0xFB $1 |
| 54 | ucd_set 0xFB $1 |
| 55 | rebind_ucd |
| 56 | } |
| 57 | |
| 58 | vcs_get() |
| 59 | { |
| 60 | echo Reading VCS settings |
| 61 | unbind_ucd |
| 62 | ucd_set 0xFA 5 |
| 63 | ucd_get 0xFB |
| 64 | local val=`echo $ucd_reg | grep -i -c 0x0f` |
| 65 | echo -e "\tUCD GPIO 5 state=$val" |
| 66 | ucd_set 0xFA 6 |
| 67 | ucd_get 0xFB |
| 68 | local val=`echo $ucd_reg | grep -i -c 0x0f` |
| 69 | echo -e "\tUCD GPIO 6 state=$val" |
| 70 | rebind_ucd |
| 71 | } |
| 72 | |
| 73 | |
| 74 | if [ "$1" == "on" ] |
| 75 | then |
| 76 | echo Turning on VCS |
| 77 | vcs_set_gpios 0x7 |
| 78 | |
| 79 | elif [ "$1" == "off" ] |
| 80 | then |
| 81 | echo Turning off VCS |
| 82 | vcs_set_gpios 0x3 |
| 83 | else |
| 84 | vcs_get |
| 85 | echo "$0 <on|off>" to set state |
| 86 | fi |