Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Thang Q. Nguyen | dde1fed | 2021-11-04 08:30:27 +0000 | [diff] [blame] | 3 | # Copyright (c) 2021 Ampere Computing LLC |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 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: 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) |
| 21 | |
Chau Ly | 4255eea | 2023-04-18 07:11:32 +0000 | [diff] [blame] | 22 | # shellcheck source=meta-ampere/meta-jade/recipes-ampere/platform/ampere-utils/gpio-lib.sh |
Thang Q. Nguyen | dde1fed | 2021-11-04 08:30:27 +0000 | [diff] [blame] | 23 | source /usr/sbin/gpio-lib.sh |
| 24 | |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 25 | if [ $# -lt 2 ]; then |
| 26 | exit 1 |
| 27 | fi |
| 28 | |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 29 | case "$1" in |
| 30 | 1) GPIO_UARTx_MODE0=56 |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 31 | ;; |
| 32 | 2) GPIO_UARTx_MODE0=57 |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 33 | ;; |
| 34 | 3) GPIO_UARTx_MODE0=58 |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 35 | ;; |
| 36 | 4) GPIO_UARTx_MODE0=59 |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 37 | ;; |
| 38 | *) echo "Invalid UART port selection" |
| 39 | exit 1 |
| 40 | ;; |
| 41 | esac |
| 42 | |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 43 | echo "Ampere UART MUX CTRL UART port $1 to mode $2" |
| 44 | |
| 45 | case "$2" in |
Thang Q. Nguyen | dde1fed | 2021-11-04 08:30:27 +0000 | [diff] [blame] | 46 | 1) gpio_configure_output "${GPIO_UARTx_MODE0}" 0 |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 47 | exit 0 |
| 48 | ;; |
Thang Q. Nguyen | dde1fed | 2021-11-04 08:30:27 +0000 | [diff] [blame] | 49 | 2) gpio_configure_output "${GPIO_UARTx_MODE0}" 1 |
Tung Nguyen | 189431e | 2020-12-16 08:11:51 +0000 | [diff] [blame] | 50 | exit 0 |
| 51 | ;; |
| 52 | *) echo "Invalid UART mode selection" |
| 53 | exit 1 |
| 54 | ;; |
| 55 | esac |