blob: c659e56991c3b85b54e0640b873a462096e7c1b0 [file] [log] [blame]
Tung Nguyen189431e2020-12-16 08:11:51 +00001#!/bin/bash
2#
Thang Q. Nguyendde1fed2021-11-04 08:30:27 +00003# Copyright (c) 2021 Ampere Computing LLC
Tung Nguyen189431e2020-12-16 08:11:51 +00004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17# Ampere Computing LLC: UART MUX/DEMUX for CPU0 UART0,1,4 and CPU1 UART1
18# Usage: ampere_uartmux_ctrl.sh <CPU UART port number> <UARTx_MODE>
19# <UARTx_MODE> of 1 sets CPU To HDR_CONN
20# <UARTx_MODE> of 2 sets BMC to CPU (eg dropbear ssh server on port 2200)
Thu Nguyene50b26f2023-07-12 11:59:14 +070021# shellcheck disable=SC2046
Thang Q. Nguyendde1fed2021-11-04 08:30:27 +000022
Tung Nguyen189431e2020-12-16 08:11:51 +000023if [ $# -lt 2 ]; then
24 exit 1
25fi
26
Tung Nguyen189431e2020-12-16 08:11:51 +000027case "$1" in
Thu Nguyene50b26f2023-07-12 11:59:14 +070028 1) GPIO_UARTx_MODE0="uart1-mode0"
29 GPIO_UARTx_MODE1="uart1-mode1"
Tung Nguyen189431e2020-12-16 08:11:51 +000030 ;;
Thu Nguyene50b26f2023-07-12 11:59:14 +070031 2) GPIO_UARTx_MODE0="uart2-mode0"
32 GPIO_UARTx_MODE1="uart2-mode1"
Tung Nguyen189431e2020-12-16 08:11:51 +000033 ;;
Thu Nguyene50b26f2023-07-12 11:59:14 +070034 3) GPIO_UARTx_MODE0="uart3-mode0"
35 GPIO_UARTx_MODE1="uart3-mode1"
Tung Nguyen189431e2020-12-16 08:11:51 +000036 ;;
Thu Nguyene50b26f2023-07-12 11:59:14 +070037 4) GPIO_UARTx_MODE0="uart4-mode0"
38 GPIO_UARTx_MODE1="uart4-mode1"
Tung Nguyen189431e2020-12-16 08:11:51 +000039 ;;
40 *) echo "Invalid UART port selection"
Thu Nguyene50b26f2023-07-12 11:59:14 +070041 exit 1
Tung Nguyen189431e2020-12-16 08:11:51 +000042 ;;
43esac
44
Tung Nguyen189431e2020-12-16 08:11:51 +000045echo "Ampere UART MUX CTRL UART port $1 to mode $2"
46
47case "$2" in
Thu Nguyene50b26f2023-07-12 11:59:14 +070048 1)
49 if gpiofind "$GPIO_UARTx_MODE0"; then
50 gpioset $(gpiofind "$GPIO_UARTx_MODE0")=1
51 fi
52 if gpiofind "$GPIO_UARTx_MODE1"; then
53 gpioset $(gpiofind "$GPIO_UARTx_MODE1")=0
54 fi
55 exit 0
56 ;;
57 2)
58 if gpiofind "$GPIO_UARTx_MODE0"; then
59 gpioset $(gpiofind "$GPIO_UARTx_MODE0")=0
60 fi
61 if gpiofind "$GPIO_UARTx_MODE1"; then
62 gpioset $(gpiofind "$GPIO_UARTx_MODE1")=1
63 fi
64 exit 0
65 ;;
Tung Nguyen189431e2020-12-16 08:11:51 +000066 *) echo "Invalid UART mode selection"
67 exit 1
68 ;;
69esac