Skip to content

Commit d2f1a6d

Browse files
committed
Allow multiple gadgets to be enabled
1 parent 03e10ba commit d2f1a6d

File tree

3 files changed

+39
-28
lines changed

3 files changed

+39
-28
lines changed

debian/radxa-otgutils.radxa-adbd.service

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Description=Enable adbd on supported Radxa products
33
Documentation=https://github.com/radxa-pkg/radxa-otgutils/
44
After=network.target
5-
Conflicts=radxa-usbnet.service
65

76
[Service]
87
Type=forking

debian/radxa-otgutils.radxa-usbnet.service

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Description=Enable USB Ethernet on supported Radxa products
33
Documentation=https://github.com/radxa-pkg/radxa-otgutils/
44
After=network.target
5-
Conflicts=radxa-adbd.service
65

76
[Service]
87
Type=forking

src/radxa-otgutils

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,45 @@ configfs_init()
44
{
55
modprobe libcomposite
66

7+
mkdir -p "/sys/kernel/config/usb_gadget/radxa-otgutils"
8+
pushd "/sys/kernel/config/usb_gadget/radxa-otgutils"
9+
10+
echo "0x1d6b" > "idVendor" # Linux Foundation
11+
echo "0x0104" > "idProduct" # Multifunction Composite Gadget
12+
echo "0x0100" > "bcdDevice" # v1.0.0
13+
echo "0x0200" > "bcdUSB" # USB 2.0
14+
echo "0xEF" > "bDeviceClass"
15+
echo "0x02" > "bDeviceSubClass"
16+
echo "0x01" > "bDeviceProtocol"
17+
18+
mkdir -p "strings/0x409"
19+
echo "0123456789ABCDEF" > "strings/0x409/serialnumber"
20+
echo "Radxa" > "strings/0x409/manufacturer"
21+
echo "OTG Utils" > "strings/0x409/product"
22+
23+
mkdir -p "configs/r.1/strings/0x409"
24+
echo "500" > "configs/r.1/MaxPower"
25+
echo "adb" > "configs/r.1/strings/0x409/configuration"
26+
27+
popd
28+
}
29+
30+
function_init()
31+
{
732
case "$MODE" in
833
adbd)
9-
local VENDOR="0x18d1"
10-
local PRODUCT="0x0001"
34+
local GADGET="ffs.adb"
1135
;;
1236
usbnet)
13-
local VENDOR="0x1d6b"
14-
local PRODUCT="0x0104"
37+
local GADGET="ecm.usb0"
1538
;;
1639
esac
1740

18-
mkdir -p "/sys/kernel/config/usb_gadget/radxa-$MODE"
19-
chmod 0770 "/sys/kernel/config/usb_gadget/radxa-$MODE"
20-
echo "$VENDOR" > "/sys/kernel/config/usb_gadget/radxa-$MODE/idVendor"
21-
echo "$PRODUCT" > "/sys/kernel/config/usb_gadget/radxa-$MODE/idProduct"
22-
mkdir -p "/sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409"
23-
chmod 0770 "/sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409"
24-
echo "Radxa" > "/sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409/manufacturer"
25-
echo "$MODE" > "/sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409/product"
26-
mkdir -p "/sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1"
27-
chmod 0770 "/sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1"
28-
29-
case "$MODE" in
30-
adbd)
31-
echo "0123456789ABCDEF" > "/sys/kernel/config/usb_gadget/radxa-$MODE/strings/0x409/serialnumber"
32-
mkdir -p "/sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/strings/0x409"
33-
chmod 0770 "/sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/strings/0x409"
34-
echo "500" > "/sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/MaxPower"
35-
echo "adb" > "/sys/kernel/config/usb_gadget/radxa-$MODE/configs/r.1/strings/0x409/configuration"
36-
;;
37-
esac
41+
if [ ! -e "/sys/kernel/config/usb_gadget/radxa-otgutils/configs/r.1/$GADGET" ];
42+
then
43+
mkdir -p "/sys/kernel/config/usb_gadget/radxa-otgutils/functions/$GADGET"
44+
ln -s "/sys/kernel/config/usb_gadget/radxa-otgutils/functions/$GADGET" "/sys/kernel/config/usb_gadget/radxa-otgutils/configs/r.1"
45+
fi
3846
}
3947

4048
function_stop()
@@ -79,12 +87,17 @@ start()
7987
echo "No USB Device Controller was detected. Did you set your OTG port to host mode?"
8088
exit 1
8189
fi
82-
echo "$UDC" > "/sys/kernel/config/usb_gadget/radxa-$MODE/UDC"
90+
echo "$UDC" > "/sys/kernel/config/usb_gadget/radxa-otgutils/UDC"
8391
}
8492

8593
stop()
8694
{
87-
echo "none" > "/sys/kernel/config/usb_gadget/radxa-$MODE/UDC"
95+
function_stop
96+
if [[ ! -e "/sys/kernel/config/usb_gadget/radxa-otgutils/configs/r.1/" ]] || \
97+
(( $(find /sys/kernel/config/usb_gadget/radxa-otgutils/configs/r.1/* -maxdepth 0 -type d | wc -l) == 0 ))
98+
then
99+
echo "none" > "/sys/kernel/config/usb_gadget/radxa-otgutils/UDC"
100+
fi
88101
case "$MODE" in
89102
adbd)
90103
start-stop-daemon --stop --oknodo --pidfile /var/run/adbd.pid --retry 5

0 commit comments

Comments
 (0)