-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathusb_otg.sh
executable file
·77 lines (64 loc) · 1.77 KB
/
usb_otg.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Copyright (c) 2021-22 Analog Devices, Inc. All Rights Reserved.
# This software is proprietary to Analog Devices, Inc. and its licensors.
# By using this software you agree to the terms of the associated
# Analog Devices Software License Agreement.
# Manages USB OtG configuration in devicetree for supported platforms
is_compatible() {
echo $COMP | grep -q $1
return $?
}
check_platform() {
# Most ARM systems will fill /sys/firmware.
COMPATIBLE="/proc/device-tree/compatible"
if [ -f "${COMPATIBLE}" ] ; then
COMP=$(strings /proc/device-tree/compatible)
echo "Compatible=$COMP"
else
echo "[ERROR] No Model information in devicetree"
exit 1
fi
if $(is_compatible "xlnx,zynq-7000"); then
fdtget -p /boot/devicetree.dtb /axi > /dev/null 2>&1 && USB="/axi/usb@e0002000" || USB="/amba/usb@e0002000"
DTB="/boot/devicetree.dtb"
elif $(is_compatible "xlnx,zynqmp"); then
fdtget -p /boot/system.dtb /axi > /dev/null 2>&1 && USB="/axi/usb@ff9d0000/usb@fe200000" || USB="/amba/usb@ff9d0000/usb@fe200000"
DTB="/boot/system.dtb"
elif $(is_compatible "altr,socfpga-cyclone5"); then
USB="/soc/usb@ffb40000"
DTB="/boot/socfpga.dtb"
else
# All other platform are not supported
echo "USB OtG Supported=No"
exit 1
fi
echo "USB OtG Supported=Yes"
}
show_status() {
echo "USB dr_mode=" $(fdtget --default "Not Specified: per usb/generic.txt dr_mode should default to otg" --type s $DTB $USB dr_mode)
}
case "$1" in
enable)
check_platform
fdtput -t s $DTB $USB dr_mode otg
show_status
;;
disable)
check_platform
fdtput -t s $DTB $USB dr_mode host
show_status
;;
delete_dr_mode)
check_platform
fdtput -d $DTB $USB dr_mode
show_status
;;
status)
check_platform
show_status
;;
*)
echo "Usage: $0 {enable|disable|delete_dr_mode|status}"
exit 1
;;
esac