Delphine CC Chiu | a576a59 | 2022-12-21 09:25:28 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Select UART Mux: UART Mux for switching between Host and BIC on Slot1 ~ Slot4 |
| 3 | # Usage: select-uart-mux <slot1|slot2|slot3|slot4> <host|bic> |
| 4 | |
| 5 | REG_OFFSET="0x01" |
| 6 | input_slot=$1 |
| 7 | input_target=$2 |
| 8 | i2c_bus_id= |
| 9 | |
| 10 | show_usage() { |
| 11 | echo "Usage: select-uart-mux [ slot1 | slot2 | slot3 | slot4 ] [ host | bic ]" |
| 12 | echo "Select UART Mux" |
| 13 | } |
| 14 | |
| 15 | if [ $# -gt 3 ]; then |
| 16 | show_usage |
| 17 | exit 255 |
| 18 | fi |
| 19 | |
| 20 | case $input_slot in |
| 21 | slot1) |
| 22 | i2c_bus_id="4" |
| 23 | ;; |
| 24 | slot2) |
| 25 | i2c_bus_id="5" |
| 26 | ;; |
| 27 | slot3) |
| 28 | i2c_bus_id="6" |
| 29 | ;; |
| 30 | slot4) |
| 31 | i2c_bus_id="7" |
| 32 | ;; |
| 33 | *) |
| 34 | echo "Slot must between 1 to 4." |
| 35 | show_usage |
| 36 | exit 255 |
| 37 | ;; |
| 38 | esac |
| 39 | |
| 40 | case $input_target in |
| 41 | host) |
| 42 | reg_val="0x03" |
| 43 | ;; |
| 44 | bic) |
| 45 | reg_val="0x04" |
| 46 | ;; |
| 47 | *) |
| 48 | echo "Input must be host or bic." |
| 49 | show_usage |
| 50 | exit 255 |
| 51 | esac |
| 52 | |
| 53 | i2ctransfer -y -f $i2c_bus_id w2@0x0f $REG_OFFSET $reg_val |
| 54 | |
| 55 | val=$(i2ctransfer -y -f $i2c_bus_id w1@0x0f $REG_OFFSET r1) |
| 56 | ret=$? |
| 57 | |
| 58 | if [ $ret -ne 0 ] || [ "$val" != $reg_val ]; then |
| 59 | echo "Failed to modify the register value, the register value is $val instead of $reg_val." |
| 60 | exit 255 |
| 61 | fi |