Lancelot Kao | dc456f9 | 2021-02-21 18:42:38 -0600 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2020 Ampere Computing LLC |
| 4 | # |
| 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 mtjade: 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 BSP |
| 20 | # <UARTx_MODE> of 2 sets SCP1 to SI2 |
| 21 | function set_gpio_ctrl() { |
| 22 | echo $1 > /sys/class/gpio/export |
| 23 | echo $2 > /sys/class//gpio/gpio$1/direction |
| 24 | echo $3 > /sys/class/gpio/gpio$1/value |
| 25 | echo $1 > /sys/class/gpio/unexport |
| 26 | } |
| 27 | |
| 28 | |
| 29 | if [ $# -lt 1 ]; then |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | echo "Ampere UART MUX CTRL UART port $1 to mode" > /dev/ttyS0 |
| 34 | |
| 35 | case "$1" in |
| 36 | ttyS1) |
| 37 | set_gpio_ctrl 167 out 1 |
| 38 | ;; |
| 39 | ttyS3) |
| 40 | set_gpio_ctrl 161 out 1 |
| 41 | set_gpio_ctrl 183 out 1 |
| 42 | set_gpio_ctrl 198 out 0 |
| 43 | ;; |
| 44 | *) |
| 45 | echo "Invalid tty passed to $0. Exiting!" > /dev/ttyS0 |
| 46 | ;; |
| 47 | esac |
| 48 | |