Potin Lai | 291d138 | 2023-01-03 09:31:22 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | CMD=$1 |
| 4 | SLED_INDEX=$2 |
| 5 | |
| 6 | CHIP_NUM=0 |
| 7 | USB2_SEL0_A_PIN_OFFSET=0 |
| 8 | USB2_SEL1_A_PIN_OFFSET=0 |
| 9 | USB2_SEL0_B_PIN_OFFSET=0 |
| 10 | USB2_SEL1_B_PIN_OFFSET=0 |
| 11 | |
| 12 | init_gpio_pin_info() |
| 13 | { |
| 14 | local pin_info |
| 15 | |
| 16 | read -r -a pin_info < <(gpiofind USB2_SEL0_A) |
| 17 | CHIP_NUM="${pin_info[0]}" |
| 18 | USB2_SEL0_A_PIN_OFFSET="${pin_info[1]}" |
| 19 | read -r -a pin_info < <(gpiofind USB2_SEL1_A) |
| 20 | USB2_SEL1_A_PIN_OFFSET="${pin_info[1]}" |
| 21 | read -r -a pin_info < <(gpiofind USB2_SEL0_B) |
| 22 | USB2_SEL0_B_PIN_OFFSET="${pin_info[1]}" |
| 23 | read -r -a pin_info < <(gpiofind USB2_SEL1_B) |
| 24 | USB2_SEL1_B_PIN_OFFSET="${pin_info[1]}" |
| 25 | } |
| 26 | |
| 27 | set_usbmux_gpio() |
| 28 | { |
| 29 | gpioset "$CHIP_NUM" \ |
| 30 | "$USB2_SEL0_A_PIN_OFFSET"="$1" \ |
| 31 | "$USB2_SEL1_A_PIN_OFFSET"="$2" \ |
| 32 | "$USB2_SEL0_B_PIN_OFFSET"="$3" \ |
| 33 | "$USB2_SEL1_B_PIN_OFFSET"="$4" |
| 34 | } |
| 35 | |
| 36 | print_help() |
| 37 | { |
| 38 | echo "Usage:" |
| 39 | echo " bletchley-usbmux-util off" |
| 40 | echo " bletchley-usbmux-util on <SLED_INDEX>" |
| 41 | echo "" |
| 42 | echo "SLED_INDEX: 1 - 6" |
| 43 | echo "" |
| 44 | } |
| 45 | |
| 46 | usb_mux_off() |
| 47 | { |
| 48 | set_usbmux_gpio 1 1 1 1 |
| 49 | } |
| 50 | |
| 51 | usb_mux_sled1() |
| 52 | { |
| 53 | usb_mux_off |
| 54 | sleep 2 |
| 55 | set_usbmux_gpio 0 0 1 1 |
| 56 | } |
| 57 | |
| 58 | usb_mux_sled2() |
| 59 | { |
| 60 | usb_mux_off |
| 61 | sleep 2 |
| 62 | set_usbmux_gpio 1 0 1 1 |
| 63 | } |
| 64 | |
| 65 | usb_mux_sled3() |
| 66 | { |
| 67 | usb_mux_off |
| 68 | sleep 2 |
| 69 | set_usbmux_gpio 0 1 1 1 |
| 70 | } |
| 71 | |
| 72 | usb_mux_sled4() |
| 73 | { |
| 74 | usb_mux_off |
| 75 | sleep 2 |
| 76 | set_usbmux_gpio 1 1 0 0 |
| 77 | } |
| 78 | |
| 79 | usb_mux_sled5() |
| 80 | { |
| 81 | usb_mux_off |
| 82 | sleep 2 |
| 83 | set_usbmux_gpio 1 1 1 0 |
| 84 | } |
| 85 | |
| 86 | usb_mux_sled6() |
| 87 | { |
| 88 | usb_mux_off |
| 89 | sleep 2 |
| 90 | set_usbmux_gpio 1 1 0 1 |
| 91 | } |
| 92 | |
| 93 | init_gpio_pin_info |
| 94 | |
| 95 | if [ "$CMD" == "off" ]; then |
| 96 | usb_mux_off |
| 97 | elif [ "$CMD" == "on" ]; then |
| 98 | if [ "$SLED_INDEX" -eq 1 ]; then |
| 99 | usb_mux_sled1 |
| 100 | elif [ "$SLED_INDEX" -eq 2 ]; then |
| 101 | usb_mux_sled2 |
| 102 | elif [ "$SLED_INDEX" -eq 3 ]; then |
| 103 | usb_mux_sled3 |
| 104 | elif [ "$SLED_INDEX" -eq 4 ]; then |
| 105 | usb_mux_sled4 |
| 106 | elif [ "$SLED_INDEX" -eq 5 ]; then |
| 107 | usb_mux_sled5 |
| 108 | elif [ "$SLED_INDEX" -eq 6 ]; then |
| 109 | usb_mux_sled6 |
| 110 | else |
| 111 | echo "Invalid SLED index: $SLED_INDEX" |
| 112 | print_help |
| 113 | exit 1 |
| 114 | fi |
| 115 | sleep 1 |
| 116 | else |
| 117 | echo "Invalid command: $CMD" |
| 118 | print_help |
| 119 | exit 1 |
| 120 | fi |
| 121 | |
| 122 | exit 0 |