blob: f2038364d1ef6ed086c8c80552a8fa6e0e9990c5 [file] [log] [blame]
Yang Chen27dbef02023-12-08 20:36:52 +08001#!/bin/bash -e
2# shellcheck source=meta-facebook/meta-minerva/recipes-minerva/plat-tool/files/minerva-common-functions
3# Select UART Mux: UART Mux for switching between MTIA blade 0~15
4# Usage: select-uart-mux <0-15>
5source /usr/libexec/minerva-common-functions
6
7convert_decimal_to_binary() {
8 decimal=$1
9
10 binary=""
11 for ((i = 3; i >= 0; i--)); do
12 bit=$(( (decimal >> i) & 1 ))
13 binary="${binary}${bit}"
14 done
15
16 echo "$binary"
17}
18
19uart_mux_select()
20{
21 local BLADE_INDEX=$1
22
23 if ((BLADE_INDEX >= 0)) && ((BLADE_INDEX < 16)); then
24 BINARY_INDEX=$(convert_decimal_to_binary "$BLADE_INDEX")
25
26 set_gpio BLADE_UART_SEL0 "${BINARY_INDEX:3:1}"
27 set_gpio BLADE_UART_SEL1 "${BINARY_INDEX:2:1}"
28 set_gpio BLADE_UART_SEL2 "${BINARY_INDEX:1:1}"
29 set_gpio BLADE_UART_SEL3 "${BINARY_INDEX:0:1}"
30 else
31 logger -p user.info "uart_mux_select: unknow blade index ($BLADE_INDEX)"
32 return 1
33 fi
34
35 return 0
36}
37
38BLADE_INDEX=$1
39uart_mux_select "$BLADE_INDEX"